@nocobase/plugin-multi-app-manager 0.7.0-alpha.33 → 0.7.0-alpha.56

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.
@@ -1,46 +1,60 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const database_1 = require("@nocobase/database");
4
- exports.default = (0, database_1.defineCollection)({
5
- name: 'applications',
6
- model: 'ApplicationModel',
7
- autoGenId: false,
8
- title: '{{t("Applications")}}',
9
- sortable: 'sort',
10
- filterTargetKey: 'name',
11
- fields: [
12
- {
13
- type: 'uid',
14
- name: 'name',
15
- primaryKey: true,
16
- prefix: 'a',
17
- interface: 'input',
18
- uiSchema: {
19
- type: 'string',
20
- title: '{{t("Application name")}}',
21
- 'x-component': 'Input',
22
- 'x-read-pretty': true,
23
- },
24
- },
25
- {
26
- type: 'string',
27
- name: 'status',
28
- interface: 'radioGroup',
29
- defaultValue: 'pending',
30
- uiSchema: {
31
- type: 'string',
32
- title: '{{t("Application status")}}',
33
- 'x-component': 'Radio.Group',
34
- enum: [
35
- { label: '创建中', value: 'pending' },
36
- { label: '运行中', value: 'running' },
37
- ],
38
- },
39
- },
40
- {
41
- type: 'json',
42
- name: 'options',
43
- },
44
- ],
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
45
5
  });
46
- //# sourceMappingURL=applications.js.map
6
+ exports.default = void 0;
7
+
8
+ function _database() {
9
+ const data = require("@nocobase/database");
10
+
11
+ _database = function _database() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ var _default = (0, _database().defineCollection)({
19
+ name: 'applications',
20
+ model: 'ApplicationModel',
21
+ autoGenId: false,
22
+ title: '{{t("Applications")}}',
23
+ sortable: 'sort',
24
+ filterTargetKey: 'name',
25
+ fields: [{
26
+ type: 'uid',
27
+ name: 'name',
28
+ primaryKey: true,
29
+ prefix: 'a',
30
+ interface: 'input',
31
+ uiSchema: {
32
+ type: 'string',
33
+ title: '{{t("Application name")}}',
34
+ 'x-component': 'Input',
35
+ 'x-read-pretty': true
36
+ }
37
+ }, {
38
+ type: 'string',
39
+ name: 'status',
40
+ interface: 'radioGroup',
41
+ defaultValue: 'pending',
42
+ uiSchema: {
43
+ type: 'string',
44
+ title: '{{t("Application status")}}',
45
+ 'x-component': 'Radio.Group',
46
+ enum: [{
47
+ label: '创建中',
48
+ value: 'pending'
49
+ }, {
50
+ label: '运行中',
51
+ value: 'running'
52
+ }]
53
+ }
54
+ }, {
55
+ type: 'json',
56
+ name: 'options'
57
+ }]
58
+ });
59
+
60
+ exports.default = _default;
package/lib/index.js CHANGED
@@ -1,8 +1,21 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApplicationModel = exports.default = void 0;
4
- const application_1 = require("./models/application");
5
- Object.defineProperty(exports, "ApplicationModel", { enumerable: true, get: function () { return application_1.ApplicationModel; } });
6
- var server_1 = require("./server");
7
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return server_1.PluginMultiAppManager; } });
8
- //# sourceMappingURL=index.js.map
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "ApplicationModel", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _application.ApplicationModel;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "default", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _server.PluginMultiAppManager;
16
+ }
17
+ });
18
+
19
+ var _application = require("./models/application");
20
+
21
+ var _server = require("./server");
@@ -1,116 +1,164 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
13
5
  });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
6
  exports.ApplicationModel = void 0;
35
- const database_1 = require("@nocobase/database");
36
- const lodash_1 = __importDefault(require("lodash"));
37
- const path = __importStar(require("path"));
38
- class ApplicationModel extends database_1.Model {
39
- static getDatabaseConfig(app) {
40
- return lodash_1.default.cloneDeep(lodash_1.default.isPlainObject(app.options.database)
41
- ? app.options.database
42
- : app.options.database.options);
43
- }
44
- static handleAppStart(app, options) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- yield app.load();
47
- if (!lodash_1.default.get(options, 'skipInstall', false)) {
48
- yield app.install();
49
- }
50
- yield app.start();
51
- });
52
- }
53
- registerToMainApp(mainApp, options) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- const appName = this.get('name');
56
- const appOptions = this.get('options') || {};
57
- const AppModel = this.constructor;
58
- const app = mainApp.appManager.createApplication(appName, Object.assign(Object.assign({}, AppModel.initOptions(appName, mainApp)), appOptions));
59
- // create database before installation if it not exists
60
- app.on('beforeInstall', function createDatabase() {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const { host, port, username, password, database, dialect } = AppModel.getDatabaseConfig(app);
63
- if (dialect === 'mysql') {
64
- const mysql = require('mysql2/promise');
65
- const connection = yield mysql.createConnection({ host, port, user: username, password });
66
- yield connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
67
- yield connection.close();
68
- }
69
- if (dialect === 'postgres') {
70
- const { Client } = require('pg');
71
- const client = new Client({
72
- user: username,
73
- host,
74
- password: password,
75
- port,
76
- });
77
- yield client.connect();
78
- try {
79
- yield client.query(`CREATE DATABASE "${database}"`);
80
- }
81
- catch (e) { }
82
- yield client.end();
83
- }
84
- });
7
+
8
+ function _database() {
9
+ const data = require("@nocobase/database");
10
+
11
+ _database = function _database() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _lodash() {
19
+ const data = _interopRequireDefault(require("lodash"));
20
+
21
+ _lodash = function _lodash() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ function path() {
29
+ const data = _interopRequireWildcard(require("path"));
30
+
31
+ path = function path() {
32
+ return data;
33
+ };
34
+
35
+ return data;
36
+ }
37
+
38
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
39
+
40
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
41
+
42
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43
+
44
+ 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; }
45
+
46
+ 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; }
47
+
48
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
49
+
50
+ 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); } }
51
+
52
+ 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); }); }; }
53
+
54
+ class ApplicationModel extends _database().Model {
55
+ static getDatabaseConfig(app) {
56
+ return _lodash().default.cloneDeep(_lodash().default.isPlainObject(app.options.database) ? app.options.database : app.options.database.options);
57
+ }
58
+
59
+ static handleAppStart(app, options) {
60
+ return _asyncToGenerator(function* () {
61
+ yield app.load();
62
+
63
+ if (!_lodash().default.get(options, 'skipInstall', false)) {
64
+ yield app.install();
65
+ }
66
+
67
+ yield app.start();
68
+ })();
69
+ }
70
+
71
+ registerToMainApp(mainApp, options) {
72
+ var _this = this;
73
+
74
+ return _asyncToGenerator(function* () {
75
+ const appName = _this.get('name');
76
+
77
+ const appOptions = _this.get('options') || {};
78
+ const AppModel = _this.constructor;
79
+ const app = mainApp.appManager.createApplication(appName, _objectSpread(_objectSpread({}, AppModel.initOptions(appName, mainApp)), appOptions)); // create database before installation if it not exists
80
+
81
+ app.on('beforeInstall', /*#__PURE__*/function () {
82
+ var _createDatabase = _asyncToGenerator(function* () {
83
+ const _AppModel$getDatabase = AppModel.getDatabaseConfig(app),
84
+ host = _AppModel$getDatabase.host,
85
+ port = _AppModel$getDatabase.port,
86
+ username = _AppModel$getDatabase.username,
87
+ password = _AppModel$getDatabase.password,
88
+ database = _AppModel$getDatabase.database,
89
+ dialect = _AppModel$getDatabase.dialect;
90
+
91
+ if (dialect === 'mysql') {
92
+ const mysql = require('mysql2/promise');
93
+
94
+ const connection = yield mysql.createConnection({
95
+ host,
96
+ port,
97
+ user: username,
98
+ password
85
99
  });
86
- yield AppModel.handleAppStart(app, options);
87
- yield AppModel.update({
88
- status: 'running',
89
- }, {
90
- transaction: options.transaction,
91
- where: {
92
- [AppModel.primaryKeyAttribute]: this.get(AppModel.primaryKeyAttribute),
93
- },
94
- hooks: false,
100
+ yield connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
101
+ yield connection.close();
102
+ }
103
+
104
+ if (dialect === 'postgres') {
105
+ const _require = require('pg'),
106
+ Client = _require.Client;
107
+
108
+ const client = new Client({
109
+ user: username,
110
+ host,
111
+ password: password,
112
+ port
95
113
  });
114
+ yield client.connect();
115
+
116
+ try {
117
+ yield client.query(`CREATE DATABASE "${database}"`);
118
+ } catch (e) {}
119
+
120
+ yield client.end();
121
+ }
96
122
  });
97
- }
98
- static initOptions(appName, mainApp) {
99
- const rawDatabaseOptions = this.getDatabaseConfig(mainApp);
100
- if (rawDatabaseOptions.dialect === 'sqlite') {
101
- const mainAppStorage = rawDatabaseOptions.storage;
102
- if (mainAppStorage !== ':memory:') {
103
- const mainStorageDir = path.dirname(mainAppStorage);
104
- rawDatabaseOptions.storage = path.join(mainStorageDir, `${appName}.sqlite`);
105
- }
106
- }
107
- else {
108
- rawDatabaseOptions.database = appName;
123
+
124
+ function createDatabase() {
125
+ return _createDatabase.apply(this, arguments);
109
126
  }
110
- return {
111
- database: rawDatabaseOptions,
112
- };
127
+
128
+ return createDatabase;
129
+ }());
130
+ yield AppModel.handleAppStart(app, options);
131
+ yield AppModel.update({
132
+ status: 'running'
133
+ }, {
134
+ transaction: options.transaction,
135
+ where: {
136
+ [AppModel.primaryKeyAttribute]: _this.get(AppModel.primaryKeyAttribute)
137
+ },
138
+ hooks: false
139
+ });
140
+ })();
141
+ }
142
+
143
+ static initOptions(appName, mainApp) {
144
+ const rawDatabaseOptions = this.getDatabaseConfig(mainApp);
145
+
146
+ if (rawDatabaseOptions.dialect === 'sqlite') {
147
+ const mainAppStorage = rawDatabaseOptions.storage;
148
+
149
+ if (mainAppStorage !== ':memory:') {
150
+ const mainStorageDir = path().dirname(mainAppStorage);
151
+ rawDatabaseOptions.storage = path().join(mainStorageDir, `${appName}.sqlite`);
152
+ }
153
+ } else {
154
+ rawDatabaseOptions.database = appName;
113
155
  }
156
+
157
+ return {
158
+ database: rawDatabaseOptions
159
+ };
160
+ }
161
+
114
162
  }
115
- exports.ApplicationModel = ApplicationModel;
116
- //# sourceMappingURL=application.js.map
163
+
164
+ exports.ApplicationModel = ApplicationModel;
package/lib/server.js CHANGED
@@ -1,61 +1,117 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
12
6
  exports.PluginMultiAppManager = void 0;
13
- const server_1 = require("@nocobase/server");
14
- const path_1 = require("path");
15
- const application_1 = require("./models/application");
16
- class PluginMultiAppManager extends server_1.Plugin {
17
- getName() {
18
- return this.getPackageName(__dirname);
19
- }
20
- install(options) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const repo = this.db.getRepository('collections');
23
- if (repo) {
24
- yield repo.db2cm('applications');
25
- }
7
+
8
+ function _server() {
9
+ const data = require("@nocobase/server");
10
+
11
+ _server = function _server() {
12
+ return data;
13
+ };
14
+
15
+ return data;
16
+ }
17
+
18
+ function _path() {
19
+ const data = require("path");
20
+
21
+ _path = function _path() {
22
+ return data;
23
+ };
24
+
25
+ return data;
26
+ }
27
+
28
+ var _application = require("./models/application");
29
+
30
+ 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); } }
31
+
32
+ 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); }); }; }
33
+
34
+ class PluginMultiAppManager extends _server().Plugin {
35
+ getName() {
36
+ return this.getPackageName(__dirname);
37
+ }
38
+
39
+ install(options) {
40
+ var _this = this;
41
+
42
+ return _asyncToGenerator(function* () {
43
+ const repo = _this.db.getRepository('collections');
44
+
45
+ if (repo) {
46
+ yield repo.db2cm('applications');
47
+ }
48
+ })();
49
+ }
50
+
51
+ load() {
52
+ var _this2 = this;
53
+
54
+ return _asyncToGenerator(function* () {
55
+ _this2.db.registerModels({
56
+ ApplicationModel: _application.ApplicationModel
57
+ });
58
+
59
+ yield _this2.db.import({
60
+ directory: (0, _path().resolve)(__dirname, 'collections')
61
+ });
62
+
63
+ _this2.db.on('applications.afterCreateWithAssociations', /*#__PURE__*/function () {
64
+ var _ref = _asyncToGenerator(function* (model, options) {
65
+ const transaction = options.transaction;
66
+ yield model.registerToMainApp(_this2.app, {
67
+ transaction
68
+ });
26
69
  });
27
- }
28
- load() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- this.db.registerModels({
31
- ApplicationModel: application_1.ApplicationModel,
32
- });
33
- yield this.db.import({
34
- directory: (0, path_1.resolve)(__dirname, 'collections'),
35
- });
36
- this.db.on('applications.afterCreateWithAssociations', (model, options) => __awaiter(this, void 0, void 0, function* () {
37
- const { transaction } = options;
38
- yield model.registerToMainApp(this.app, { transaction });
39
- }));
40
- this.db.on('applications.afterDestroy', (model) => __awaiter(this, void 0, void 0, function* () {
41
- yield this.app.appManager.removeApplication(model.get('name'));
42
- }));
43
- this.app.appManager.on('beforeGetApplication', function lazyLoadApplication({ appManager, name }) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- if (!appManager.applications.has(name)) {
46
- const existsApplication = (yield this.app.db.getRepository('applications').findOne({
47
- filter: {
48
- name,
49
- },
50
- }));
51
- if (existsApplication) {
52
- yield existsApplication.registerToMainApp(this.app, { skipInstall: true });
53
- }
54
- }
55
- });
70
+
71
+ return function (_x, _x2) {
72
+ return _ref.apply(this, arguments);
73
+ };
74
+ }());
75
+
76
+ _this2.db.on('applications.afterDestroy', /*#__PURE__*/function () {
77
+ var _ref2 = _asyncToGenerator(function* (model) {
78
+ yield _this2.app.appManager.removeApplication(model.get('name'));
79
+ });
80
+
81
+ return function (_x3) {
82
+ return _ref2.apply(this, arguments);
83
+ };
84
+ }());
85
+
86
+ _this2.app.appManager.on('beforeGetApplication', /*#__PURE__*/function () {
87
+ var _lazyLoadApplication = _asyncToGenerator(function* ({
88
+ appManager,
89
+ name
90
+ }) {
91
+ if (!appManager.applications.has(name)) {
92
+ const existsApplication = yield this.app.db.getRepository('applications').findOne({
93
+ filter: {
94
+ name
95
+ }
56
96
  });
97
+
98
+ if (existsApplication) {
99
+ yield existsApplication.registerToMainApp(this.app, {
100
+ skipInstall: true
101
+ });
102
+ }
103
+ }
57
104
  });
58
- }
105
+
106
+ function lazyLoadApplication(_x4) {
107
+ return _lazyLoadApplication.apply(this, arguments);
108
+ }
109
+
110
+ return lazyLoadApplication;
111
+ }());
112
+ })();
113
+ }
114
+
59
115
  }
60
- exports.PluginMultiAppManager = PluginMultiAppManager;
61
- //# sourceMappingURL=server.js.map
116
+
117
+ exports.PluginMultiAppManager = PluginMultiAppManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-multi-app-manager",
3
- "version": "0.7.0-alpha.33",
3
+ "version": "0.7.0-alpha.56",
4
4
  "main": "lib/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "licenses": [
@@ -9,13 +9,8 @@
9
9
  "url": "http://www.apache.org/licenses/LICENSE-2.0"
10
10
  }
11
11
  ],
12
- "scripts": {
13
- "build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm",
14
- "build:cjs": "tsc --project tsconfig.build.json",
15
- "build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir esm"
16
- },
17
12
  "dependencies": {
18
- "@nocobase/server": "0.7.0-alpha.33"
13
+ "@nocobase/server": "0.7.0-alpha.56"
19
14
  },
20
- "gitHead": "c4b5f4f84b18c2d8bc40f82947b9338e2f620984"
15
+ "gitHead": "9a8c05e8fb26029f1d1ba68408a8bddac0e67a76"
21
16
  }
@@ -1,2 +0,0 @@
1
- declare const _default: import("@nocobase/database").CollectionOptions;
2
- export default _default;
@@ -1,44 +0,0 @@
1
- import { defineCollection } from '@nocobase/database';
2
- export default defineCollection({
3
- name: 'applications',
4
- model: 'ApplicationModel',
5
- autoGenId: false,
6
- title: '{{t("Applications")}}',
7
- sortable: 'sort',
8
- filterTargetKey: 'name',
9
- fields: [
10
- {
11
- type: 'uid',
12
- name: 'name',
13
- primaryKey: true,
14
- prefix: 'a',
15
- interface: 'input',
16
- uiSchema: {
17
- type: 'string',
18
- title: '{{t("Application name")}}',
19
- 'x-component': 'Input',
20
- 'x-read-pretty': true,
21
- },
22
- },
23
- {
24
- type: 'string',
25
- name: 'status',
26
- interface: 'radioGroup',
27
- defaultValue: 'pending',
28
- uiSchema: {
29
- type: 'string',
30
- title: '{{t("Application status")}}',
31
- 'x-component': 'Radio.Group',
32
- enum: [
33
- { label: '创建中', value: 'pending' },
34
- { label: '运行中', value: 'running' },
35
- ],
36
- },
37
- },
38
- {
39
- type: 'json',
40
- name: 'options',
41
- },
42
- ],
43
- });
44
- //# sourceMappingURL=applications.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"applications.js","sourceRoot":"","sources":["../../src/collections/applications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,eAAe,gBAAgB,CAAC;IAC9B,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,kBAAkB;IACzB,SAAS,EAAE,KAAK;IAChB,KAAK,EAAE,uBAAuB;IAC9B,QAAQ,EAAE,MAAM;IAChB,eAAe,EAAE,MAAM;IACvB,MAAM,EAAE;QACN;YACE,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,MAAM;YACZ,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,GAAG;YACX,SAAS,EAAE,OAAO;YAClB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,2BAA2B;gBAClC,aAAa,EAAE,OAAO;gBACtB,eAAe,EAAE,IAAI;aACtB;SACF;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,YAAY;YACvB,YAAY,EAAE,SAAS;YACvB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,6BAA6B;gBACpC,aAAa,EAAE,aAAa;gBAC5B,IAAI,EAAE;oBACJ,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;oBAClC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;iBACnC;aACF;SACF;QACD;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,SAAS;SAChB;KACF;CACF,CAAC,CAAC","sourcesContent":["import { defineCollection } from '@nocobase/database';\n\nexport default defineCollection({\n name: 'applications',\n model: 'ApplicationModel',\n autoGenId: false,\n title: '{{t(\"Applications\")}}',\n sortable: 'sort',\n filterTargetKey: 'name',\n fields: [\n {\n type: 'uid',\n name: 'name',\n primaryKey: true,\n prefix: 'a',\n interface: 'input',\n uiSchema: {\n type: 'string',\n title: '{{t(\"Application name\")}}',\n 'x-component': 'Input',\n 'x-read-pretty': true,\n },\n },\n {\n type: 'string',\n name: 'status',\n interface: 'radioGroup',\n defaultValue: 'pending',\n uiSchema: {\n type: 'string',\n title: '{{t(\"Application status\")}}',\n 'x-component': 'Radio.Group',\n enum: [\n { label: '创建中', value: 'pending' },\n { label: '运行中', value: 'running' },\n ],\n },\n },\n {\n type: 'json',\n name: 'options',\n },\n ],\n});\n"]}
package/esm/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { ApplicationModel, registerAppOptions } from './models/application';
2
- export { PluginMultiAppManager as default } from './server';
3
- export { ApplicationModel, registerAppOptions };
package/esm/index.js DELETED
@@ -1,4 +0,0 @@
1
- import { ApplicationModel } from './models/application';
2
- export { PluginMultiAppManager as default } from './server';
3
- export { ApplicationModel };
4
- //# sourceMappingURL=index.js.map
package/esm/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAsB,MAAM,sBAAsB,CAAC;AAE5E,OAAO,EAAE,qBAAqB,IAAI,OAAO,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAsB,CAAC","sourcesContent":["import { ApplicationModel, registerAppOptions } from './models/application';\n\nexport { PluginMultiAppManager as default } from './server';\nexport { ApplicationModel, registerAppOptions };\n"]}
@@ -1,13 +0,0 @@
1
- import { IDatabaseOptions, Model, TransactionAble } from '@nocobase/database';
2
- import { Application } from '@nocobase/server';
3
- export interface registerAppOptions extends TransactionAble {
4
- skipInstall?: boolean;
5
- }
6
- export declare class ApplicationModel extends Model {
7
- static getDatabaseConfig(app: Application): IDatabaseOptions;
8
- static handleAppStart(app: Application, options: registerAppOptions): Promise<void>;
9
- registerToMainApp(mainApp: Application, options: registerAppOptions): Promise<void>;
10
- static initOptions(appName: string, mainApp: Application): {
11
- database: IDatabaseOptions;
12
- };
13
- }
@@ -1,90 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Model } from '@nocobase/database';
11
- import lodash from 'lodash';
12
- import * as path from 'path';
13
- export class ApplicationModel extends Model {
14
- static getDatabaseConfig(app) {
15
- return lodash.cloneDeep(lodash.isPlainObject(app.options.database)
16
- ? app.options.database
17
- : app.options.database.options);
18
- }
19
- static handleAppStart(app, options) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- yield app.load();
22
- if (!lodash.get(options, 'skipInstall', false)) {
23
- yield app.install();
24
- }
25
- yield app.start();
26
- });
27
- }
28
- registerToMainApp(mainApp, options) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- const appName = this.get('name');
31
- const appOptions = this.get('options') || {};
32
- const AppModel = this.constructor;
33
- const app = mainApp.appManager.createApplication(appName, Object.assign(Object.assign({}, AppModel.initOptions(appName, mainApp)), appOptions));
34
- // create database before installation if it not exists
35
- app.on('beforeInstall', function createDatabase() {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const { host, port, username, password, database, dialect } = AppModel.getDatabaseConfig(app);
38
- if (dialect === 'mysql') {
39
- const mysql = require('mysql2/promise');
40
- const connection = yield mysql.createConnection({ host, port, user: username, password });
41
- yield connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
42
- yield connection.close();
43
- }
44
- if (dialect === 'postgres') {
45
- const { Client } = require('pg');
46
- const client = new Client({
47
- user: username,
48
- host,
49
- password: password,
50
- port,
51
- });
52
- yield client.connect();
53
- try {
54
- yield client.query(`CREATE DATABASE "${database}"`);
55
- }
56
- catch (e) { }
57
- yield client.end();
58
- }
59
- });
60
- });
61
- yield AppModel.handleAppStart(app, options);
62
- yield AppModel.update({
63
- status: 'running',
64
- }, {
65
- transaction: options.transaction,
66
- where: {
67
- [AppModel.primaryKeyAttribute]: this.get(AppModel.primaryKeyAttribute),
68
- },
69
- hooks: false,
70
- });
71
- });
72
- }
73
- static initOptions(appName, mainApp) {
74
- const rawDatabaseOptions = this.getDatabaseConfig(mainApp);
75
- if (rawDatabaseOptions.dialect === 'sqlite') {
76
- const mainAppStorage = rawDatabaseOptions.storage;
77
- if (mainAppStorage !== ':memory:') {
78
- const mainStorageDir = path.dirname(mainAppStorage);
79
- rawDatabaseOptions.storage = path.join(mainStorageDir, `${appName}.sqlite`);
80
- }
81
- }
82
- else {
83
- rawDatabaseOptions.database = appName;
84
- }
85
- return {
86
- database: rawDatabaseOptions,
87
- };
88
- }
89
- }
90
- //# sourceMappingURL=application.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"application.js","sourceRoot":"","sources":["../../src/models/application.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAiB,EAAoB,KAAK,EAAmB,MAAM,oBAAoB,CAAC;AAExF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAM7B,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,MAAM,CAAC,iBAAiB,CAAC,GAAgB;QACvC,OAAO,MAAM,CAAC,SAAS,CACrB,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;YACxC,CAAC,CAAE,GAAG,CAAC,OAAO,CAAC,QAA6B;YAC5C,CAAC,CAAE,GAAG,CAAC,OAAO,CAAC,QAAqB,CAAC,OAAO,CAC/C,CAAC;IACJ,CAAC;IAED,MAAM,CAAO,cAAc,CAAC,GAAgB,EAAE,OAA2B;;YACvE,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YAEjB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,CAAC,EAAE;gBAC9C,MAAM,GAAG,CAAC,OAAO,EAAE,CAAC;aACrB;YAED,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;KAAA;IAEK,iBAAiB,CAAC,OAAoB,EAAE,OAA2B;;YACvE,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAW,CAAC;YAC3C,MAAM,UAAU,GAAI,IAAI,CAAC,GAAG,CAAC,SAAS,CAAS,IAAI,EAAE,CAAC;YAEtD,MAAM,QAAQ,G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AA,CAAC,CAAC;YAEH,MAAM,QAAQ,CAAC,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YAE5C,MAAM,QAAQ,CAAC,MAAM,CACnB;gBACE,MAAM,EAAE,SAAS;aAClB,EACD;gBACE,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,KAAK,EAAE;oBACL,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,mBAAmB,CAAC;iBACvE;gBACD,KAAK,EAAE,KAAK;aACb,CACF,CAAC;QACJ,CAAC;KAAA;IAED,MAAM,CAAC,WAAW,CAAC,OAAe,EAAE,OAAoB;QACtD,MAAM,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAE3D,IAAI,kBAAkB,CAAC,OAAO,KAAK,QAAQ,EAAE;YAC3C,MAAM,cAAc,GAAG,kBAAkB,CAAC,OAAO,CAAC;YAClD,IAAI,cAAc,KAAK,UAAU,EAAE;gBACjC,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;gBACpD,kBAAkB,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,OAAO,SAAS,CAAC,CAAC;aAC7E;SACF;aAAM;YACL,kBAAkB,CAAC,QAAQ,GAAG,OAAO,CAAC;SACvC;QAED,OAAO;YACL,QAAQ,EAAE,kBAAkB;SAC7B,CAAC;IACJ,CAAC;CACF","sourcesContent":["import Database, { IDatabaseOptions, Model, TransactionAble } from '@nocobase/database';\nimport { Application } from '@nocobase/server';\nimport lodash from 'lodash';\nimport * as path from 'path';\n\nexport interface registerAppOptions extends TransactionAble {\n skipInstall?: boolean;\n}\n\nexport class ApplicationModel extends Model {\n static getDatabaseConfig(app: Application): IDatabaseOptions {\n return lodash.cloneDeep(\n lodash.isPlainObject(app.options.database)\n ? (app.options.database as IDatabaseOptions)\n : (app.options.database as Database).options,\n );\n }\n\n static async handleAppStart(app: Application, options: registerAppOptions) {\n await app.load();\n\n if (!lodash.get(options, 'skipInstall', false)) {\n await app.install();\n }\n\n await app.start();\n }\n\n async registerToMainApp(mainApp: Application, options: registerAppOptions) {\n const appName = this.get('name') as string;\n const appOptions = (this.get('options') as any) || {};\n\n const AppModel = this.constructor as typeof ApplicationModel;\n\n const app = mainApp.appManager.createApplication(appName, {\n ...AppModel.initOptions(appName, mainApp),\n ...appOptions,\n });\n\n // create database before installation if it not exists\n app.on('beforeInstall', async function createDatabase() {\n const { host, port, username, password, database, dialect } = AppModel.getDatabaseConfig(app);\n\n if (dialect === 'mysql') {\n const mysql = require('mysql2/promise');\n const connection = await mysql.createConnection({ host, port, user: username, password });\n await connection.query(`CREATE DATABASE IF NOT EXISTS \\`${database}\\`;`);\n await connection.close();\n }\n\n if (dialect === 'postgres') {\n const { Client } = require('pg');\n\n const client = new Client({\n user: username,\n host,\n password: password,\n port,\n });\n\n await client.connect();\n\n try {\n await client.query(`CREATE DATABASE \"${database}\"`);\n } catch (e) {}\n\n await client.end();\n }\n });\n\n await AppModel.handleAppStart(app, options);\n\n await AppModel.update(\n {\n status: 'running',\n },\n {\n transaction: options.transaction,\n where: {\n [AppModel.primaryKeyAttribute]: this.get(AppModel.primaryKeyAttribute),\n },\n hooks: false,\n },\n );\n }\n\n static initOptions(appName: string, mainApp: Application) {\n const rawDatabaseOptions = this.getDatabaseConfig(mainApp);\n\n if (rawDatabaseOptions.dialect === 'sqlite') {\n const mainAppStorage = rawDatabaseOptions.storage;\n if (mainAppStorage !== ':memory:') {\n const mainStorageDir = path.dirname(mainAppStorage);\n rawDatabaseOptions.storage = path.join(mainStorageDir, `${appName}.sqlite`);\n }\n } else {\n rawDatabaseOptions.database = appName;\n }\n\n return {\n database: rawDatabaseOptions,\n };\n }\n}\n"]}
package/esm/server.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { InstallOptions, Plugin } from '@nocobase/server';
2
- export declare class PluginMultiAppManager extends Plugin {
3
- getName(): string;
4
- install(options?: InstallOptions): Promise<void>;
5
- load(): Promise<void>;
6
- }
package/esm/server.js DELETED
@@ -1,57 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Plugin } from '@nocobase/server';
11
- import { resolve } from 'path';
12
- import { ApplicationModel } from './models/application';
13
- export class PluginMultiAppManager extends Plugin {
14
- getName() {
15
- return this.getPackageName(__dirname);
16
- }
17
- install(options) {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- const repo = this.db.getRepository('collections');
20
- if (repo) {
21
- yield repo.db2cm('applications');
22
- }
23
- });
24
- }
25
- load() {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- this.db.registerModels({
28
- ApplicationModel,
29
- });
30
- yield this.db.import({
31
- directory: resolve(__dirname, 'collections'),
32
- });
33
- this.db.on('applications.afterCreateWithAssociations', (model, options) => __awaiter(this, void 0, void 0, function* () {
34
- const { transaction } = options;
35
- yield model.registerToMainApp(this.app, { transaction });
36
- }));
37
- this.db.on('applications.afterDestroy', (model) => __awaiter(this, void 0, void 0, function* () {
38
- yield this.app.appManager.removeApplication(model.get('name'));
39
- }));
40
- this.app.appManager.on('beforeGetApplication', function lazyLoadApplication({ appManager, name }) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- if (!appManager.applications.has(name)) {
43
- const existsApplication = (yield this.app.db.getRepository('applications').findOne({
44
- filter: {
45
- name,
46
- },
47
- }));
48
- if (existsApplication) {
49
- yield existsApplication.registerToMainApp(this.app, { skipInstall: true });
50
- }
51
- }
52
- });
53
- });
54
- });
55
- }
56
- }
57
- //# sourceMappingURL=server.js.map
package/esm/server.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAA8B,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD,MAAM,OAAO,qBAAsB,SAAQ,MAAM;IAC/C,OAAO;QACL,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAEK,OAAO,CAAC,OAAwB;;YACpC,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,aAAa,CAAM,aAAa,CAAC,CAAC;YACvD,IAAI,IAAI,EAAE;gBACR,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;aAClC;QACH,CAAC;KAAA;IAEK,IAAI;;YACR,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC;gBACrB,gBAAgB;aACjB,CAAC,CAAC;YAEH,MAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC;gBACnB,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,aAAa,CAAC;aAC7C,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,0CAA0C,EAAE,CAAO,KAAuB,EAAE,OAAO,EAAE,EAAE;gBAChG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;gBAEhC,MAAM,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;YAC3D,CAAC,CAAA,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,2BAA2B,EAAE,CAAO,KAAuB,EAAE,EAAE;gBACxE,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAW,CAAC,CAAC;YAC3E,CAAC,CAAA,CAAC,CAAC;YAEH,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CACpB,sBAAsB,EACtB,SAAe,mBAAmB,CAAC,EAAE,UAAU,EAAE,IAAI,EAA4C;;oBAC/F,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;wBACtC,MAAM,iBAAiB,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC;4BACjF,MAAM,EAAE;gCACN,IAAI;6BACL;yBACF,CAAC,CAA4B,CAAC;wBAE/B,IAAI,iBAAiB,EAAE;4BACrB,MAAM,iBAAiB,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;yBAC5E;qBACF;gBACH,CAAC;aAAA,CACF,CAAC;QACJ,CAAC;KAAA;CACF","sourcesContent":["import { AppManager, InstallOptions, Plugin } from '@nocobase/server';\nimport { resolve } from 'path';\nimport { ApplicationModel } from './models/application';\n\nexport class PluginMultiAppManager extends Plugin {\n getName(): string {\n return this.getPackageName(__dirname);\n }\n\n async install(options?: InstallOptions) {\n const repo = this.db.getRepository<any>('collections');\n if (repo) {\n await repo.db2cm('applications');\n }\n }\n\n async load() {\n this.db.registerModels({\n ApplicationModel,\n });\n\n await this.db.import({\n directory: resolve(__dirname, 'collections'),\n });\n\n this.db.on('applications.afterCreateWithAssociations', async (model: ApplicationModel, options) => {\n const { transaction } = options;\n\n await model.registerToMainApp(this.app, { transaction });\n });\n\n this.db.on('applications.afterDestroy', async (model: ApplicationModel) => {\n await this.app.appManager.removeApplication(model.get('name') as string);\n });\n\n this.app.appManager.on(\n 'beforeGetApplication',\n async function lazyLoadApplication({ appManager, name }: { appManager: AppManager; name: string }) {\n if (!appManager.applications.has(name)) {\n const existsApplication = (await this.app.db.getRepository('applications').findOne({\n filter: {\n name,\n },\n })) as ApplicationModel | null;\n\n if (existsApplication) {\n await existsApplication.registerToMainApp(this.app, { skipInstall: true });\n }\n }\n },\n );\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"applications.js","sourceRoot":"","sources":["../../src/collections/applications.ts"],"names":[],"mappings":";;AAAA,iDAAsD;AAEtD,kBAAe,IAAA,2BAAgB,EAAC;IAC9B,IAAI,EAAE,cAAc;IACpB,KAAK,EAAE,kBAAkB;IACzB,SAAS,EAAE,KAAK;IAChB,KAAK,EAAE,uBAAuB;IAC9B,QAAQ,EAAE,MAAM;IAChB,eAAe,EAAE,MAAM;IACvB,MAAM,EAAE;QACN;YACE,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,MAAM;YACZ,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,GAAG;YACX,SAAS,EAAE,OAAO;YAClB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,2BAA2B;gBAClC,aAAa,EAAE,OAAO;gBACtB,eAAe,EAAE,IAAI;aACtB;SACF;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,QAAQ;YACd,SAAS,EAAE,YAAY;YACvB,YAAY,EAAE,SAAS;YACvB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,6BAA6B;gBACpC,aAAa,EAAE,aAAa;gBAC5B,IAAI,EAAE;oBACJ,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;oBAClC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE;iBACnC;aACF;SACF;QACD;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,SAAS;SAChB;KACF;CACF,CAAC,CAAC","sourcesContent":["import { defineCollection } from '@nocobase/database';\n\nexport default defineCollection({\n name: 'applications',\n model: 'ApplicationModel',\n autoGenId: false,\n title: '{{t(\"Applications\")}}',\n sortable: 'sort',\n filterTargetKey: 'name',\n fields: [\n {\n type: 'uid',\n name: 'name',\n primaryKey: true,\n prefix: 'a',\n interface: 'input',\n uiSchema: {\n type: 'string',\n title: '{{t(\"Application name\")}}',\n 'x-component': 'Input',\n 'x-read-pretty': true,\n },\n },\n {\n type: 'string',\n name: 'status',\n interface: 'radioGroup',\n defaultValue: 'pending',\n uiSchema: {\n type: 'string',\n title: '{{t(\"Application status\")}}',\n 'x-component': 'Radio.Group',\n enum: [\n { label: '创建中', value: 'pending' },\n { label: '运行中', value: 'running' },\n ],\n },\n },\n {\n type: 'json',\n name: 'options',\n },\n ],\n});\n"]}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4E;AAGnE,iGAHA,8BAAgB,OAGA;AADzB,mCAA4D;AAAnD,iGAAA,qBAAqB,OAAW","sourcesContent":["import { ApplicationModel, registerAppOptions } from './models/application';\n\nexport { PluginMultiAppManager as default } from './server';\nexport { ApplicationModel, registerAppOptions };\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"application.js","sourceRoot":"","sources":["../../src/models/application.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAwF;AAExF,oDAA4B;AAC5B,2CAA6B;AAM7B,MAAa,gBAAiB,SAAQ,gBAAK;IACzC,MAAM,CAAC,iBAAiB,CAAC,GAAgB;QACvC,OAAO,gBAAM,CAAC,SAAS,CACrB,gBAAM,CAAC,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;YACxC,CAAC,CAAE,GAAG,CAAC,OAAO,CAAC,QAA6B;YAC5C,CAAC,CAAE,GAAG,CAAC,OAAO,CAAC,QAAqB,CAAC,OAAO,CAC/C,CAAC;IACJ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O,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,GAAG,OAAO,SAAS,CAAC,CAAC;aAC7E;SACF;aAAM;YACL,kBAAkB,CAAC,QAAQ,GAAG,OAAO,CAAC;SACvC;QAED,OAAO;YACL,QAAQ,EAAE,kBAAkB;SAC7B,CAAC;IACJ,CAAC;CACF;AA9FD,4CA8FC","sourcesContent":["import Database, { IDatabaseOptions, Model, TransactionAble } from '@nocobase/database';\nimport { Application } from '@nocobase/server';\nimport lodash from 'lodash';\nimport * as path from 'path';\n\nexport interface registerAppOptions extends TransactionAble {\n skipInstall?: boolean;\n}\n\nexport class ApplicationModel extends Model {\n static getDatabaseConfig(app: Application): IDatabaseOptions {\n return lodash.cloneDeep(\n lodash.isPlainObject(app.options.database)\n ? (app.options.database as IDatabaseOptions)\n : (app.options.database as Database).options,\n );\n }\n\n static async handleAppStart(app: Application, options: registerAppOptions) {\n await app.load();\n\n if (!lodash.get(options, 'skipInstall', false)) {\n await app.install();\n }\n\n await app.start();\n }\n\n async registerToMainApp(mainApp: Application, options: registerAppOptions) {\n const appName = this.get('name') as string;\n const appOptions = (this.get('options') as any) || {};\n\n const AppModel = this.constructor as typeof ApplicationModel;\n\n const app = mainApp.appManager.createApplication(appName, {\n ...AppModel.initOptions(appName, mainApp),\n ...appOptions,\n });\n\n // create database before installation if it not exists\n app.on('beforeInstall', async function createDatabase() {\n const { host, port, username, password, database, dialect } = AppModel.getDatabaseConfig(app);\n\n if (dialect === 'mysql') {\n const mysql = require('mysql2/promise');\n const connection = await mysql.createConnection({ host, port, user: username, password });\n await connection.query(`CREATE DATABASE IF NOT EXISTS \\`${database}\\`;`);\n await connection.close();\n }\n\n if (dialect === 'postgres') {\n const { Client } = require('pg');\n\n const client = new Client({\n user: username,\n host,\n password: password,\n port,\n });\n\n await client.connect();\n\n try {\n await client.query(`CREATE DATABASE \"${database}\"`);\n } catch (e) {}\n\n await client.end();\n }\n });\n\n await AppModel.handleAppStart(app, options);\n\n await AppModel.update(\n {\n status: 'running',\n },\n {\n transaction: options.transaction,\n where: {\n [AppModel.primaryKeyAttribute]: this.get(AppModel.primaryKeyAttribute),\n },\n hooks: false,\n },\n );\n }\n\n static initOptions(appName: string, mainApp: Application) {\n const rawDatabaseOptions = this.getDatabaseConfig(mainApp);\n\n if (rawDatabaseOptions.dialect === 'sqlite') {\n const mainAppStorage = rawDatabaseOptions.storage;\n if (mainAppStorage !== ':memory:') {\n const mainStorageDir = path.dirname(mainAppStorage);\n rawDatabaseOptions.storage = path.join(mainStorageDir, `${appName}.sqlite`);\n }\n } else {\n rawDatabaseOptions.database = appName;\n }\n\n return {\n database: rawDatabaseOptions,\n };\n }\n}\n"]}
package/lib/server.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAsE;AACtE,+BAA+B;AAC/B,sDAAwD;AAExD,MAAa,qBAAsB,SAAQ,eAAM;IAC/C,OAAO;QACL,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAEK,OAAO,CAAC,OAAwB;;YACpC,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,aAAa,CAAM,aAAa,CAAC,CAAC;YACvD,IAAI,IAAI,EAAE;gBACR,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;aAClC;QACH,CAAC;KAAA;IAEK,IAAI;;YACR,IAAI,CAAC,EAAE,CAAC,cAAc,CAAC;gBACrB,gBAAgB,EAAhB,8BAAgB;aACjB,CAAC,CAAC;YAEH,MAAM,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC;gBACnB,SAAS,EAAE,IAAA,cAAO,EAAC,SAAS,EAAE,aAAa,CAAC;aAC7C,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,0CAA0C,EAAE,CAAO,KAAuB,EAAE,OAAO,EAAE,EAAE;gBAChG,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;gBAEhC,MAAM,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;YAC3D,CAAC,CAAA,CAAC,CAAC;YAEH,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,2BAA2B,EAAE,CAAO,KAAuB,EAAE,EAAE;gBACxE,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAW,CAAC,CAAC;YAC3E,CAAC,CAAA,CAAC,CAAC;YAEH,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CACpB,sBAAsB,EACtB,SAAe,mBAAmB,CAAC,EAAE,UAAU,EAAE,IAAI,EAA4C;;oBAC/F,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;wBACtC,MAAM,iBAAiB,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC;4BACjF,MAAM,EAAE;gCACN,IAAI;6BACL;yBACF,CAAC,CAA4B,CAAC;wBAE/B,IAAI,iBAAiB,EAAE;4BACrB,MAAM,iBAAiB,CAAC,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC;yBAC5E;qBACF;gBACH,CAAC;aAAA,CACF,CAAC;QACJ,CAAC;KAAA;CACF;AAhDD,sDAgDC","sourcesContent":["import { AppManager, InstallOptions, Plugin } from '@nocobase/server';\nimport { resolve } from 'path';\nimport { ApplicationModel } from './models/application';\n\nexport class PluginMultiAppManager extends Plugin {\n getName(): string {\n return this.getPackageName(__dirname);\n }\n\n async install(options?: InstallOptions) {\n const repo = this.db.getRepository<any>('collections');\n if (repo) {\n await repo.db2cm('applications');\n }\n }\n\n async load() {\n this.db.registerModels({\n ApplicationModel,\n });\n\n await this.db.import({\n directory: resolve(__dirname, 'collections'),\n });\n\n this.db.on('applications.afterCreateWithAssociations', async (model: ApplicationModel, options) => {\n const { transaction } = options;\n\n await model.registerToMainApp(this.app, { transaction });\n });\n\n this.db.on('applications.afterDestroy', async (model: ApplicationModel) => {\n await this.app.appManager.removeApplication(model.get('name') as string);\n });\n\n this.app.appManager.on(\n 'beforeGetApplication',\n async function lazyLoadApplication({ appManager, name }: { appManager: AppManager; name: string }) {\n if (!appManager.applications.has(name)) {\n const existsApplication = (await this.app.db.getRepository('applications').findOne({\n filter: {\n name,\n },\n })) as ApplicationModel | null;\n\n if (existsApplication) {\n await existsApplication.registerToMainApp(this.app, { skipInstall: true });\n }\n }\n },\n );\n }\n}\n"]}
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.build.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "declaration": true
6
- },
7
- "include": ["./src/**/*.ts", "./src/**/*.tsx"],
8
- "exclude": ["./src/__tests__/*", "./esm/*", "./lib/*"]
9
- }