@nocobase/plugin-multi-app-share-collection 0.11.1-alpha.5 → 0.12.0-alpha.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.
Files changed (56) hide show
  1. package/client.d.ts +2 -3
  2. package/client.js +1 -1
  3. package/dist/client/index.js +510 -0
  4. package/{lib → dist}/index.d.ts +1 -0
  5. package/dist/index.js +18 -0
  6. package/dist/locale/es-ES.js +16 -0
  7. package/dist/locale/pt-BR.js +16 -0
  8. package/dist/locale/zh-CN.js +16 -0
  9. package/dist/server/collections/applications.js +21 -0
  10. package/dist/server/collections/collections.js +21 -0
  11. package/dist/server/index.js +11 -0
  12. package/{src/server/migrations/20230319111111-update-apps-collections.ts → dist/server/migrations/20230319111111-update-apps-collections.js} +26 -33
  13. package/dist/server/plugin.js +278 -0
  14. package/package.json +16 -25
  15. package/server.d.ts +2 -3
  16. package/server.js +1 -1
  17. package/lib/client/MultiAppShareCollectionProvider.js +0 -122
  18. package/lib/client/TableTransfer.js +0 -487
  19. package/lib/client/index.js +0 -27
  20. package/lib/client/utils.js +0 -25
  21. package/lib/index.js +0 -13
  22. package/lib/locale/es-ES.js +0 -19
  23. package/lib/locale/pt-BR.js +0 -19
  24. package/lib/locale/zh-CN.js +0 -19
  25. package/lib/server/collections/applications.js +0 -27
  26. package/lib/server/collections/collections.js +0 -27
  27. package/lib/server/index.js +0 -13
  28. package/lib/server/migrations/20230319111111-update-apps-collections.js +0 -110
  29. package/lib/server/plugin.js +0 -408
  30. package/src/client/MultiAppShareCollectionProvider.tsx +0 -86
  31. package/src/client/TableTransfer.tsx +0 -398
  32. package/src/client/index.tsx +0 -10
  33. package/src/client/utils.tsx +0 -11
  34. package/src/index.ts +0 -1
  35. package/src/locale/es-ES.ts +0 -12
  36. package/src/locale/pt-BR.ts +0 -12
  37. package/src/locale/zh-CN.ts +0 -12
  38. package/src/server/__tests__/collection-sync.test.ts +0 -514
  39. package/src/server/__tests__/index.ts +0 -25
  40. package/src/server/collections/.gitkeep +0 -0
  41. package/src/server/collections/applications.ts +0 -17
  42. package/src/server/collections/collections.ts +0 -17
  43. package/src/server/index.ts +0 -1
  44. package/src/server/plugin.ts +0 -332
  45. /package/{lib → dist}/client/MultiAppShareCollectionProvider.d.ts +0 -0
  46. /package/{lib → dist}/client/TableTransfer.d.ts +0 -0
  47. /package/{lib → dist}/client/index.d.ts +0 -0
  48. /package/{lib → dist}/client/utils.d.ts +0 -0
  49. /package/{lib → dist}/locale/es-ES.d.ts +0 -0
  50. /package/{lib → dist}/locale/pt-BR.d.ts +0 -0
  51. /package/{lib → dist}/locale/zh-CN.d.ts +0 -0
  52. /package/{lib → dist}/server/collections/applications.d.ts +0 -0
  53. /package/{lib → dist}/server/collections/collections.d.ts +0 -0
  54. /package/{lib → dist}/server/index.d.ts +0 -0
  55. /package/{lib → dist}/server/migrations/20230319111111-update-apps-collections.d.ts +0 -0
  56. /package/{lib → dist}/server/plugin.d.ts +0 -0
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- function _server() {
8
- const data = require("@nocobase/server");
9
- _server = function _server() {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _utils() {
15
- const data = require("@nocobase/utils");
16
- _utils = function _utils() {
17
- return data;
18
- };
19
- return data;
20
- }
21
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
22
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
23
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
24
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
25
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
26
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
27
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
28
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
29
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
30
- class _default extends _server().Migration {
31
- up() {
32
- var _this = this;
33
- return _asyncToGenerator(function* () {
34
- const result = yield _this.app.version.satisfies('<0.9.3-alpha.1');
35
- if (!result) {
36
- return;
37
- }
38
- if (!_this.app.db.getCollection('applications')) return;
39
- yield _this.app.db.getCollection('collections').repository.destroy({
40
- where: {
41
- name: 'applications'
42
- }
43
- });
44
- const appSyncedCollections = new Map();
45
- const collections = yield _this.app.db.getCollection('collections').repository.find();
46
- const collectionsData = collections.map(collection => collection.toJSON());
47
- var _iterator = _createForOfIteratorHelper(collections),
48
- _step;
49
- try {
50
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
51
- const collection = _step.value;
52
- const collectionSyncToApps = collection.get('syncToApps');
53
- if (collectionSyncToApps) {
54
- var _iterator3 = _createForOfIteratorHelper(collectionSyncToApps),
55
- _step3;
56
- try {
57
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
58
- const app = _step3.value;
59
- if (!appSyncedCollections.has(app)) {
60
- appSyncedCollections.set(app, new Set());
61
- }
62
- appSyncedCollections.get(app).add(collection.name);
63
- }
64
- } catch (err) {
65
- _iterator3.e(err);
66
- } finally {
67
- _iterator3.f();
68
- }
69
- }
70
- }
71
- } catch (err) {
72
- _iterator.e(err);
73
- } finally {
74
- _iterator.f();
75
- }
76
- const allCollections = collections.map(collection => collection.name);
77
- const appCollectionBlacklist = _this.app.db.getCollection('appCollectionBlacklist');
78
- var _iterator2 = _createForOfIteratorHelper(appSyncedCollections),
79
- _step2;
80
- try {
81
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
82
- const _step2$value = _slicedToArray(_step2.value, 2),
83
- app = _step2$value[0],
84
- syncedCollections = _step2$value[1];
85
- const blackListCollections = allCollections.filter(collection => !syncedCollections.has(collection) && !['users', 'roles'].includes(collection));
86
- const connectedCollections = _utils().CollectionsGraph.connectedNodes({
87
- collections: collectionsData,
88
- nodes: blackListCollections,
89
- direction: 'reverse'
90
- });
91
- console.log(JSON.stringify({
92
- app,
93
- connectedCollections
94
- }, null, 2));
95
- yield appCollectionBlacklist.model.bulkCreate(connectedCollections.map(collection => {
96
- return {
97
- applicationName: app,
98
- collectionName: collection
99
- };
100
- }));
101
- }
102
- } catch (err) {
103
- _iterator2.e(err);
104
- } finally {
105
- _iterator2.f();
106
- }
107
- })();
108
- }
109
- }
110
- exports.default = _default;
@@ -1,408 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.MultiAppShareCollectionPlugin = void 0;
7
- function _pluginMultiAppManager() {
8
- const data = _interopRequireDefault(require("@nocobase/plugin-multi-app-manager"));
9
- _pluginMultiAppManager = function _pluginMultiAppManager() {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _server() {
15
- const data = require("@nocobase/server");
16
- _server = function _server() {
17
- return data;
18
- };
19
- return data;
20
- }
21
- function _utils() {
22
- const data = require("@nocobase/utils");
23
- _utils = function _utils() {
24
- return data;
25
- };
26
- return data;
27
- }
28
- function _path() {
29
- const data = require("path");
30
- _path = function _path() {
31
- return data;
32
- };
33
- return data;
34
- }
35
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
36
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
37
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
38
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
39
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
40
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
41
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
42
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
43
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
44
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
45
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
46
- const subAppFilteredPlugins = ['multi-app-share-collection', 'multi-app-manager'];
47
- class SubAppPlugin extends _server().Plugin {
48
- beforeLoad() {
49
- const mainApp = this.options.mainApp;
50
- const subApp = this.app;
51
- const sharedCollectionGroups = ['audit-logs', 'workflow', 'charts', 'collection-manager', 'file-manager', 'graph-collection-manager', 'map', 'sequence-field', 'snapshot-field', 'verification', 'localization-management'];
52
- const collectionGroups = mainApp.db.collectionGroupManager.getGroups();
53
- const sharedCollectionGroupsCollections = [];
54
- var _iterator = _createForOfIteratorHelper(collectionGroups),
55
- _step;
56
- try {
57
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
58
- const group = _step.value;
59
- if (sharedCollectionGroups.includes(group.namespace)) {
60
- sharedCollectionGroupsCollections.push(...group.collections);
61
- }
62
- }
63
- } catch (err) {
64
- _iterator.e(err);
65
- } finally {
66
- _iterator.f();
67
- }
68
- const sharedCollections = [...sharedCollectionGroupsCollections.flat(), 'users', 'users_jobs'];
69
- subApp.db.on('beforeDefineCollection', options => {
70
- const name = options.name;
71
- // 指向主应用的 系统schema
72
- if (sharedCollections.includes(name)) {
73
- options.schema = mainApp.db.options.schema || 'public';
74
- }
75
- });
76
- subApp.db.on('beforeUpdateCollection', (collection, newOptions) => {
77
- if (collection.name === 'roles') {
78
- newOptions.schema = subApp.db.options.schema;
79
- }
80
- });
81
- this.app.resourcer.use( /*#__PURE__*/function () {
82
- var _ref = _asyncToGenerator(function* (ctx, next) {
83
- const _ctx$action = ctx.action,
84
- actionName = _ctx$action.actionName,
85
- resourceName = _ctx$action.resourceName;
86
- if (actionName === 'list' && resourceName === 'applicationPlugins') {
87
- ctx.action.mergeParams({
88
- filter: {
89
- 'name.$notIn': subAppFilteredPlugins
90
- }
91
- });
92
- }
93
- if (actionName === 'list' && resourceName === 'collections') {
94
- const appCollectionBlacklistCollection = mainApp.db.getCollection('appCollectionBlacklist');
95
- const blackList = yield appCollectionBlacklistCollection.model.findAll({
96
- where: {
97
- applicationName: subApp.name
98
- }
99
- });
100
- if (blackList.length > 0) {
101
- ctx.action.mergeParams({
102
- filter: {
103
- 'name.$notIn': blackList.map(item => item.get('collectionName'))
104
- }
105
- });
106
- }
107
- }
108
- yield next();
109
- });
110
- return function (_x, _x2) {
111
- return _ref.apply(this, arguments);
112
- };
113
- }());
114
- // new subApp sync plugins from mainApp
115
- subApp.on('beforeInstall', /*#__PURE__*/_asyncToGenerator(function* () {
116
- const subAppPluginsCollection = subApp.db.getCollection('applicationPlugins');
117
- const mainAppPluginsCollection = mainApp.db.getCollection('applicationPlugins');
118
- // delete old collection
119
- yield subApp.db.sequelize.query(`TRUNCATE ${subAppPluginsCollection.quotedTableName()}`);
120
- yield subApp.db.sequelize.query(`
121
- INSERT INTO ${subAppPluginsCollection.quotedTableName()}
122
- SELECT *
123
- FROM ${mainAppPluginsCollection.quotedTableName()}
124
- WHERE "name" not in ('multi-app-manager', 'multi-app-share-collection');
125
- `);
126
- const sequenceNameSql = `SELECT pg_get_serial_sequence('"${subAppPluginsCollection.collectionSchema()}"."${subAppPluginsCollection.model.tableName}"', 'id')`;
127
- const sequenceName = yield subApp.db.sequelize.query(sequenceNameSql, {
128
- type: 'SELECT'
129
- });
130
- yield subApp.db.sequelize.query(`
131
- SELECT setval('${sequenceName[0]['pg_get_serial_sequence']}', (SELECT max("id") FROM ${subAppPluginsCollection.quotedTableName()}));
132
- `);
133
- console.log(`sync plugins from ${mainApp.name} app to sub app ${subApp.name}`);
134
- }));
135
- }
136
- }
137
- class MultiAppShareCollectionPlugin extends _server().Plugin {
138
- afterAdd() {}
139
- beforeEnable() {
140
- var _this = this;
141
- return _asyncToGenerator(function* () {
142
- if (!_this.db.inDialect('postgres')) {
143
- throw new Error('multi-app-share-collection plugin only support postgres');
144
- }
145
- })();
146
- }
147
- beforeLoad() {
148
- var _this2 = this;
149
- return _asyncToGenerator(function* () {
150
- if (!_this2.db.inDialect('postgres')) {
151
- throw new Error('multi-app-share-collection plugin only support postgres');
152
- }
153
- const traverseSubApps = /*#__PURE__*/function () {
154
- var _ref3 = _asyncToGenerator(function* (callback, options) {
155
- if (_utils().lodash.get(options, 'loadFromDatabase')) {
156
- var _iterator2 = _createForOfIteratorHelper(yield _this2.app.db.getCollection('applications').repository.find()),
157
- _step2;
158
- try {
159
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
160
- const application = _step2.value;
161
- const appName = application.get('name');
162
- const subApp = yield _this2.app.appManager.getApplication(appName);
163
- yield callback(subApp);
164
- }
165
- } catch (err) {
166
- _iterator2.e(err);
167
- } finally {
168
- _iterator2.f();
169
- }
170
- return;
171
- }
172
- const subApps = [..._this2.app.appManager.applications.values()];
173
- for (var _i = 0, _subApps = subApps; _i < _subApps.length; _i++) {
174
- const subApp = _subApps[_i];
175
- yield callback(subApp);
176
- }
177
- });
178
- return function traverseSubApps(_x3, _x4) {
179
- return _ref3.apply(this, arguments);
180
- };
181
- }();
182
- _this2.app.on('afterSubAppAdded', subApp => {
183
- subApp.plugin(SubAppPlugin, {
184
- name: 'sub-app',
185
- mainApp: _this2.app
186
- });
187
- });
188
- _this2.app.db.on('users.afterCreateWithAssociations', /*#__PURE__*/function () {
189
- var _ref4 = _asyncToGenerator(function* (model, options) {
190
- yield traverseSubApps( /*#__PURE__*/function () {
191
- var _ref5 = _asyncToGenerator(function* (subApp) {
192
- const transaction = options.transaction;
193
- const repository = subApp.db.getRepository('roles');
194
- const subAppModel = yield subApp.db.getCollection('users').repository.findOne({
195
- filter: {
196
- id: model.get('id')
197
- },
198
- transaction
199
- });
200
- const defaultRole = yield repository.findOne({
201
- filter: {
202
- default: true
203
- },
204
- transaction
205
- });
206
- if (defaultRole && (yield subAppModel.countRoles({
207
- transaction
208
- })) == 0) {
209
- yield subAppModel.addRoles(defaultRole, {
210
- transaction
211
- });
212
- }
213
- });
214
- return function (_x7) {
215
- return _ref5.apply(this, arguments);
216
- };
217
- }());
218
- });
219
- return function (_x5, _x6) {
220
- return _ref4.apply(this, arguments);
221
- };
222
- }());
223
- _this2.app.db.on('collection:loaded', /*#__PURE__*/function () {
224
- var _ref6 = _asyncToGenerator(function* ({
225
- transaction,
226
- collection
227
- }) {
228
- yield traverseSubApps( /*#__PURE__*/function () {
229
- var _ref7 = _asyncToGenerator(function* (subApp) {
230
- const name = collection.name;
231
- const collectionRecord = yield subApp.db.getRepository('collections').findOne({
232
- filter: {
233
- name
234
- },
235
- transaction
236
- });
237
- yield collectionRecord.load({
238
- transaction
239
- });
240
- });
241
- return function (_x9) {
242
- return _ref7.apply(this, arguments);
243
- };
244
- }());
245
- });
246
- return function (_x8) {
247
- return _ref6.apply(this, arguments);
248
- };
249
- }());
250
- _this2.app.db.on('field:loaded', /*#__PURE__*/function () {
251
- var _ref8 = _asyncToGenerator(function* ({
252
- transaction,
253
- fieldKey
254
- }) {
255
- yield traverseSubApps( /*#__PURE__*/function () {
256
- var _ref9 = _asyncToGenerator(function* (subApp) {
257
- const fieldRecord = yield subApp.db.getRepository('fields').findOne({
258
- filterByTk: fieldKey,
259
- transaction
260
- });
261
- if (fieldRecord) {
262
- yield fieldRecord.load({
263
- transaction
264
- });
265
- }
266
- });
267
- return function (_x11) {
268
- return _ref9.apply(this, arguments);
269
- };
270
- }());
271
- });
272
- return function (_x10) {
273
- return _ref8.apply(this, arguments);
274
- };
275
- }());
276
- _this2.app.on('afterEnablePlugin', /*#__PURE__*/function () {
277
- var _ref10 = _asyncToGenerator(function* (pluginName) {
278
- yield traverseSubApps( /*#__PURE__*/function () {
279
- var _ref11 = _asyncToGenerator(function* (subApp) {
280
- if (subAppFilteredPlugins.includes(pluginName)) return;
281
- yield subApp.pm.enable(pluginName);
282
- });
283
- return function (_x13) {
284
- return _ref11.apply(this, arguments);
285
- };
286
- }(), {
287
- loadFromDatabase: true
288
- });
289
- });
290
- return function (_x12) {
291
- return _ref10.apply(this, arguments);
292
- };
293
- }());
294
- _this2.app.on('afterDisablePlugin', /*#__PURE__*/function () {
295
- var _ref12 = _asyncToGenerator(function* (pluginName) {
296
- yield traverseSubApps( /*#__PURE__*/function () {
297
- var _ref13 = _asyncToGenerator(function* (subApp) {
298
- if (subAppFilteredPlugins.includes(pluginName)) return;
299
- yield subApp.pm.disable(pluginName);
300
- });
301
- return function (_x15) {
302
- return _ref13.apply(this, arguments);
303
- };
304
- }(), {
305
- loadFromDatabase: true
306
- });
307
- });
308
- return function (_x14) {
309
- return _ref12.apply(this, arguments);
310
- };
311
- }());
312
- _this2.app.db.on('field.afterRemove', removedField => {
313
- const subApps = [..._this2.app.appManager.applications.values()];
314
- for (var _i2 = 0, _subApps2 = subApps; _i2 < _subApps2.length; _i2++) {
315
- const subApp = _subApps2[_i2];
316
- const collectionName = removedField.collection.name;
317
- const collection = subApp.db.getCollection(collectionName);
318
- if (!collection) {
319
- subApp.log.warn(`collection ${collectionName} not found in ${subApp.name}`);
320
- continue;
321
- }
322
- collection.removeField(removedField.name);
323
- }
324
- });
325
- _this2.app.db.on(`afterRemoveCollection`, collection => {
326
- const subApps = [..._this2.app.appManager.applications.values()];
327
- for (var _i3 = 0, _subApps3 = subApps; _i3 < _subApps3.length; _i3++) {
328
- const subApp = _subApps3[_i3];
329
- subApp.db.removeCollection(collection.name);
330
- }
331
- });
332
- })();
333
- }
334
- load() {
335
- var _this3 = this;
336
- return _asyncToGenerator(function* () {
337
- const multiAppManager = _this3.app.getPlugin('multi-app-manager');
338
- if (!multiAppManager) {
339
- _this3.app.log.warn('multi-app-share-collection plugin need multi-app-manager plugin enabled');
340
- return;
341
- }
342
- yield _this3.db.import({
343
- directory: (0, _path().resolve)(__dirname, 'collections')
344
- });
345
- // this.db.addMigrations({
346
- // namespace: 'multi-app-share-collection',
347
- // directory: resolve(__dirname, './migrations'),
348
- // });
349
- _this3.app.resourcer.registerActionHandlers({
350
- 'applications:shareCollections': function () {
351
- var _applicationsShareCollections = _asyncToGenerator(function* (ctx, next) {
352
- const _ctx$action$params = ctx.action.params,
353
- filterByTk = _ctx$action$params.filterByTk,
354
- values = _ctx$action$params.values;
355
- ctx.body = {
356
- filterByTk,
357
- values
358
- };
359
- yield next();
360
- });
361
- function applicationsShareCollections(_x16, _x17) {
362
- return _applicationsShareCollections.apply(this, arguments);
363
- }
364
- return applicationsShareCollections;
365
- }()
366
- });
367
- // 子应用启动参数
368
- multiAppManager.setAppOptionsFactory((appName, mainApp) => {
369
- const mainAppDbConfig = _pluginMultiAppManager().default.getDatabaseConfig(mainApp);
370
- const databaseOptions = _objectSpread(_objectSpread({}, mainAppDbConfig), {}, {
371
- schema: appName
372
- });
373
- const plugins = [...mainApp.pm.getPlugins().keys()].filter(name => name !== 'multi-app-manager' && name !== 'multi-app-share-collection');
374
- return {
375
- database: _utils().lodash.merge(databaseOptions, {
376
- dialectOptions: {
377
- application_name: `nocobase.${appName}`
378
- }
379
- }),
380
- plugins: plugins.includes('nocobase') ? ['nocobase'] : plugins,
381
- resourcer: {
382
- prefix: '/api'
383
- },
384
- logger: _objectSpread(_objectSpread({}, mainApp.options.logger), {}, {
385
- requestWhitelist: ['action', 'header.x-role', 'header.x-hostname', 'header.x-timezone', 'header.x-locale', 'referer', 'header.x-app']
386
- })
387
- // pmSock: resolve(process.cwd(), 'storage', `${appName}.sock`),
388
- };
389
- });
390
- // 子应用数据库创建
391
- multiAppManager.setAppDbCreator( /*#__PURE__*/function () {
392
- var _ref14 = _asyncToGenerator(function* (app) {
393
- const schema = app.options.database.schema;
394
- yield _this3.app.db.sequelize.query(`CREATE SCHEMA IF NOT EXISTS ${schema}`);
395
- });
396
- return function (_x18) {
397
- return _ref14.apply(this, arguments);
398
- };
399
- }());
400
- })();
401
- }
402
- requiredPlugins() {
403
- return ['multi-app-manager'];
404
- }
405
- }
406
- exports.MultiAppShareCollectionPlugin = MultiAppShareCollectionPlugin;
407
- var _default = MultiAppShareCollectionPlugin;
408
- exports.default = _default;
@@ -1,86 +0,0 @@
1
- import { useForm } from '@formily/react';
2
- import { useActionContext, useAPIClient, useRecord } from '@nocobase/client';
3
- import { tableActionColumnSchema } from '@nocobase/plugin-multi-app-manager/client';
4
- import { message } from 'antd';
5
- import React from 'react';
6
- import { TableTransfer } from './TableTransfer';
7
- import { i18nText } from './utils';
8
-
9
- const useShareCollectionAction = () => {
10
- const form = useForm();
11
- const ctx = useActionContext();
12
- const api = useAPIClient();
13
- const record = useRecord();
14
- return {
15
- async run() {
16
- console.log(form.values.names);
17
- await api.request({
18
- url: `applications/${record.name}/collectionBlacklist`,
19
- data: form.values.names,
20
- method: 'post',
21
- });
22
- ctx.setVisible(false);
23
- form.reset();
24
- message.success('Saved successfully');
25
- },
26
- };
27
- };
28
-
29
- const updateSchema = tableActionColumnSchema.properties.update;
30
- const deleteSchema = tableActionColumnSchema.properties.delete;
31
-
32
- delete tableActionColumnSchema.properties.update;
33
- delete tableActionColumnSchema.properties.delete;
34
-
35
- tableActionColumnSchema.properties['collection'] = {
36
- type: 'void',
37
- title: i18nText('Share collections'),
38
- 'x-component': 'Action.Link',
39
- 'x-component-props': {},
40
- properties: {
41
- drawer: {
42
- type: 'void',
43
- 'x-component': 'Action.Drawer',
44
- 'x-component-props': {
45
- width: '95vw',
46
- },
47
- 'x-decorator': 'Form',
48
- title: i18nText('Share collections'),
49
- properties: {
50
- names: {
51
- type: 'array',
52
- 'x-component': TableTransfer,
53
- 'x-decorator': 'FormItem',
54
- },
55
- footer: {
56
- type: 'void',
57
- 'x-component': 'Action.Drawer.Footer',
58
- properties: {
59
- cancel: {
60
- title: '{{t("Cancel")}}',
61
- 'x-component': 'Action',
62
- 'x-component-props': {
63
- useAction: '{{ cm.useCancelAction }}',
64
- },
65
- },
66
- submit: {
67
- title: '{{t("Submit")}}',
68
- 'x-component': 'Action',
69
- 'x-component-props': {
70
- type: 'primary',
71
- useAction: useShareCollectionAction,
72
- },
73
- },
74
- },
75
- },
76
- },
77
- },
78
- },
79
- };
80
-
81
- tableActionColumnSchema.properties.update = updateSchema;
82
- tableActionColumnSchema.properties.delete = deleteSchema;
83
-
84
- export const MultiAppShareCollectionProvider = (props) => {
85
- return <>{props.children}</>;
86
- };