@nocobase/plugin-multi-app-share-collection 0.9.2-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.
Files changed (41) hide show
  1. package/client.d.ts +4 -0
  2. package/client.js +30 -0
  3. package/lib/client/TableTransfer.d.ts +3 -0
  4. package/lib/client/TableTransfer.js +500 -0
  5. package/lib/client/index.d.ts +2 -0
  6. package/lib/client/index.js +122 -0
  7. package/lib/client/locale/pt-BR.d.ts +13 -0
  8. package/lib/client/locale/pt-BR.js +19 -0
  9. package/lib/client/locale/zh-CN.d.ts +13 -0
  10. package/lib/client/locale/zh-CN.js +19 -0
  11. package/lib/client/utils.d.ts +4 -0
  12. package/lib/client/utils.js +25 -0
  13. package/lib/index.d.ts +1 -0
  14. package/lib/index.js +13 -0
  15. package/lib/server/collections/applications.d.ts +6 -0
  16. package/lib/server/collections/applications.js +27 -0
  17. package/lib/server/collections/collections.d.ts +6 -0
  18. package/lib/server/collections/collections.js +27 -0
  19. package/lib/server/index.d.ts +1 -0
  20. package/lib/server/index.js +13 -0
  21. package/lib/server/migrations/20230319111111-update-apps-collections.d.ts +4 -0
  22. package/lib/server/migrations/20230319111111-update-apps-collections.js +106 -0
  23. package/lib/server/plugin.d.ts +9 -0
  24. package/lib/server/plugin.js +408 -0
  25. package/package.json +12 -0
  26. package/server.d.ts +4 -0
  27. package/server.js +30 -0
  28. package/src/client/TableTransfer.tsx +388 -0
  29. package/src/client/index.tsx +86 -0
  30. package/src/client/locale/pt-BR.ts +13 -0
  31. package/src/client/locale/zh-CN.ts +13 -0
  32. package/src/client/utils.tsx +11 -0
  33. package/src/index.ts +1 -0
  34. package/src/server/__tests__/collection-sync.test.ts +489 -0
  35. package/src/server/__tests__/index.ts +25 -0
  36. package/src/server/collections/.gitkeep +0 -0
  37. package/src/server/collections/applications.ts +17 -0
  38. package/src/server/collections/collections.ts +17 -0
  39. package/src/server/index.ts +1 -0
  40. package/src/server/migrations/20230319111111-update-apps-collections.ts +67 -0
  41. package/src/server/plugin.ts +331 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = {
8
+ 'Share collections': 'Compartilhar tabelas',
9
+ 'Unshared collections': 'Tabelas não compartilhadas',
10
+ 'Shared collections': 'Tabelas compartilhadas',
11
+ 'All categories': 'Todas as categorias',
12
+ 'Enter name or title...': 'Digite o nome ou título...',
13
+ 'Are you sure to add the following collections?': 'Tem certeza de que deseja adicionar as seguintes tabelas?',
14
+ 'Are you sure to remove the following collections?': 'Tem certeza de que deseja remover as seguintes tabelas?',
15
+ 'Collection display name': 'Nome de exibição da tabela',
16
+ 'Collection name': 'Nome da tabela',
17
+ 'Collection category': 'Categoria da tabela'
18
+ };
19
+ exports.default = _default;
@@ -0,0 +1,13 @@
1
+ declare const _default: {
2
+ 'Share collections': string;
3
+ 'Unshared collections': string;
4
+ 'Shared collections': string;
5
+ 'All categories': string;
6
+ 'Enter name or title...': string;
7
+ 'Are you sure to add the following collections?': string;
8
+ 'Are you sure to remove the following collections?': string;
9
+ 'Collection display name': string;
10
+ 'Collection name': string;
11
+ 'Collection category': string;
12
+ };
13
+ export default _default;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = {
8
+ 'Share collections': '共享数据表',
9
+ 'Unshared collections': '未共享的数据表',
10
+ 'Shared collections': '已共享的数据表',
11
+ 'All categories': '所有分类',
12
+ 'Enter name or title...': '输入数据表标题或标识',
13
+ 'Are you sure to add the following collections?': '确定添加以下数据表?',
14
+ 'Are you sure to remove the following collections?': '确定移除以下数据表?',
15
+ 'Collection display name': '标题',
16
+ 'Collection name': '标识',
17
+ 'Collection category': '分类'
18
+ };
19
+ exports.default = _default;
@@ -0,0 +1,4 @@
1
+ export declare const usePluginUtils: () => {
2
+ t: import("react-i18next").TFunction<"multi-app-share-collection", undefined>;
3
+ };
4
+ export declare const i18nText: (text: any) => string;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.usePluginUtils = exports.i18nText = void 0;
7
+ function _reactI18next() {
8
+ const data = require("react-i18next");
9
+ _reactI18next = function _reactI18next() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ const usePluginUtils = () => {
15
+ const _useTranslation = (0, _reactI18next().useTranslation)('multi-app-share-collection'),
16
+ t = _useTranslation.t;
17
+ return {
18
+ t
19
+ };
20
+ };
21
+ exports.usePluginUtils = usePluginUtils;
22
+ const i18nText = text => {
23
+ return `{{t("${text}", { ns: 'multi-app-share-collection' })}}`;
24
+ };
25
+ exports.i18nText = i18nText;
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from './server';
package/lib/index.js ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _server.default;
10
+ }
11
+ });
12
+ var _server = _interopRequireDefault(require("./server"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ collectionOptions: import("@nocobase/database").CollectionOptions;
3
+ mergeOptions: import("@nocobase/database").MergeOptions;
4
+ extend: boolean;
5
+ };
6
+ export default _default;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _database() {
8
+ const data = require("@nocobase/database");
9
+ _database = function _database() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ var _default = (0, _database().extendCollection)({
15
+ name: 'applications',
16
+ fields: [{
17
+ type: 'belongsToMany',
18
+ name: 'collectionBlacklist',
19
+ through: 'appCollectionBlacklist',
20
+ target: 'collections',
21
+ targetKey: 'name',
22
+ otherKey: 'collectionName',
23
+ sourceKey: 'name',
24
+ foreignKey: 'applicationName'
25
+ }]
26
+ });
27
+ exports.default = _default;
@@ -0,0 +1,6 @@
1
+ declare const _default: {
2
+ collectionOptions: import("@nocobase/database").CollectionOptions;
3
+ mergeOptions: import("@nocobase/database").MergeOptions;
4
+ extend: boolean;
5
+ };
6
+ export default _default;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _database() {
8
+ const data = require("@nocobase/database");
9
+ _database = function _database() {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ var _default = (0, _database().extendCollection)({
15
+ name: 'collections',
16
+ fields: [{
17
+ type: 'belongsToMany',
18
+ name: 'collectionBlacklist',
19
+ through: 'appCollectionBlacklist',
20
+ target: 'applications',
21
+ targetKey: 'name',
22
+ otherKey: 'applicationName',
23
+ sourceKey: 'name',
24
+ foreignKey: 'collectionName'
25
+ }]
26
+ });
27
+ exports.default = _default;
@@ -0,0 +1 @@
1
+ export { default } from './plugin';
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "default", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _plugin.default;
10
+ }
11
+ });
12
+ var _plugin = _interopRequireDefault(require("./plugin"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -0,0 +1,4 @@
1
+ import { Migration } from '@nocobase/server';
2
+ export default class extends Migration {
3
+ up(): Promise<void>;
4
+ }
@@ -0,0 +1,106 @@
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
+ if (!_this.app.db.getCollection('applications')) return;
35
+ yield _this.app.db.getCollection('collections').repository.destroy({
36
+ where: {
37
+ name: 'applications'
38
+ }
39
+ });
40
+ const appSyncedCollections = new Map();
41
+ const collections = yield _this.app.db.getCollection('collections').repository.find();
42
+ const collectionsData = collections.map(collection => collection.toJSON());
43
+ var _iterator = _createForOfIteratorHelper(collections),
44
+ _step;
45
+ try {
46
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
47
+ const collection = _step.value;
48
+ const collectionSyncToApps = collection.get('syncToApps');
49
+ if (collectionSyncToApps) {
50
+ var _iterator3 = _createForOfIteratorHelper(collectionSyncToApps),
51
+ _step3;
52
+ try {
53
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
54
+ const app = _step3.value;
55
+ if (!appSyncedCollections.has(app)) {
56
+ appSyncedCollections.set(app, new Set());
57
+ }
58
+ appSyncedCollections.get(app).add(collection.name);
59
+ }
60
+ } catch (err) {
61
+ _iterator3.e(err);
62
+ } finally {
63
+ _iterator3.f();
64
+ }
65
+ }
66
+ }
67
+ } catch (err) {
68
+ _iterator.e(err);
69
+ } finally {
70
+ _iterator.f();
71
+ }
72
+ const allCollections = collections.map(collection => collection.name);
73
+ const appCollectionBlacklist = _this.app.db.getCollection('appCollectionBlacklist');
74
+ var _iterator2 = _createForOfIteratorHelper(appSyncedCollections),
75
+ _step2;
76
+ try {
77
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
78
+ const _step2$value = _slicedToArray(_step2.value, 2),
79
+ app = _step2$value[0],
80
+ syncedCollections = _step2$value[1];
81
+ const blackListCollections = allCollections.filter(collection => !syncedCollections.has(collection) && !['users', 'roles'].includes(collection));
82
+ const connectedCollections = _utils().CollectionsGraph.connectedNodes({
83
+ collections: collectionsData,
84
+ nodes: blackListCollections,
85
+ direction: 'reverse'
86
+ });
87
+ console.log(JSON.stringify({
88
+ app,
89
+ connectedCollections
90
+ }, null, 2));
91
+ yield appCollectionBlacklist.model.bulkCreate(connectedCollections.map(collection => {
92
+ return {
93
+ applicationName: app,
94
+ collectionName: collection
95
+ };
96
+ }));
97
+ }
98
+ } catch (err) {
99
+ _iterator2.e(err);
100
+ } finally {
101
+ _iterator2.f();
102
+ }
103
+ })();
104
+ }
105
+ }
106
+ exports.default = _default;
@@ -0,0 +1,9 @@
1
+ import { Plugin } from '@nocobase/server';
2
+ export declare class MultiAppShareCollectionPlugin extends Plugin {
3
+ afterAdd(): void;
4
+ beforeEnable(): Promise<void>;
5
+ beforeLoad(): Promise<void>;
6
+ load(): Promise<void>;
7
+ requiredPlugins(): any[];
8
+ }
9
+ export default MultiAppShareCollectionPlugin;