@nocobase/plugin-multi-app-manager 0.7.0-alpha.9 → 0.7.1-alpha.6

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,32 +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
- createdBy: true,
11
- filterTargetKey: 'name',
12
- fields: [
13
- {
14
- type: 'uid',
15
- name: 'name',
16
- primaryKey: true,
17
- prefix: 'a',
18
- interface: 'input',
19
- uiSchema: {
20
- type: 'string',
21
- title: '{{t("Application name")}}',
22
- 'x-component': 'Input',
23
- 'x-read-pretty': true,
24
- },
25
- },
26
- {
27
- type: 'json',
28
- name: 'options',
29
- },
30
- ],
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
31
5
  });
32
- //# 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.d.ts CHANGED
@@ -1 +1,3 @@
1
+ import { ApplicationModel, registerAppOptions } from './models/application';
1
2
  export { PluginMultiAppManager as default } from './server';
3
+ export { ApplicationModel, registerAppOptions };
package/lib/index.js CHANGED
@@ -1,6 +1,21 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = void 0;
4
- var server_1 = require("./server");
5
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return server_1.PluginMultiAppManager; } });
6
- //# 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,13 +1,13 @@
1
- import { IDatabaseOptions, Model, TransactionAble } from '@nocobase/database';
1
+ import { IDatabaseOptions, Model, Transactionable } from '@nocobase/database';
2
2
  import { Application } from '@nocobase/server';
3
- interface registerAppOptions extends TransactionAble {
3
+ export interface registerAppOptions extends Transactionable {
4
4
  skipInstall?: boolean;
5
5
  }
6
6
  export declare class ApplicationModel extends Model {
7
7
  static getDatabaseConfig(app: Application): IDatabaseOptions;
8
+ static handleAppStart(app: Application, options: registerAppOptions): Promise<void>;
8
9
  registerToMainApp(mainApp: Application, options: registerAppOptions): Promise<void>;
9
10
  static initOptions(appName: string, mainApp: Application): {
10
11
  database: IDatabaseOptions;
11
12
  };
12
13
  }
13
- export {};
@@ -1,101 +1,165 @@
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
- registerToMainApp(mainApp, options) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const { transaction } = options;
47
- const appName = this.get('name');
48
- const appOptions = this.get('options') || {};
49
- const app = mainApp.appManager.createApplication(appName, Object.assign(Object.assign({}, ApplicationModel.initOptions(appName, mainApp)), appOptions));
50
- app.on('beforeInstall', function createDatabase() {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const { host, port, username, password, database, dialect } = ApplicationModel.getDatabaseConfig(app);
53
- if (dialect === 'mysql') {
54
- const mysql = require('mysql2/promise');
55
- const connection = yield mysql.createConnection({ host, port, user: username, password });
56
- yield connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
57
- yield connection.close();
58
- }
59
- if (dialect === 'postgres') {
60
- const { Client } = require('pg');
61
- const client = new Client({
62
- user: username,
63
- host,
64
- password: password,
65
- port,
66
- });
67
- yield client.connect();
68
- try {
69
- yield client.query(`CREATE DATABASE "${database}"`);
70
- }
71
- catch (e) { }
72
- yield client.end();
73
- }
74
- });
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
75
99
  });
76
- yield app.load();
77
- if (!lodash_1.default.get(options, 'skipInstall', false)) {
78
- yield app.install();
79
- }
80
- yield app.start();
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
+ host,
110
+ port,
111
+ user: username,
112
+ password,
113
+ database: 'postgres'
114
+ });
115
+ yield client.connect();
116
+
117
+ try {
118
+ yield client.query(`CREATE DATABASE "${database}"`);
119
+ } catch (e) {}
120
+
121
+ yield client.end();
122
+ }
81
123
  });
82
- }
83
- static initOptions(appName, mainApp) {
84
- const rawDatabaseOptions = ApplicationModel.getDatabaseConfig(mainApp);
85
- if (rawDatabaseOptions.dialect === 'sqlite') {
86
- const mainAppStorage = rawDatabaseOptions.storage;
87
- if (mainAppStorage !== ':memory:') {
88
- const mainStorageDir = path.dirname(mainAppStorage);
89
- rawDatabaseOptions.storage = path.join(mainStorageDir, `${appName}.sqlite`);
90
- }
91
- }
92
- else {
93
- rawDatabaseOptions.database = appName;
124
+
125
+ function createDatabase() {
126
+ return _createDatabase.apply(this, arguments);
94
127
  }
95
- return {
96
- database: rawDatabaseOptions,
97
- };
128
+
129
+ return createDatabase;
130
+ }());
131
+ yield AppModel.handleAppStart(app, options);
132
+ yield AppModel.update({
133
+ status: 'running'
134
+ }, {
135
+ transaction: options.transaction,
136
+ where: {
137
+ [AppModel.primaryKeyAttribute]: _this.get(AppModel.primaryKeyAttribute)
138
+ },
139
+ hooks: false
140
+ });
141
+ })();
142
+ }
143
+
144
+ static initOptions(appName, mainApp) {
145
+ const rawDatabaseOptions = this.getDatabaseConfig(mainApp);
146
+
147
+ if (rawDatabaseOptions.dialect === 'sqlite') {
148
+ const mainAppStorage = rawDatabaseOptions.storage;
149
+
150
+ if (mainAppStorage !== ':memory:') {
151
+ const mainStorageDir = path().dirname(mainAppStorage);
152
+ rawDatabaseOptions.storage = path().join(mainStorageDir, `${appName}.sqlite`);
153
+ }
154
+ } else {
155
+ rawDatabaseOptions.database = appName;
98
156
  }
157
+
158
+ return {
159
+ database: rawDatabaseOptions
160
+ };
161
+ }
162
+
99
163
  }
100
- exports.ApplicationModel = ApplicationModel;
101
- //# sourceMappingURL=application.js.map
164
+
165
+ exports.ApplicationModel = ApplicationModel;
package/lib/server.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { Plugin } from '@nocobase/server';
1
+ import { InstallOptions, Plugin } from '@nocobase/server';
2
2
  export declare class PluginMultiAppManager extends Plugin {
3
3
  getName(): string;
4
+ install(options?: InstallOptions): Promise<void>;
4
5
  load(): Promise<void>;
5
6
  }
package/lib/server.js CHANGED
@@ -1,53 +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
- load() {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- this.db.registerModels({
23
- ApplicationModel: application_1.ApplicationModel,
24
- });
25
- yield this.db.import({
26
- directory: (0, path_1.resolve)(__dirname, 'collections'),
27
- });
28
- this.db.on('applications.afterCreateWithAssociations', (model, options) => __awaiter(this, void 0, void 0, function* () {
29
- const { transaction } = options;
30
- yield model.registerToMainApp(this.app, { transaction });
31
- }));
32
- this.db.on('applications.afterDestroy', (model) => __awaiter(this, void 0, void 0, function* () {
33
- yield this.app.appManager.removeApplication(model.get('name'));
34
- }));
35
- this.app.appManager.on('beforeGetApplication', function lazyLoadApplication({ appManager, name }) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- if (!appManager.applications.has(name)) {
38
- const existsApplication = (yield this.app.db.getRepository('applications').findOne({
39
- filter: {
40
- name,
41
- },
42
- }));
43
- if (existsApplication) {
44
- yield existsApplication.registerToMainApp(this.app, { skipInstall: true });
45
- }
46
- }
47
- });
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
+ });
69
+ });
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
+ }
48
96
  });
97
+
98
+ if (existsApplication) {
99
+ yield existsApplication.registerToMainApp(this.app, {
100
+ skipInstall: true
101
+ });
102
+ }
103
+ }
49
104
  });
50
- }
105
+
106
+ function lazyLoadApplication(_x4) {
107
+ return _lazyLoadApplication.apply(this, arguments);
108
+ }
109
+
110
+ return lazyLoadApplication;
111
+ }());
112
+ })();
113
+ }
114
+
51
115
  }
52
- exports.PluginMultiAppManager = PluginMultiAppManager;
53
- //# 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.9",
3
+ "version": "0.7.1-alpha.6",
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.9"
13
+ "@nocobase/server": "0.7.1-alpha.6"
19
14
  },
20
- "gitHead": "79d5b309fb92148162bfedfb7e304b4673faf568"
15
+ "gitHead": "b6f96c97020d278ae597bf05553442d7516b2216"
21
16
  }
@@ -1,2 +0,0 @@
1
- declare const _default: import("@nocobase/database").CollectionOptions;
2
- export default _default;
@@ -1,30 +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
- createdBy: true,
9
- filterTargetKey: 'name',
10
- fields: [
11
- {
12
- type: 'uid',
13
- name: 'name',
14
- primaryKey: true,
15
- prefix: 'a',
16
- interface: 'input',
17
- uiSchema: {
18
- type: 'string',
19
- title: '{{t("Application name")}}',
20
- 'x-component': 'Input',
21
- 'x-read-pretty': true,
22
- },
23
- },
24
- {
25
- type: 'json',
26
- name: 'options',
27
- },
28
- ],
29
- });
30
- //# 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,SAAS,EAAE,IAAI;IACf,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,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 createdBy: true,\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: 'json',\n name: 'options',\n },\n ],\n});\n"]}
package/esm/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { PluginMultiAppManager as default } from './server';
package/esm/index.js DELETED
@@ -1,2 +0,0 @@
1
- export { PluginMultiAppManager as default } from './server';
2
- //# 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,qBAAqB,IAAI,OAAO,EAAE,MAAM,UAAU,CAAC","sourcesContent":["export { PluginMultiAppManager as default } from './server';\n"]}
@@ -1,13 +0,0 @@
1
- import { IDatabaseOptions, Model, TransactionAble } from '@nocobase/database';
2
- import { Application } from '@nocobase/server';
3
- interface registerAppOptions extends TransactionAble {
4
- skipInstall?: boolean;
5
- }
6
- export declare class ApplicationModel extends Model {
7
- static getDatabaseConfig(app: Application): IDatabaseOptions;
8
- registerToMainApp(mainApp: Application, options: registerAppOptions): Promise<void>;
9
- static initOptions(appName: string, mainApp: Application): {
10
- database: IDatabaseOptions;
11
- };
12
- }
13
- export {};
@@ -1,75 +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
- registerToMainApp(mainApp, options) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- const { transaction } = options;
22
- const appName = this.get('name');
23
- const appOptions = this.get('options') || {};
24
- const app = mainApp.appManager.createApplication(appName, Object.assign(Object.assign({}, ApplicationModel.initOptions(appName, mainApp)), appOptions));
25
- app.on('beforeInstall', function createDatabase() {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const { host, port, username, password, database, dialect } = ApplicationModel.getDatabaseConfig(app);
28
- if (dialect === 'mysql') {
29
- const mysql = require('mysql2/promise');
30
- const connection = yield mysql.createConnection({ host, port, user: username, password });
31
- yield connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
32
- yield connection.close();
33
- }
34
- if (dialect === 'postgres') {
35
- const { Client } = require('pg');
36
- const client = new Client({
37
- user: username,
38
- host,
39
- password: password,
40
- port,
41
- });
42
- yield client.connect();
43
- try {
44
- yield client.query(`CREATE DATABASE "${database}"`);
45
- }
46
- catch (e) { }
47
- yield client.end();
48
- }
49
- });
50
- });
51
- yield app.load();
52
- if (!lodash.get(options, 'skipInstall', false)) {
53
- yield app.install();
54
- }
55
- yield app.start();
56
- });
57
- }
58
- static initOptions(appName, mainApp) {
59
- const rawDatabaseOptions = ApplicationModel.getDatabaseConfig(mainApp);
60
- if (rawDatabaseOptions.dialect === 'sqlite') {
61
- const mainAppStorage = rawDatabaseOptions.storage;
62
- if (mainAppStorage !== ':memory:') {
63
- const mainStorageDir = path.dirname(mainAppStorage);
64
- rawDatabaseOptions.storage = path.join(mainStorageDir, `${appName}.sqlite`);
65
- }
66
- }
67
- else {
68
- rawDatabaseOptions.database = appName;
69
- }
70
- return {
71
- database: rawDatabaseOptions,
72
- };
73
- }
74
- }
75
- //# sourceMappingURL=application.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"application.js","sourceRoot":"","sources":["../../src/models/application.ts"],"names":[],"mappings":"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","sourcesContent":["import Database, { IDatabaseOptions, Model, TransactionAble } from '@nocobase/database';\nimport { Application } from '@nocobase/server';\nimport lodash from 'lodash';\nimport * as path from 'path';\n\ninterface 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 async registerToMainApp(mainApp: Application, options: registerAppOptions) {\n const { transaction } = options;\n const appName = this.get('name') as string;\n const appOptions = (this.get('options') as any) || {};\n\n const app = mainApp.appManager.createApplication(appName, {\n ...ApplicationModel.initOptions(appName, mainApp),\n ...appOptions,\n });\n\n app.on('beforeInstall', async function createDatabase() {\n const { host, port, username, password, database, dialect } = ApplicationModel.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 app.load();\n\n if (!lodash.get(options, 'skipInstall', false)) {\n await app.install();\n }\n\n await app.start();\n }\n\n static initOptions(appName: string, mainApp: Application) {\n const rawDatabaseOptions = ApplicationModel.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,5 +0,0 @@
1
- import { Plugin } from '@nocobase/server';
2
- export declare class PluginMultiAppManager extends Plugin {
3
- getName(): string;
4
- load(): Promise<void>;
5
- }
package/esm/server.js DELETED
@@ -1,49 +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
- load() {
18
- return __awaiter(this, void 0, void 0, function* () {
19
- this.db.registerModels({
20
- ApplicationModel,
21
- });
22
- yield this.db.import({
23
- directory: resolve(__dirname, 'collections'),
24
- });
25
- this.db.on('applications.afterCreateWithAssociations', (model, options) => __awaiter(this, void 0, void 0, function* () {
26
- const { transaction } = options;
27
- yield model.registerToMainApp(this.app, { transaction });
28
- }));
29
- this.db.on('applications.afterDestroy', (model) => __awaiter(this, void 0, void 0, function* () {
30
- yield this.app.appManager.removeApplication(model.get('name'));
31
- }));
32
- this.app.appManager.on('beforeGetApplication', function lazyLoadApplication({ appManager, name }) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- if (!appManager.applications.has(name)) {
35
- const existsApplication = (yield this.app.db.getRepository('applications').findOne({
36
- filter: {
37
- name,
38
- },
39
- }));
40
- if (existsApplication) {
41
- yield existsApplication.registerToMainApp(this.app, { skipInstall: true });
42
- }
43
- }
44
- });
45
- });
46
- });
47
- }
48
- }
49
- //# 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,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD,MAAM,OAAO,qBAAsB,SAAQ,MAAM;IAC/C,OAAO;QACL,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;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;gBAChC,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 { Plugin } from '@nocobase/server';\nimport { resolve } from 'path';\nimport { ApplicationModel } from './models/application';\nimport { AppManager } from '@nocobase/server';\n\nexport class PluginMultiAppManager extends Plugin {\n getName(): string {\n return this.getPackageName(__dirname);\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 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,SAAS,EAAE,IAAI;IACf,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,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 createdBy: true,\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: '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,mCAA4D;AAAnD,iGAAA,qBAAqB,OAAW","sourcesContent":["export { PluginMultiAppManager as default } from './server';\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,CAAC;IAEK,iBAAiB,CAAC,OAAoB,EAAE,OAA2B;;YACvE,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;YAChC,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,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAC,OAAO,kCACnD,gBAAgB,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,GAC9C,UAAU,EACb,CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,eAAe,EAAE,SAAe,cAAc;;oBACnD,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;oBAEtG,IAAI,OAAO,KAAK,OAAO,EAAE;wBACvB,MAAM,KAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;wBACxC,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC;wBAC1F,MAAM,UAAU,CAAC,KAAK,CAAC,mCAAmC,QAAQ,KAAK,CAAC,CAAC;wBACzE,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;qBAC1B;oBAED,IAAI,OAAO,KAAK,UAAU,EAAE;wBAC1B,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;wBAEjC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;4BACxB,IAAI,EAAE,QAAQ;4BACd,IAAI;4BACJ,QAAQ,EAAE,QAAQ;4BAClB,IAAI;yBACL,CAAC,CAAC;wBAEH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;wBAEvB,IAAI;4BACF,MAAM,MAAM,CAAC,KAAK,CAAC,oBAAoB,QAAQ,GAAG,CAAC,CAAC;yBACrD;wBAAC,OAAO,CAAC,EAAE,GAAE;wBAEd,MAAM,MAAM,CAAC,GAAG,EAAE,CAAC;qBACpB;gBACH,CAAC;aAAA,CAAC,CAAC;YAEH,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YAEjB,IAAI,CAAC,gBAAM,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;IAED,MAAM,CAAC,WAAW,CAAC,OAAe,EAAE,OAAoB;QACtD,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAEvE,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;AA3ED,4CA2EC","sourcesContent":["import Database, { IDatabaseOptions, Model, TransactionAble } from '@nocobase/database';\nimport { Application } from '@nocobase/server';\nimport lodash from 'lodash';\nimport * as path from 'path';\n\ninterface 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 async registerToMainApp(mainApp: Application, options: registerAppOptions) {\n const { transaction } = options;\n const appName = this.get('name') as string;\n const appOptions = (this.get('options') as any) || {};\n\n const app = mainApp.appManager.createApplication(appName, {\n ...ApplicationModel.initOptions(appName, mainApp),\n ...appOptions,\n });\n\n app.on('beforeInstall', async function createDatabase() {\n const { host, port, username, password, database, dialect } = ApplicationModel.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 app.load();\n\n if (!lodash.get(options, 'skipInstall', false)) {\n await app.install();\n }\n\n await app.start();\n }\n\n static initOptions(appName: string, mainApp: Application) {\n const rawDatabaseOptions = ApplicationModel.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,6CAA0C;AAC1C,+BAA+B;AAC/B,sDAAwD;AAGxD,MAAa,qBAAsB,SAAQ,eAAM;IAC/C,OAAO;QACL,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;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;gBAChC,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;AAxCD,sDAwCC","sourcesContent":["import { Plugin } from '@nocobase/server';\nimport { resolve } from 'path';\nimport { ApplicationModel } from './models/application';\nimport { AppManager } from '@nocobase/server';\n\nexport class PluginMultiAppManager extends Plugin {\n getName(): string {\n return this.getPackageName(__dirname);\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 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
- }