@nocobase/plugin-data-source-manager 1.4.0-alpha → 1.4.0-alpha.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.
package/dist/externalVersion.js
CHANGED
|
@@ -8,26 +8,27 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "1.4.0-alpha",
|
|
11
|
+
"@nocobase/client": "1.4.0-alpha.1",
|
|
12
12
|
"react": "18.2.0",
|
|
13
|
-
"@nocobase/plugin-acl": "1.4.0-alpha",
|
|
14
|
-
"@nocobase/utils": "1.4.0-alpha",
|
|
15
|
-
"@nocobase/server": "1.4.0-alpha",
|
|
13
|
+
"@nocobase/plugin-acl": "1.4.0-alpha.1",
|
|
14
|
+
"@nocobase/utils": "1.4.0-alpha.1",
|
|
15
|
+
"@nocobase/server": "1.4.0-alpha.1",
|
|
16
16
|
"lodash": "4.17.21",
|
|
17
|
+
"@nocobase/data-source-manager": "1.4.0-alpha.1",
|
|
17
18
|
"@ant-design/icons": "5.2.6",
|
|
18
19
|
"antd": "5.12.8",
|
|
19
20
|
"react-router-dom": "6.21.0",
|
|
20
|
-
"@formily/shared": "2.3.
|
|
21
|
+
"@formily/shared": "2.3.2",
|
|
21
22
|
"react-i18next": "11.18.6",
|
|
22
23
|
"@formily/react": "2.3.0",
|
|
23
24
|
"@emotion/css": "11.13.0",
|
|
24
|
-
"@nocobase/database": "1.4.0-alpha",
|
|
25
|
-
"@nocobase/acl": "1.4.0-alpha",
|
|
25
|
+
"@nocobase/database": "1.4.0-alpha.1",
|
|
26
|
+
"@nocobase/acl": "1.4.0-alpha.1",
|
|
26
27
|
"sequelize": "6.35.2",
|
|
27
|
-
"@nocobase/test": "1.4.0-alpha",
|
|
28
|
+
"@nocobase/test": "1.4.0-alpha.1",
|
|
28
29
|
"@formily/antd-v5": "1.1.9",
|
|
29
30
|
"@formily/core": "2.3.0",
|
|
30
31
|
"@formily/reactive": "2.3.0",
|
|
31
32
|
"@dnd-kit/core": "6.1.0",
|
|
32
|
-
"antd-style": "3.
|
|
33
|
+
"antd-style": "3.7.1"
|
|
33
34
|
};
|
|
@@ -97,27 +97,30 @@ class DataSourceModel extends import_database.Model {
|
|
|
97
97
|
}
|
|
98
98
|
const type = this.get("type");
|
|
99
99
|
const createOptions = this.get("options");
|
|
100
|
-
const dataSource = app.dataSourceManager.factory.create(type, {
|
|
101
|
-
...createOptions,
|
|
102
|
-
name: dataSourceKey,
|
|
103
|
-
logger: app.logger.child({ dataSourceKey }),
|
|
104
|
-
sqlLogger: app.sqlLogger.child({ dataSourceKey })
|
|
105
|
-
});
|
|
106
|
-
if (loadAtAfterStart) {
|
|
107
|
-
dataSource.on("loadMessage", ({ message }) => {
|
|
108
|
-
app.setMaintainingMessage(`${message} in data source ${this.get("displayName")}`);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
const acl = dataSource.acl;
|
|
112
|
-
for (const [actionName, actionParams] of Object.entries(availableActions)) {
|
|
113
|
-
acl.setAvailableAction(actionName, actionParams);
|
|
114
|
-
}
|
|
115
|
-
acl.allow("*", "*", (ctx) => {
|
|
116
|
-
return ctx.state.currentRole === "root";
|
|
117
|
-
});
|
|
118
|
-
dataSource.resourceManager.use(import_plugin_acl.setCurrentRole, { tag: "setCurrentRole", before: "acl", after: "auth" });
|
|
119
|
-
await this.loadIntoACL({ app, acl, transaction: options.transaction });
|
|
120
100
|
try {
|
|
101
|
+
const dataSource = app.dataSourceManager.factory.create(type, {
|
|
102
|
+
...createOptions,
|
|
103
|
+
name: dataSourceKey,
|
|
104
|
+
logger: app.logger.child({ dataSourceKey }),
|
|
105
|
+
sqlLogger: app.sqlLogger.child({ dataSourceKey })
|
|
106
|
+
});
|
|
107
|
+
dataSource.on("loadingProgress", (progress) => {
|
|
108
|
+
pluginDataSourceManagerServer.dataSourceLoadingProgress[dataSourceKey] = progress;
|
|
109
|
+
});
|
|
110
|
+
if (loadAtAfterStart) {
|
|
111
|
+
dataSource.on("loadMessage", ({ message }) => {
|
|
112
|
+
app.setMaintainingMessage(`${message} in data source ${this.get("displayName")}`);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const acl = dataSource.acl;
|
|
116
|
+
for (const [actionName, actionParams] of Object.entries(availableActions)) {
|
|
117
|
+
acl.setAvailableAction(actionName, actionParams);
|
|
118
|
+
}
|
|
119
|
+
acl.allow("*", "*", (ctx) => {
|
|
120
|
+
return ctx.state.currentRole === "root";
|
|
121
|
+
});
|
|
122
|
+
dataSource.resourceManager.use(import_plugin_acl.setCurrentRole, { tag: "setCurrentRole", before: "acl", after: "auth" });
|
|
123
|
+
await this.loadIntoACL({ app, acl, transaction: options.transaction });
|
|
121
124
|
await app.dataSourceManager.add(dataSource, {
|
|
122
125
|
localData: await this.loadLocalData()
|
|
123
126
|
});
|
package/dist/server/plugin.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
import { Plugin } from '@nocobase/server';
|
|
10
|
+
import { LoadingProgress } from '@nocobase/data-source-manager';
|
|
10
11
|
type DataSourceState = 'loading' | 'loaded' | 'loading-failed' | 'reloading' | 'reloading-failed';
|
|
11
12
|
export declare class PluginDataSourceManagerServer extends Plugin {
|
|
12
13
|
dataSourceErrors: {
|
|
@@ -15,6 +16,9 @@ export declare class PluginDataSourceManagerServer extends Plugin {
|
|
|
15
16
|
dataSourceStatus: {
|
|
16
17
|
[dataSourceKey: string]: DataSourceState;
|
|
17
18
|
};
|
|
19
|
+
dataSourceLoadingProgress: {
|
|
20
|
+
[dataSourceKey: string]: LoadingProgress;
|
|
21
|
+
};
|
|
18
22
|
beforeLoad(): Promise<void>;
|
|
19
23
|
load(): Promise<void>;
|
|
20
24
|
}
|
package/dist/server/plugin.js
CHANGED
|
@@ -58,6 +58,7 @@ const canRefreshStatus = ["loaded", "loading-failed", "reloading-failed"];
|
|
|
58
58
|
class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
59
59
|
dataSourceErrors = {};
|
|
60
60
|
dataSourceStatus = {};
|
|
61
|
+
dataSourceLoadingProgress = {};
|
|
61
62
|
async beforeLoad() {
|
|
62
63
|
this.app.db.registerModels({
|
|
63
64
|
DataSourcesCollectionModel: import_data_sources_collection_model.DataSourcesCollectionModel,
|
|
@@ -98,6 +99,9 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
|
98
99
|
const dataSourceOptions = model.get("options");
|
|
99
100
|
const type = model.get("type");
|
|
100
101
|
const klass = this.app.dataSourceManager.factory.getClass(type);
|
|
102
|
+
if (!klass) {
|
|
103
|
+
throw new Error(`Data source type "${type}" is not registered`);
|
|
104
|
+
}
|
|
101
105
|
try {
|
|
102
106
|
await klass.testConnection(dataSourceOptions);
|
|
103
107
|
} catch (error) {
|
|
@@ -128,7 +132,7 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
|
128
132
|
});
|
|
129
133
|
});
|
|
130
134
|
const app = this.app;
|
|
131
|
-
this.app.use(async (ctx, next)
|
|
135
|
+
this.app.use(async function setDataSourceListItemStatus(ctx, next) {
|
|
132
136
|
await next();
|
|
133
137
|
if (!ctx.action) {
|
|
134
138
|
return;
|
|
@@ -152,10 +156,10 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
|
152
156
|
data["status"] = "loaded";
|
|
153
157
|
return data;
|
|
154
158
|
}
|
|
155
|
-
const dataSourceStatus =
|
|
159
|
+
const dataSourceStatus = plugin.dataSourceStatus[item.get("key")];
|
|
156
160
|
data["status"] = dataSourceStatus;
|
|
157
161
|
if (dataSourceStatus === "loading-failed" || dataSourceStatus === "reloading-failed") {
|
|
158
|
-
data["errorMessage"] =
|
|
162
|
+
data["errorMessage"] = plugin.dataSourceErrors[item.get("key")].message;
|
|
159
163
|
}
|
|
160
164
|
return data;
|
|
161
165
|
})
|
|
@@ -205,7 +209,7 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
|
205
209
|
}
|
|
206
210
|
return item;
|
|
207
211
|
};
|
|
208
|
-
this.app.
|
|
212
|
+
this.app.resourceManager.use(async function setDataSourceListDefaultSort(ctx, next) {
|
|
209
213
|
if (!ctx.action) {
|
|
210
214
|
await next();
|
|
211
215
|
return;
|
|
@@ -218,7 +222,7 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
|
218
222
|
}
|
|
219
223
|
await next();
|
|
220
224
|
});
|
|
221
|
-
this.app.use(async (ctx, next)
|
|
225
|
+
this.app.use(async function handleAppendDataSourceCollection(ctx, next) {
|
|
222
226
|
await next();
|
|
223
227
|
if (!ctx.action) {
|
|
224
228
|
return;
|
|
@@ -305,7 +309,9 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
|
305
309
|
});
|
|
306
310
|
this.app.db.on("dataSourcesCollections.afterDestroy", async (model) => {
|
|
307
311
|
const dataSource = this.app.dataSourceManager.dataSources.get(model.get("dataSourceKey"));
|
|
308
|
-
dataSource
|
|
312
|
+
if (dataSource) {
|
|
313
|
+
dataSource.collectionManager.removeCollection(model.get("name"));
|
|
314
|
+
}
|
|
309
315
|
});
|
|
310
316
|
this.app.db.on("dataSourcesFields.afterSaveWithAssociations", async (model) => {
|
|
311
317
|
model.load({
|
|
@@ -409,7 +415,8 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
|
409
415
|
transaction
|
|
410
416
|
});
|
|
411
417
|
});
|
|
412
|
-
|
|
418
|
+
const self = this;
|
|
419
|
+
this.app.resourceManager.use(async function appendDataToRolesCheck(ctx, next) {
|
|
413
420
|
const action = ctx.action;
|
|
414
421
|
await next();
|
|
415
422
|
const { resourceName, actionName } = action.params;
|
|
@@ -418,11 +425,11 @@ class PluginDataSourceManagerServer extends import_server.Plugin {
|
|
|
418
425
|
const dataSources = await ctx.db.getRepository("dataSources").find();
|
|
419
426
|
ctx.bodyMeta = {
|
|
420
427
|
dataSources: dataSources.reduce((carry, dataSourceModel) => {
|
|
421
|
-
const dataSource =
|
|
428
|
+
const dataSource = self.app.dataSourceManager.dataSources.get(dataSourceModel.get("key"));
|
|
422
429
|
if (!dataSource) {
|
|
423
430
|
return carry;
|
|
424
431
|
}
|
|
425
|
-
const dataSourceStatus =
|
|
432
|
+
const dataSourceStatus = self.dataSourceStatus[dataSourceModel.get("key")];
|
|
426
433
|
if (dataSourceStatus !== "loaded") {
|
|
427
434
|
return carry;
|
|
428
435
|
}
|
|
@@ -48,6 +48,22 @@ var data_sources_collections_default = {
|
|
|
48
48
|
const params = ctx.action.params;
|
|
49
49
|
const { associatedIndex: dataSourceKey } = params;
|
|
50
50
|
const dataSource = ctx.app.dataSourceManager.dataSources.get(dataSourceKey);
|
|
51
|
+
const plugin = ctx.app.pm.get("data-source-manager");
|
|
52
|
+
const dataSourceStatus = plugin.dataSourceStatus[dataSourceKey];
|
|
53
|
+
if (dataSourceStatus === "loading-failed") {
|
|
54
|
+
const error = plugin.dataSourceErrors[dataSourceKey];
|
|
55
|
+
if (error) {
|
|
56
|
+
throw new Error(`dataSource ${dataSourceKey} loading failed: ${error.message}`);
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`dataSource ${dataSourceKey} loading failed`);
|
|
59
|
+
}
|
|
60
|
+
if (["loading", "reloading"].includes(dataSourceStatus)) {
|
|
61
|
+
const progress = plugin.dataSourceLoadingProgress[dataSourceKey];
|
|
62
|
+
if (progress) {
|
|
63
|
+
throw new Error(`dataSource ${dataSourceKey} is ${dataSourceStatus} (${progress.loaded}/${progress.total})`);
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`dataSource ${dataSourceKey} is ${dataSourceStatus}`);
|
|
66
|
+
}
|
|
51
67
|
if (!dataSource) {
|
|
52
68
|
throw new Error(`dataSource ${dataSourceKey} not found`);
|
|
53
69
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-data-source-manager",
|
|
3
|
-
"version": "1.4.0-alpha",
|
|
3
|
+
"version": "1.4.0-alpha.1",
|
|
4
4
|
"main": "dist/server/index.js",
|
|
5
5
|
"displayName": "Data source manager",
|
|
6
6
|
"displayName.zh-CN": "数据源管理",
|
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
"keywords": [
|
|
18
18
|
"Data model tools"
|
|
19
19
|
],
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "b42379db55cd8774d3543c8d6cdc566434d3f170"
|
|
21
21
|
}
|