@nocobase/plugin-data-source-manager 1.2.12-alpha → 1.3.0-alpha.20240710084543
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/package.json +2 -2
- package/dist/client/DatabaseConnectionProvider.d.ts +0 -11
- package/dist/client/ThridDataSource.d.ts +0 -12
- package/dist/client/component/BreadcumbTitle.d.ts +0 -10
- package/dist/client/component/CollectionsManager/AddFieldAction.d.ts +0 -13
- package/dist/client/component/CollectionsManager/CollectionFields.d.ts +0 -16
- package/dist/client/component/CollectionsManager/CollectionTitle.d.ts +0 -9
- package/dist/client/component/CollectionsManager/ConfigurationTable.d.ts +0 -10
- package/dist/client/component/CollectionsManager/ConfigurationTabs.d.ts +0 -10
- package/dist/client/component/CollectionsManager/EditCollectionAction.d.ts +0 -14
- package/dist/client/component/CollectionsManager/EditFieldAction.d.ts +0 -10
- package/dist/client/component/CollectionsManager/FilterTargetKeyAlert.d.ts +0 -12
- package/dist/client/component/CollectionsManager/SetFilterTargetKey.d.ts +0 -10
- package/dist/client/component/CollectionsManager/components/CollectionFieldInterfaceSelect.d.ts +0 -10
- package/dist/client/component/CollectionsManager/components/CollectionName.d.ts +0 -9
- package/dist/client/component/CollectionsManager/components/FieldTitleInput.d.ts +0 -10
- package/dist/client/component/CollectionsManager/components/FieldType.d.ts +0 -10
- package/dist/client/component/CollectionsManager/components/TitleField.d.ts +0 -10
- package/dist/client/component/CollectionsManager/components/UnSupportFields.d.ts +0 -10
- package/dist/client/component/CollectionsManager/components/index.d.ts +0 -14
- package/dist/client/component/CollectionsManager/hooks.d.ts +0 -20
- package/dist/client/component/CollectionsManager/index.d.ts +0 -10
- package/dist/client/component/CollectionsManager/schema/collectionFields.d.ts +0 -12
- package/dist/client/component/CollectionsManager/schema/collections.d.ts +0 -72
- package/dist/client/component/CreateDatabaseConnectAction.d.ts +0 -10
- package/dist/client/component/DatabaseConnectionManager.d.ts +0 -10
- package/dist/client/component/EditDatabaseConnectionAction.d.ts +0 -10
- package/dist/client/component/MainDataSourceManager/Configuration/AddCategoryAction.d.ts +0 -11
- package/dist/client/component/MainDataSourceManager/Configuration/CollectionFields.d.ts +0 -11
- package/dist/client/component/MainDataSourceManager/Configuration/ConfigurationTable.d.ts +0 -10
- package/dist/client/component/MainDataSourceManager/Configuration/ConfigurationTabs.d.ts +0 -10
- package/dist/client/component/MainDataSourceManager/Configuration/EditCategoryAction.d.ts +0 -11
- package/dist/client/component/MainDataSourceManager/Configuration/index.d.ts +0 -13
- package/dist/client/component/MainDataSourceManager/Configuration/interfaces.d.ts +0 -24
- package/dist/client/component/MainDataSourceManager/Configuration/schemas/collectionFields.d.ts +0 -10
- package/dist/client/component/MainDataSourceManager/Configuration/schemas/collections.d.ts +0 -15
- package/dist/client/component/MainDataSourceManager/index.d.ts +0 -10
- package/dist/client/component/PermissionManager/DataSourceTable.d.ts +0 -11
- package/dist/client/component/PermissionManager/PermisionProvider.d.ts +0 -13
- package/dist/client/component/PermissionManager/RoleConfigure.d.ts +0 -10
- package/dist/client/component/PermissionManager/RolesResourcesActions.d.ts +0 -11
- package/dist/client/component/PermissionManager/ScopeSelect.d.ts +0 -11
- package/dist/client/component/PermissionManager/StrategyActions.d.ts +0 -10
- package/dist/client/component/PermissionManager/index.d.ts +0 -11
- package/dist/client/component/PermissionManager/schemas/dataSourceTable.d.ts +0 -10
- package/dist/client/component/PermissionManager/schemas/roleCollections.d.ts +0 -10
- package/dist/client/component/PermissionManager/schemas/scopes.d.ts +0 -130
- package/dist/client/component/PermissionManager/schemas/useRoleResourceValues.d.ts +0 -16
- package/dist/client/component/PermissionManager/schemas/useSaveRoleResourceAction.d.ts +0 -11
- package/dist/client/component/PermissionManager/style.d.ts +0 -9
- package/dist/client/component/ViewDatabaseConnectionAction.d.ts +0 -10
- package/dist/client/constant.d.ts +0 -9
- package/dist/client/hooks/index.d.ts +0 -14
- package/dist/client/index.d.ts +0 -17
- package/dist/client/index.js +0 -59
- package/dist/client/locale/index.d.ts +0 -11
- package/dist/client/schema/index.d.ts +0 -15
- package/dist/externalVersion.js +0 -33
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -48
- package/dist/locale/zh-CN.json +0 -40
- package/dist/server/collections/data-sources-collections.d.ts +0 -10
- package/dist/server/collections/data-sources-collections.js +0 -75
- package/dist/server/collections/data-sources-fields.d.ts +0 -10
- package/dist/server/collections/data-sources-fields.js +0 -96
- package/dist/server/collections/data-sources-roles-resources-actions.d.ts +0 -10
- package/dist/server/collections/data-sources-roles-resources-actions.js +0 -61
- package/dist/server/collections/data-sources-roles-resources-scopes.d.ts +0 -10
- package/dist/server/collections/data-sources-roles-resources-scopes.js +0 -65
- package/dist/server/collections/data-sources-roles-resources.d.ts +0 -10
- package/dist/server/collections/data-sources-roles-resources.js +0 -71
- package/dist/server/collections/data-sources-roles.d.ts +0 -10
- package/dist/server/collections/data-sources-roles.js +0 -63
- package/dist/server/collections/data-sources.d.ts +0 -10
- package/dist/server/collections/data-sources.js +0 -80
- package/dist/server/errors/type-infer-error.d.ts +0 -10
- package/dist/server/errors/type-infer-error.js +0 -37
- package/dist/server/index.d.ts +0 -10
- package/dist/server/index.js +0 -48
- package/dist/server/migrations/20240301164024-migrate-acl-resources.d.ts +0 -15
- package/dist/server/migrations/20240301164024-migrate-acl-resources.js +0 -127
- package/dist/server/migrations/20240414103927-update-snippet-name.d.ts +0 -14
- package/dist/server/migrations/20240414103927-update-snippet-name.js +0 -60
- package/dist/server/models/connections-roles-resources-action.d.ts +0 -11
- package/dist/server/models/connections-roles-resources-action.js +0 -38
- package/dist/server/models/connections-roles-resources.d.ts +0 -11
- package/dist/server/models/connections-roles-resources.js +0 -38
- package/dist/server/models/data-source.d.ts +0 -25
- package/dist/server/models/data-source.js +0 -173
- package/dist/server/models/data-sources-collection-model.d.ts +0 -15
- package/dist/server/models/data-sources-collection-model.js +0 -46
- package/dist/server/models/data-sources-field-model.d.ts +0 -18
- package/dist/server/models/data-sources-field-model.js +0 -63
- package/dist/server/models/data-sources-roles-model.d.ts +0 -17
- package/dist/server/models/data-sources-roles-model.js +0 -64
- package/dist/server/plugin.d.ts +0 -21
- package/dist/server/plugin.js +0 -443
- package/dist/server/resourcers/data-sources-collections-fields.d.ts +0 -19
- package/dist/server/resourcers/data-sources-collections-fields.js +0 -140
- package/dist/server/resourcers/data-sources-collections.d.ts +0 -16
- package/dist/server/resourcers/data-sources-collections.js +0 -115
- package/dist/server/resourcers/data-sources-resources.d.ts +0 -17
- package/dist/server/resourcers/data-sources-resources.js +0 -97
- package/dist/server/resourcers/data-sources-roles.d.ts +0 -16
- package/dist/server/resourcers/data-sources-roles.js +0 -98
- package/dist/server/resourcers/roles-data-sources-collections.d.ts +0 -15
- package/dist/server/resourcers/roles-data-sources-collections.js +0 -111
- package/dist/server/services/full-data-repository.d.ts +0 -16
- package/dist/server/services/full-data-repository.js +0 -60
- package/dist/server/services/type-interface-map.d.ts +0 -191
- package/dist/server/services/type-interface-map.js +0 -253
- package/dist/server/utils.d.ts +0 -9
- package/dist/server/utils.js +0 -47
|
@@ -1,63 +0,0 @@
|
|
|
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_field_model_exports = {};
|
|
28
|
-
__export(data_sources_field_model_exports, {
|
|
29
|
-
DataSourcesFieldModel: () => DataSourcesFieldModel
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(data_sources_field_model_exports);
|
|
32
|
-
var import_database = require("@nocobase/database");
|
|
33
|
-
var import_utils = require("../utils");
|
|
34
|
-
class DataSourcesFieldModel extends import_database.MagicAttributeModel {
|
|
35
|
-
load(loadOptions) {
|
|
36
|
-
const { app } = loadOptions;
|
|
37
|
-
const options = this.get();
|
|
38
|
-
const { collectionName, name, dataSourceKey } = options;
|
|
39
|
-
const dataSource = app.dataSourceManager.dataSources.get(dataSourceKey);
|
|
40
|
-
const collection = dataSource.collectionManager.getCollection(collectionName);
|
|
41
|
-
const oldField = collection.getField(name);
|
|
42
|
-
const newOptions = (0, import_utils.mergeOptions)(oldField ? oldField.options : {}, options);
|
|
43
|
-
collection.setField(name, newOptions);
|
|
44
|
-
}
|
|
45
|
-
unload(loadOptions) {
|
|
46
|
-
const { app } = loadOptions;
|
|
47
|
-
const options = this.get();
|
|
48
|
-
const { collectionName, name, dataSourceKey } = options;
|
|
49
|
-
const dataSource = app.dataSourceManager.dataSources.get(dataSourceKey);
|
|
50
|
-
if (!dataSource) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const collection = dataSource.collectionManager.getCollection(collectionName);
|
|
54
|
-
if (!collection) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
collection.removeField(name);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
-
0 && (module.exports = {
|
|
62
|
-
DataSourcesFieldModel
|
|
63
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
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 { Model } from '@nocobase/database';
|
|
10
|
-
import { ACL } from '@nocobase/acl';
|
|
11
|
-
import { Transaction } from 'sequelize';
|
|
12
|
-
export declare class DataSourcesRolesModel extends Model {
|
|
13
|
-
writeToAcl(options: {
|
|
14
|
-
acl: ACL;
|
|
15
|
-
transaction?: Transaction;
|
|
16
|
-
}): Promise<void>;
|
|
17
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
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_roles_model_exports = {};
|
|
28
|
-
__export(data_sources_roles_model_exports, {
|
|
29
|
-
DataSourcesRolesModel: () => DataSourcesRolesModel
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(data_sources_roles_model_exports);
|
|
32
|
-
var import_database = require("@nocobase/database");
|
|
33
|
-
class DataSourcesRolesModel extends import_database.Model {
|
|
34
|
-
async writeToAcl(options) {
|
|
35
|
-
const { acl, transaction } = options;
|
|
36
|
-
const roleName = this.get("roleName");
|
|
37
|
-
let role = acl.getRole(roleName);
|
|
38
|
-
if (!role) {
|
|
39
|
-
role = acl.define({
|
|
40
|
-
role: roleName
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
role.setStrategy({
|
|
44
|
-
...this.get("strategy") || {}
|
|
45
|
-
});
|
|
46
|
-
const resources = await this.db.getRepository("dataSourcesRolesResources").find({
|
|
47
|
-
filter: {
|
|
48
|
-
roleName,
|
|
49
|
-
dataSourceKey: this.get("dataSourceKey")
|
|
50
|
-
},
|
|
51
|
-
transaction
|
|
52
|
-
});
|
|
53
|
-
for (const resource of resources) {
|
|
54
|
-
await resource.writeToACL({
|
|
55
|
-
acl,
|
|
56
|
-
transaction
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
-
0 && (module.exports = {
|
|
63
|
-
DataSourcesRolesModel
|
|
64
|
-
});
|
package/dist/server/plugin.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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 { Plugin } from '@nocobase/server';
|
|
10
|
-
type DataSourceState = 'loading' | 'loaded' | 'loading-failed' | 'reloading' | 'reloading-failed';
|
|
11
|
-
export declare class PluginDataSourceManagerServer extends Plugin {
|
|
12
|
-
dataSourceErrors: {
|
|
13
|
-
[dataSourceKey: string]: Error;
|
|
14
|
-
};
|
|
15
|
-
dataSourceStatus: {
|
|
16
|
-
[dataSourceKey: string]: DataSourceState;
|
|
17
|
-
};
|
|
18
|
-
beforeLoad(): Promise<void>;
|
|
19
|
-
load(): Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
export default PluginDataSourceManagerServer;
|
package/dist/server/plugin.js
DELETED
|
@@ -1,443 +0,0 @@
|
|
|
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 plugin_exports = {};
|
|
38
|
-
__export(plugin_exports, {
|
|
39
|
-
PluginDataSourceManagerServer: () => PluginDataSourceManagerServer,
|
|
40
|
-
default: () => plugin_default
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(plugin_exports);
|
|
43
|
-
var import_server = require("@nocobase/server");
|
|
44
|
-
var import_path = require("path");
|
|
45
|
-
var import_data_sources_collection_model = require("./models/data-sources-collection-model");
|
|
46
|
-
var import_data_sources_field_model = require("./models/data-sources-field-model");
|
|
47
|
-
var import_data_sources_collections = __toESM(require("./resourcers/data-sources-collections"));
|
|
48
|
-
var import_data_sources_collections_fields = __toESM(require("./resourcers/data-sources-collections-fields"));
|
|
49
|
-
var import_data_sources_resources = __toESM(require("./resourcers/data-sources-resources"));
|
|
50
|
-
var import_data_sources_roles = __toESM(require("./resourcers/data-sources-roles"));
|
|
51
|
-
var import_roles_data_sources_collections = require("./resourcers/roles-data-sources-collections");
|
|
52
|
-
var import_lodash = __toESM(require("lodash"));
|
|
53
|
-
var import_connections_roles_resources = require("./models/connections-roles-resources");
|
|
54
|
-
var import_connections_roles_resources_action = require("./models/connections-roles-resources-action");
|
|
55
|
-
var import_data_source = require("./models/data-source");
|
|
56
|
-
var import_data_sources_roles_model = require("./models/data-sources-roles-model");
|
|
57
|
-
const canRefreshStatus = ["loaded", "loading-failed", "reloading-failed"];
|
|
58
|
-
class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
59
|
-
dataSourceErrors = {};
|
|
60
|
-
dataSourceStatus = {};
|
|
61
|
-
async beforeLoad() {
|
|
62
|
-
this.app.db.registerModels({
|
|
63
|
-
DataSourcesCollectionModel: import_data_sources_collection_model.DataSourcesCollectionModel,
|
|
64
|
-
DataSourcesFieldModel: import_data_sources_field_model.DataSourcesFieldModel,
|
|
65
|
-
DataSourcesRolesModel: import_data_sources_roles_model.DataSourcesRolesModel,
|
|
66
|
-
DataSourcesRolesResourcesModel: import_connections_roles_resources.DataSourcesRolesResourcesModel,
|
|
67
|
-
DataSourcesRolesResourcesActionModel: import_connections_roles_resources_action.DataSourcesRolesResourcesActionModel,
|
|
68
|
-
DataSourceModel: import_data_source.DataSourceModel
|
|
69
|
-
});
|
|
70
|
-
this.app.db.on("dataSourcesFields.beforeCreate", async (model, options) => {
|
|
71
|
-
const validatePresent = (name) => {
|
|
72
|
-
if (!model.get(name)) {
|
|
73
|
-
throw new Error(`"${name}" is required`);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
const validatePresents = (names) => {
|
|
77
|
-
names.forEach((name) => validatePresent(name));
|
|
78
|
-
};
|
|
79
|
-
const type = model.get("type");
|
|
80
|
-
if (type === "belongsTo") {
|
|
81
|
-
validatePresents(["foreignKey", "targetKey", "target"]);
|
|
82
|
-
}
|
|
83
|
-
if (type === "hasMany") {
|
|
84
|
-
validatePresents(["foreignKey", "sourceKey", "target"]);
|
|
85
|
-
}
|
|
86
|
-
if (type == "hasOne") {
|
|
87
|
-
validatePresents(["foreignKey", "sourceKey", "target"]);
|
|
88
|
-
}
|
|
89
|
-
if (type === "belongsToMany") {
|
|
90
|
-
validatePresents(["foreignKey", "otherKey", "sourceKey", "targetKey", "through", "target"]);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
this.app.db.on("dataSources.beforeCreate", async (model, options) => {
|
|
94
|
-
this.dataSourceStatus[model.get("key")] = "loading";
|
|
95
|
-
});
|
|
96
|
-
this.app.db.on("dataSources.beforeSave", async (model) => {
|
|
97
|
-
if (model.changed("options") && !model.isMainRecord()) {
|
|
98
|
-
const dataSourceOptions = model.get("options");
|
|
99
|
-
const type = model.get("type");
|
|
100
|
-
const klass = this.app.dataSourceManager.factory.getClass(type);
|
|
101
|
-
try {
|
|
102
|
-
await klass.testConnection(dataSourceOptions);
|
|
103
|
-
} catch (error) {
|
|
104
|
-
throw new Error(`Test connection failed: ${error.message}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
this.app.db.on("dataSources.afterSave", async (model, options) => {
|
|
109
|
-
if (model.changed("options") && !model.isMainRecord()) {
|
|
110
|
-
model.loadIntoApplication({
|
|
111
|
-
app: this.app
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
this.app.db.on("dataSources.afterCreate", async (model, options) => {
|
|
116
|
-
if (model.isMainRecord()) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const { transaction } = options;
|
|
120
|
-
await this.app.db.getRepository("dataSourcesRolesResourcesScopes").create({
|
|
121
|
-
values: {
|
|
122
|
-
dataSourceKey: model.get("key"),
|
|
123
|
-
key: "all",
|
|
124
|
-
name: '{{t("All records")}}',
|
|
125
|
-
scope: {}
|
|
126
|
-
},
|
|
127
|
-
transaction
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
const app = this.app;
|
|
131
|
-
this.app.use(async (ctx, next) => {
|
|
132
|
-
await next();
|
|
133
|
-
if (!ctx.action) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
const { actionName, resourceName, params } = ctx.action;
|
|
137
|
-
if (resourceName === "dataSources" && actionName == "list") {
|
|
138
|
-
let dataPath = "body";
|
|
139
|
-
if (Array.isArray(ctx.body["data"])) {
|
|
140
|
-
dataPath = "body.data";
|
|
141
|
-
}
|
|
142
|
-
const items = import_lodash.default.get(ctx, dataPath);
|
|
143
|
-
if (!Array.isArray(items)) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
import_lodash.default.set(
|
|
147
|
-
ctx,
|
|
148
|
-
dataPath,
|
|
149
|
-
items.map((item) => {
|
|
150
|
-
const data = item.toJSON();
|
|
151
|
-
if (item.isMainRecord()) {
|
|
152
|
-
data["status"] = "loaded";
|
|
153
|
-
return data;
|
|
154
|
-
}
|
|
155
|
-
const dataSourceStatus = this.dataSourceStatus[item.get("key")];
|
|
156
|
-
data["status"] = dataSourceStatus;
|
|
157
|
-
if (dataSourceStatus === "loading-failed" || dataSourceStatus === "reloading-failed") {
|
|
158
|
-
data["errorMessage"] = this.dataSourceErrors[item.get("key")].message;
|
|
159
|
-
}
|
|
160
|
-
return data;
|
|
161
|
-
})
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
const plugin = this;
|
|
166
|
-
const mapDataSourceWithCollection = (dataSourceModel, appendCollections = true) => {
|
|
167
|
-
const dataSource = app.dataSourceManager.dataSources.get(dataSourceModel.get("key"));
|
|
168
|
-
const dataSourceStatus = plugin.dataSourceStatus[dataSourceModel.get("key")];
|
|
169
|
-
const item = {
|
|
170
|
-
key: dataSourceModel.get("key"),
|
|
171
|
-
displayName: dataSourceModel.get("displayName"),
|
|
172
|
-
status: dataSourceStatus,
|
|
173
|
-
type: dataSourceModel.get("type"),
|
|
174
|
-
// @ts-ignore
|
|
175
|
-
isDBInstance: !!(dataSource == null ? void 0 : dataSource.collectionManager.db)
|
|
176
|
-
};
|
|
177
|
-
if (dataSourceStatus === "loading-failed" || dataSourceStatus === "reloading-failed") {
|
|
178
|
-
item["errorMessage"] = plugin.dataSourceErrors[dataSourceModel.get("key")].message;
|
|
179
|
-
}
|
|
180
|
-
if (!dataSource) {
|
|
181
|
-
return item;
|
|
182
|
-
}
|
|
183
|
-
if (appendCollections) {
|
|
184
|
-
const collections = dataSource.collectionManager.getCollections();
|
|
185
|
-
item.collections = collections.map((collection) => {
|
|
186
|
-
const collectionOptions = collection.options;
|
|
187
|
-
const fields = [...collection.fields.values()].map((field) => field.options);
|
|
188
|
-
return {
|
|
189
|
-
...collectionOptions,
|
|
190
|
-
fields
|
|
191
|
-
};
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
return item;
|
|
195
|
-
};
|
|
196
|
-
this.app.resourcer.use(async (ctx, next) => {
|
|
197
|
-
if (!ctx.action) {
|
|
198
|
-
await next();
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const { actionName, resourceName, params } = ctx.action;
|
|
202
|
-
if (resourceName === "dataSources" && actionName == "list") {
|
|
203
|
-
if (!params.sort) {
|
|
204
|
-
params.sort = ["-fixed", "createdAt"];
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
await next();
|
|
208
|
-
});
|
|
209
|
-
this.app.use(async (ctx, next) => {
|
|
210
|
-
await next();
|
|
211
|
-
if (!ctx.action) {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
const { actionName, resourceName, params } = ctx.action;
|
|
215
|
-
if (resourceName === "dataSources" && actionName == "get") {
|
|
216
|
-
let appendCollections = false;
|
|
217
|
-
const appends = ctx.action.params.appends;
|
|
218
|
-
if (appends && appends.includes("collections")) {
|
|
219
|
-
appendCollections = true;
|
|
220
|
-
}
|
|
221
|
-
if (ctx.body.data) {
|
|
222
|
-
ctx.body.data = mapDataSourceWithCollection(ctx.body.data, appendCollections);
|
|
223
|
-
} else {
|
|
224
|
-
ctx.body = mapDataSourceWithCollection(ctx.body, appendCollections);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
this.app.actions({
|
|
229
|
-
async ["dataSources:listEnabled"](ctx, next) {
|
|
230
|
-
const dataSources = await ctx.db.getRepository("dataSources").find({
|
|
231
|
-
filter: {
|
|
232
|
-
enabled: true,
|
|
233
|
-
"type.$ne": "main"
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
ctx.body = dataSources.map((dataSourceModel) => {
|
|
237
|
-
return mapDataSourceWithCollection(dataSourceModel);
|
|
238
|
-
});
|
|
239
|
-
await next();
|
|
240
|
-
},
|
|
241
|
-
async ["dataSources:testConnection"](ctx, next) {
|
|
242
|
-
const { values } = ctx.action.params;
|
|
243
|
-
const { options, type } = values;
|
|
244
|
-
const klass = ctx.app.dataSourceManager.factory.getClass(type);
|
|
245
|
-
try {
|
|
246
|
-
await klass.testConnection(options);
|
|
247
|
-
} catch (error) {
|
|
248
|
-
throw new Error(`Test connection failed: ${error.message}`);
|
|
249
|
-
}
|
|
250
|
-
ctx.body = {
|
|
251
|
-
success: true
|
|
252
|
-
};
|
|
253
|
-
await next();
|
|
254
|
-
},
|
|
255
|
-
async ["dataSources:refresh"](ctx, next) {
|
|
256
|
-
const { filterByTk, clientStatus } = ctx.action.params;
|
|
257
|
-
const dataSourceModel = await ctx.db.getRepository("dataSources").findOne({
|
|
258
|
-
filter: {
|
|
259
|
-
key: filterByTk
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
const currentStatus = plugin.dataSourceStatus[filterByTk];
|
|
263
|
-
if (canRefreshStatus.includes(currentStatus) && (clientStatus ? clientStatus && canRefreshStatus.includes(clientStatus) : true)) {
|
|
264
|
-
dataSourceModel.loadIntoApplication({
|
|
265
|
-
app: ctx.app
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
ctx.body = {
|
|
269
|
-
status: plugin.dataSourceStatus[filterByTk]
|
|
270
|
-
};
|
|
271
|
-
await next();
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
this.app.resourcer.define(import_data_sources_collections.default);
|
|
275
|
-
this.app.resourcer.define(import_data_sources_collections_fields.default);
|
|
276
|
-
this.app.resourcer.define(import_roles_data_sources_collections.rolesRemoteCollectionsResourcer);
|
|
277
|
-
this.app.resourcer.define(import_data_sources_roles.default);
|
|
278
|
-
this.app.resourcer.define(import_data_sources_resources.default);
|
|
279
|
-
this.app.resourcer.define({
|
|
280
|
-
name: "dataSources"
|
|
281
|
-
});
|
|
282
|
-
this.app.db.on("dataSourcesFields.afterSave", async (model) => {
|
|
283
|
-
model.load({
|
|
284
|
-
app: this.app
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
this.app.db.on("dataSourcesFields.afterDestroy", async (model) => {
|
|
288
|
-
model.unload({
|
|
289
|
-
app: this.app
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
this.app.db.on("dataSourcesCollections.afterSave", async (model) => {
|
|
293
|
-
model.load({
|
|
294
|
-
app: this.app
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
this.app.db.on("dataSources.afterDestroy", async (model) => {
|
|
298
|
-
this.app.dataSourceManager.dataSources.delete(model.get("key"));
|
|
299
|
-
});
|
|
300
|
-
this.app.on("afterStart", async (app2) => {
|
|
301
|
-
const dataSourcesRecords = await this.app.db.getRepository("dataSources").find({
|
|
302
|
-
filter: {
|
|
303
|
-
enabled: true
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
const loadPromises = dataSourcesRecords.map((dataSourceRecord) => {
|
|
307
|
-
if (dataSourceRecord.isMainRecord()) {
|
|
308
|
-
return dataSourceRecord.loadIntoACL({ app: app2, acl: app2.acl });
|
|
309
|
-
}
|
|
310
|
-
return dataSourceRecord.loadIntoApplication({ app: app2, loadAtAfterStart: true });
|
|
311
|
-
});
|
|
312
|
-
this.app.setMaintainingMessage("Loading data sources...");
|
|
313
|
-
await Promise.all(loadPromises);
|
|
314
|
-
});
|
|
315
|
-
this.app.db.on(
|
|
316
|
-
"dataSourcesRolesResources.afterSaveWithAssociations",
|
|
317
|
-
async (model, options) => {
|
|
318
|
-
const { transaction } = options;
|
|
319
|
-
const dataSource = this.app.dataSourceManager.dataSources.get(model.get("dataSourceKey"));
|
|
320
|
-
await model.writeToACL({
|
|
321
|
-
acl: dataSource.acl,
|
|
322
|
-
transaction
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
);
|
|
326
|
-
this.app.db.on(
|
|
327
|
-
"dataSourcesRolesResourcesActions.afterUpdateWithAssociations",
|
|
328
|
-
async (model, options) => {
|
|
329
|
-
const { transaction } = options;
|
|
330
|
-
const resource = await model.getResource({
|
|
331
|
-
transaction
|
|
332
|
-
});
|
|
333
|
-
const dataSource = this.app.dataSourceManager.dataSources.get(resource.get("dataSourceKey"));
|
|
334
|
-
await resource.writeToACL({
|
|
335
|
-
acl: dataSource.acl,
|
|
336
|
-
transaction
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
);
|
|
340
|
-
this.app.db.on("dataSourcesRolesResources.afterDestroy", async (model, options) => {
|
|
341
|
-
const dataSource = this.app.dataSourceManager.dataSources.get(model.get("dataSourceKey"));
|
|
342
|
-
const roleName = model.get("roleName");
|
|
343
|
-
const role = dataSource.acl.getRole(roleName);
|
|
344
|
-
if (role) {
|
|
345
|
-
role.revokeResource(model.get("name"));
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
this.app.db.on("dataSourcesRoles.afterSave", async (model, options) => {
|
|
349
|
-
const { transaction } = options;
|
|
350
|
-
const dataSource = this.app.dataSourceManager.dataSources.get(model.get("dataSourceKey"));
|
|
351
|
-
await model.writeToAcl({
|
|
352
|
-
acl: dataSource.acl,
|
|
353
|
-
transaction
|
|
354
|
-
});
|
|
355
|
-
await this.app.db.getRepository("roles").update({
|
|
356
|
-
filter: {
|
|
357
|
-
name: model.get("roleName")
|
|
358
|
-
},
|
|
359
|
-
values: {
|
|
360
|
-
strategy: model.get("strategy")
|
|
361
|
-
},
|
|
362
|
-
hooks: false,
|
|
363
|
-
transaction
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
this.app.on("acl:writeResources", async ({ roleName, transaction }) => {
|
|
367
|
-
const dataSource = this.app.dataSourceManager.dataSources.get("main");
|
|
368
|
-
const dataSourceRole = await this.app.db.getRepository("dataSourcesRoles").findOne({
|
|
369
|
-
filter: {
|
|
370
|
-
dataSourceKey: "main",
|
|
371
|
-
roleName
|
|
372
|
-
},
|
|
373
|
-
transaction
|
|
374
|
-
});
|
|
375
|
-
await dataSourceRole.writeToAcl({
|
|
376
|
-
acl: dataSource.acl,
|
|
377
|
-
transaction
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
this.app.resourcer.use(async (ctx, next) => {
|
|
381
|
-
const action = ctx.action;
|
|
382
|
-
await next();
|
|
383
|
-
const { resourceName, actionName } = action.params;
|
|
384
|
-
if (resourceName === "roles" && actionName == "check") {
|
|
385
|
-
const roleName = ctx.state.currentRole;
|
|
386
|
-
const dataSources = await ctx.db.getRepository("dataSources").find();
|
|
387
|
-
ctx.bodyMeta = {
|
|
388
|
-
dataSources: dataSources.reduce((carry, dataSourceModel) => {
|
|
389
|
-
const dataSource = this.app.dataSourceManager.dataSources.get(dataSourceModel.get("key"));
|
|
390
|
-
if (!dataSource) {
|
|
391
|
-
return carry;
|
|
392
|
-
}
|
|
393
|
-
const dataSourceStatus = this.dataSourceStatus[dataSourceModel.get("key")];
|
|
394
|
-
if (dataSourceStatus !== "loaded") {
|
|
395
|
-
return carry;
|
|
396
|
-
}
|
|
397
|
-
const aclInstance = dataSource.acl;
|
|
398
|
-
const roleInstance = aclInstance.getRole(roleName);
|
|
399
|
-
const dataObj = {
|
|
400
|
-
strategy: {},
|
|
401
|
-
resources: roleInstance ? [...roleInstance.resources.keys()] : [],
|
|
402
|
-
actions: {}
|
|
403
|
-
};
|
|
404
|
-
if (roleInstance) {
|
|
405
|
-
const data = roleInstance.toJSON();
|
|
406
|
-
dataObj["name"] = data["name"];
|
|
407
|
-
dataObj["strategy"] = data["strategy"];
|
|
408
|
-
dataObj["actions"] = data["actions"];
|
|
409
|
-
}
|
|
410
|
-
carry[dataSourceModel.get("key")] = dataObj;
|
|
411
|
-
return carry;
|
|
412
|
-
}, {})
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
this.app.acl.registerSnippet({
|
|
417
|
-
name: `pm.data-source-manager`,
|
|
418
|
-
actions: [
|
|
419
|
-
"dataSources:*",
|
|
420
|
-
"dataSources.collections:*",
|
|
421
|
-
"dataSourcesCollections.fields:*",
|
|
422
|
-
"roles.dataSourceResources"
|
|
423
|
-
]
|
|
424
|
-
});
|
|
425
|
-
this.app.acl.allow("dataSources", "listEnabled", "loggedIn");
|
|
426
|
-
this.app.acl.allow("dataSources", "get", "loggedIn");
|
|
427
|
-
this.app.acl.addFixedParams("dataSources", "destroy", () => {
|
|
428
|
-
return {
|
|
429
|
-
filter: {
|
|
430
|
-
"key.$ne": "main"
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
async load() {
|
|
436
|
-
await this.importCollections((0, import_path.resolve)(__dirname, "collections"));
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
var plugin_default = PluginDataSourceManagerServer;
|
|
440
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
441
|
-
0 && (module.exports = {
|
|
442
|
-
PluginDataSourceManagerServer
|
|
443
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
declare const _default: {
|
|
10
|
-
name: string;
|
|
11
|
-
actions: {
|
|
12
|
-
list(ctx: any, next: any): Promise<void>;
|
|
13
|
-
get(ctx: any, next: any): Promise<void>;
|
|
14
|
-
update(ctx: any, next: any): Promise<void>;
|
|
15
|
-
create(ctx: any, next: any): Promise<void>;
|
|
16
|
-
destroy(ctx: any, next: any): Promise<void>;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export default _default;
|