@nocobase/plugin-data-source-main 1.5.0-alpha.5 → 1.5.0-beta.2
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/index.js +1 -1
- package/dist/externalVersion.js +7 -6
- package/dist/server/server.d.ts +1 -1
- package/dist/server/server.js +9 -57
- package/package.json +3 -3
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
(function(e,n){typeof exports=="object"&&typeof module!="undefined"?n(exports,require("@nocobase/client")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client"],n):(e=typeof globalThis!="undefined"?globalThis:e||self,n(e["@nocobase/plugin-data-source-main"]={},e["@nocobase/client"]))})(this,function(e,n){"use strict";var a=(e,n,o)=>new Promise((u,d)=>{var c=i=>{try{t(o.next(i))}catch(s){d(s)}},l=i=>{try{t(o.throw(i))}catch(s){d(s)}},t=i=>i.done?u(i.value):Promise.resolve(i.value).then(c,l);t((o=o.apply(e,n)).next())});class o extends n.Plugin{load(){return a(this,null,function*(){})}}e.default=o,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/externalVersion.js
CHANGED
|
@@ -8,13 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
"@nocobase/client": "1.5.0-
|
|
12
|
-
"@nocobase/database": "1.5.0-
|
|
13
|
-
"@nocobase/plugin-error-handler": "1.5.0-
|
|
14
|
-
"@nocobase/server": "1.5.0-
|
|
11
|
+
"@nocobase/client": "1.5.0-beta.2",
|
|
12
|
+
"@nocobase/database": "1.5.0-beta.2",
|
|
13
|
+
"@nocobase/plugin-error-handler": "1.5.0-beta.2",
|
|
14
|
+
"@nocobase/server": "1.5.0-beta.2",
|
|
15
|
+
"async-mutex": "0.3.2",
|
|
15
16
|
"lodash": "4.17.21",
|
|
16
|
-
"@nocobase/test": "1.5.0-
|
|
17
|
-
"@nocobase/utils": "1.5.0-
|
|
17
|
+
"@nocobase/test": "1.5.0-beta.2",
|
|
18
|
+
"@nocobase/utils": "1.5.0-beta.2",
|
|
18
19
|
"sequelize": "6.35.2",
|
|
19
20
|
"dayjs": "1.11.10"
|
|
20
21
|
};
|
package/dist/server/server.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { Plugin } from '@nocobase/server';
|
|
|
11
11
|
export declare class PluginDataSourceMainServer extends Plugin {
|
|
12
12
|
private loadFilter;
|
|
13
13
|
setLoadFilter(filter: Filter): void;
|
|
14
|
-
|
|
14
|
+
onSync(message: any): Promise<void>;
|
|
15
15
|
beforeLoad(): Promise<void>;
|
|
16
16
|
load(): Promise<void>;
|
|
17
17
|
install(): Promise<void>;
|
package/dist/server/server.js
CHANGED
|
@@ -42,6 +42,7 @@ __export(server_exports, {
|
|
|
42
42
|
module.exports = __toCommonJS(server_exports);
|
|
43
43
|
var import_database = require("@nocobase/database");
|
|
44
44
|
var import_server = require("@nocobase/server");
|
|
45
|
+
var import_async_mutex = require("async-mutex");
|
|
45
46
|
var import_lodash = __toESM(require("lodash"));
|
|
46
47
|
var import_path = __toESM(require("path"));
|
|
47
48
|
var import__ = require(".");
|
|
@@ -60,9 +61,9 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
60
61
|
setLoadFilter(filter) {
|
|
61
62
|
this.loadFilter = filter;
|
|
62
63
|
}
|
|
63
|
-
async
|
|
64
|
+
async onSync(message) {
|
|
64
65
|
const { type, collectionName } = message;
|
|
65
|
-
if (type === "
|
|
66
|
+
if (type === "newCollection") {
|
|
66
67
|
const collectionModel = await this.app.db.getCollection("collections").repository.findOne({
|
|
67
68
|
filter: {
|
|
68
69
|
name: collectionName
|
|
@@ -70,22 +71,6 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
70
71
|
});
|
|
71
72
|
await collectionModel.load();
|
|
72
73
|
}
|
|
73
|
-
if (type === "removeField") {
|
|
74
|
-
const { collectionName: collectionName2, fieldName } = message;
|
|
75
|
-
const collection = this.app.db.getCollection(collectionName2);
|
|
76
|
-
if (!collection) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
return collection.removeFieldFromDb(fieldName);
|
|
80
|
-
}
|
|
81
|
-
if (type === "removeCollection") {
|
|
82
|
-
const { collectionName: collectionName2 } = message;
|
|
83
|
-
const collection = this.app.db.getCollection(collectionName2);
|
|
84
|
-
if (!collection) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
collection.remove();
|
|
88
|
-
}
|
|
89
74
|
}
|
|
90
75
|
async beforeLoad() {
|
|
91
76
|
this.app.db.registerRepositories({
|
|
@@ -110,15 +95,10 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
110
95
|
await model.migrate({
|
|
111
96
|
transaction
|
|
112
97
|
});
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
transaction
|
|
120
|
-
}
|
|
121
|
-
);
|
|
98
|
+
this.app.syncManager.publish(this.name, {
|
|
99
|
+
type: "newCollection",
|
|
100
|
+
collectionName: model.get("name")
|
|
101
|
+
});
|
|
122
102
|
}
|
|
123
103
|
}
|
|
124
104
|
);
|
|
@@ -132,15 +112,6 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
132
112
|
removeOptions["cascade"] = true;
|
|
133
113
|
}
|
|
134
114
|
await model.remove(removeOptions);
|
|
135
|
-
this.sendSyncMessage(
|
|
136
|
-
{
|
|
137
|
-
type: "removeCollection",
|
|
138
|
-
collectionName: model.get("name")
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
transaction: options.transaction
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
115
|
});
|
|
145
116
|
this.app.db.on("fields.beforeCreate", (0, import_beforeCreateCheckFieldInMySQL.beforeCreateCheckFieldInMySQL)(this.app.db));
|
|
146
117
|
this.app.db.on("fields.beforeCreate", (0, import_hooks.beforeCreateForReverseField)(this.app.db));
|
|
@@ -251,33 +222,14 @@ class PluginDataSourceMainServer extends import_server.Plugin {
|
|
|
251
222
|
}
|
|
252
223
|
};
|
|
253
224
|
await collection.sync(syncOptions);
|
|
254
|
-
this.sendSyncMessage(
|
|
255
|
-
{
|
|
256
|
-
type: "syncCollection",
|
|
257
|
-
collectionName: model.get("collectionName")
|
|
258
|
-
},
|
|
259
|
-
{
|
|
260
|
-
transaction
|
|
261
|
-
}
|
|
262
|
-
);
|
|
263
225
|
}
|
|
264
226
|
});
|
|
265
227
|
this.app.db.on("fields.beforeDestroy", (0, import_beforeDestoryField.beforeDestoryField)(this.app.db));
|
|
266
228
|
this.app.db.on("fields.beforeDestroy", (0, import_hooks.beforeDestroyForeignKey)(this.app.db));
|
|
229
|
+
const mutex = new import_async_mutex.Mutex();
|
|
267
230
|
this.app.db.on("fields.beforeDestroy", async (model, options) => {
|
|
268
|
-
|
|
269
|
-
await this.app.lockManager.runExclusive(lockKey, async () => {
|
|
231
|
+
await mutex.runExclusive(async () => {
|
|
270
232
|
await model.remove(options);
|
|
271
|
-
this.sendSyncMessage(
|
|
272
|
-
{
|
|
273
|
-
type: "removeField",
|
|
274
|
-
collectionName: model.get("collectionName"),
|
|
275
|
-
fieldName: model.get("name")
|
|
276
|
-
},
|
|
277
|
-
{
|
|
278
|
-
transaction: options.transaction
|
|
279
|
-
}
|
|
280
|
-
);
|
|
281
233
|
});
|
|
282
234
|
});
|
|
283
235
|
this.app.db.on("fields.afterDestroy", async (model, options) => {
|
package/package.json
CHANGED
|
@@ -4,25 +4,25 @@
|
|
|
4
4
|
"displayName.zh-CN": "数据源:主数据库",
|
|
5
5
|
"description": "NocoBase main database, supports relational databases such as PostgreSQL, MySQL, MariaDB and so on.",
|
|
6
6
|
"description.zh-CN": "NocoBase 主数据库,支持 PostgreSQL、MySQL、MariaDB 等关系型数据库。",
|
|
7
|
-
"version": "1.5.0-
|
|
7
|
+
"version": "1.5.0-beta.2",
|
|
8
8
|
"main": "./dist/server/index.js",
|
|
9
9
|
"homepage": "https://docs.nocobase.com/handbook/data-source-main",
|
|
10
10
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/data-source-main",
|
|
11
11
|
"license": "AGPL-3.0",
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"@hapi/topo": "^6.0.0",
|
|
14
|
+
"async-mutex": "^0.3.2",
|
|
14
15
|
"toposort": "^2.0.2"
|
|
15
16
|
},
|
|
16
17
|
"peerDependencies": {
|
|
17
18
|
"@nocobase/client": "1.x",
|
|
18
19
|
"@nocobase/database": "1.x",
|
|
19
20
|
"@nocobase/plugin-error-handler": "1.x",
|
|
20
|
-
"@nocobase/plugin-field-sort": "1.x",
|
|
21
21
|
"@nocobase/server": "1.x",
|
|
22
22
|
"@nocobase/test": "1.x",
|
|
23
23
|
"@nocobase/utils": "1.x"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "8a9c29fdac5c6295dcc7abf00c3fa81bd9e01a36",
|
|
26
26
|
"keywords": [
|
|
27
27
|
"Data sources"
|
|
28
28
|
]
|