@nocobase/plugin-multi-app-manager 0.9.0-alpha.2 → 0.9.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/README.zh-CN.md +13 -0
- package/lib/collections/applications.js +2 -0
- package/lib/models/application.d.ts +5 -45
- package/lib/models/application.js +30 -107
- package/lib/server.d.ts +10 -1
- package/lib/server.js +152 -20
- package/package.json +3 -3
package/README.md
ADDED
package/README.zh-CN.md
ADDED
|
@@ -1,52 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Model, Transactionable } from '@nocobase/database';
|
|
2
2
|
import { Application } from '@nocobase/server';
|
|
3
|
+
import { AppDbCreator, AppOptionsFactory } from '../server';
|
|
3
4
|
export interface registerAppOptions extends Transactionable {
|
|
4
5
|
skipInstall?: boolean;
|
|
6
|
+
dbCreator: AppDbCreator;
|
|
7
|
+
appOptionsFactory: AppOptionsFactory;
|
|
5
8
|
}
|
|
6
9
|
export declare class ApplicationModel extends Model {
|
|
7
|
-
static
|
|
8
|
-
static handleAppStart(app: Application, options: registerAppOptions): Promise<void>;
|
|
10
|
+
static handleAppStart(mainApp: Application, app: Application, options: registerAppOptions): Promise<void>;
|
|
9
11
|
registerToMainApp(mainApp: Application, options: registerAppOptions): Promise<void>;
|
|
10
|
-
static initOptions(appName: string, mainApp: Application): {
|
|
11
|
-
database: {
|
|
12
|
-
tablePrefix: string;
|
|
13
|
-
migrator?: any;
|
|
14
|
-
usingBigIntForId?: boolean;
|
|
15
|
-
dialect?: import("sequelize").Dialect;
|
|
16
|
-
dialectModule?: object;
|
|
17
|
-
dialectModulePath?: string;
|
|
18
|
-
dialectOptions?: object;
|
|
19
|
-
storage?: string;
|
|
20
|
-
database?: string;
|
|
21
|
-
username?: string;
|
|
22
|
-
password?: string;
|
|
23
|
-
host?: string;
|
|
24
|
-
port?: number;
|
|
25
|
-
ssl?: boolean;
|
|
26
|
-
protocol?: string;
|
|
27
|
-
define?: import("sequelize").ModelOptions<import("sequelize").Model<any, any>>;
|
|
28
|
-
query?: import("sequelize").QueryOptions;
|
|
29
|
-
set?: import("sequelize").DefaultSetOptions;
|
|
30
|
-
sync?: import("@nocobase/database").SyncOptions;
|
|
31
|
-
timezone?: string;
|
|
32
|
-
omitNull?: boolean;
|
|
33
|
-
native?: boolean;
|
|
34
|
-
replication?: false | import("sequelize").ReplicationOptions;
|
|
35
|
-
pool?: import("sequelize").PoolOptions;
|
|
36
|
-
quoteIdentifiers?: boolean;
|
|
37
|
-
isolationLevel?: string;
|
|
38
|
-
transactionType?: import("sequelize").Transaction.TYPES;
|
|
39
|
-
typeValidation?: boolean;
|
|
40
|
-
operatorsAliases?: import("sequelize").OperatorsAliases;
|
|
41
|
-
standardConformingStrings?: boolean;
|
|
42
|
-
clientMinMessages?: string | boolean;
|
|
43
|
-
hooks?: Partial<import("sequelize/types/hooks").SequelizeHooks<import("sequelize").Model<any, any>, any, any>>;
|
|
44
|
-
minifyAliases?: boolean;
|
|
45
|
-
logQueryParameters?: boolean;
|
|
46
|
-
retry?: import("sequelize").RetryOptions;
|
|
47
|
-
schema?: string;
|
|
48
|
-
logging?: boolean | ((sql: string, timing?: number) => void);
|
|
49
|
-
benchmark?: boolean;
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
12
|
}
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.ApplicationModel = void 0;
|
|
7
7
|
|
|
8
8
|
function _database() {
|
|
9
|
-
const data =
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
10
|
|
|
11
11
|
_database = function _database() {
|
|
12
12
|
return data;
|
|
@@ -15,32 +15,6 @@ function _database() {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
|
-
|
|
40
|
-
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); }
|
|
41
|
-
|
|
42
|
-
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; }
|
|
43
|
-
|
|
44
18
|
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
19
|
|
|
46
20
|
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; }
|
|
@@ -52,17 +26,23 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
52
26
|
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
27
|
|
|
54
28
|
class ApplicationModel extends _database().Model {
|
|
55
|
-
static
|
|
56
|
-
const oldConfig = app.options.database instanceof _database().default ? app.options.database.options : app.options.database;
|
|
57
|
-
return _lodash().default.cloneDeep(_lodash().default.omit(oldConfig, ['migrator']));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
static handleAppStart(app, options) {
|
|
29
|
+
static handleAppStart(mainApp, app, options) {
|
|
61
30
|
return _asyncToGenerator(function* () {
|
|
31
|
+
yield mainApp.emitAsync('beforeSubAppLoad', {
|
|
32
|
+
mainApp,
|
|
33
|
+
subApp: app
|
|
34
|
+
});
|
|
62
35
|
yield app.load();
|
|
63
36
|
|
|
64
|
-
if (!(
|
|
65
|
-
yield app.
|
|
37
|
+
if (!(yield app.isInstalled())) {
|
|
38
|
+
yield app.db.sync();
|
|
39
|
+
yield app.install(); // emit an event on mainApp
|
|
40
|
+
// current if you add listener on subApp through `subApp.on('afterInstall')` , it will be clear after subApp installed
|
|
41
|
+
|
|
42
|
+
yield mainApp.emitAsync('afterSubAppInstalled', {
|
|
43
|
+
mainApp,
|
|
44
|
+
subApp: app
|
|
45
|
+
});
|
|
66
46
|
}
|
|
67
47
|
|
|
68
48
|
yield app.start();
|
|
@@ -77,62 +57,26 @@ class ApplicationModel extends _database().Model {
|
|
|
77
57
|
|
|
78
58
|
const appOptions = _this.get('options') || {};
|
|
79
59
|
const AppModel = _this.constructor;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
dialect = _mainApp$db$options.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
|
|
99
|
-
});
|
|
100
|
-
yield connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
|
|
101
|
-
yield connection.close();
|
|
60
|
+
const app = mainApp.appManager.createApplication(appName, _objectSpread(_objectSpread(_objectSpread({}, options.appOptionsFactory(appName, mainApp)), appOptions), {}, {
|
|
61
|
+
name: appName
|
|
62
|
+
}));
|
|
63
|
+
const isInstalled = yield _asyncToGenerator(function* () {
|
|
64
|
+
try {
|
|
65
|
+
return yield app.isInstalled();
|
|
66
|
+
} catch (e) {
|
|
67
|
+
if (e.message.includes('does not exist') || e.message.includes('Unknown database')) {
|
|
68
|
+
return false;
|
|
102
69
|
}
|
|
103
70
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const client = new Client({
|
|
109
|
-
host,
|
|
110
|
-
port,
|
|
111
|
-
user: username,
|
|
112
|
-
password,
|
|
113
|
-
database: 'postgres'
|
|
114
|
-
});
|
|
115
|
-
yield client.connect();
|
|
71
|
+
throw e;
|
|
72
|
+
}
|
|
73
|
+
})();
|
|
116
74
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
} catch (e) {}
|
|
120
|
-
|
|
121
|
-
yield client.end();
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
return function createDatabase() {
|
|
126
|
-
return _ref.apply(this, arguments);
|
|
127
|
-
};
|
|
128
|
-
}();
|
|
129
|
-
|
|
130
|
-
if (!(options === null || options === void 0 ? void 0 : options.skipInstall)) {
|
|
131
|
-
yield createDatabase();
|
|
75
|
+
if (!isInstalled) {
|
|
76
|
+
yield options.dbCreator(app);
|
|
132
77
|
}
|
|
133
78
|
|
|
134
|
-
|
|
135
|
-
yield AppModel.handleAppStart(app, options);
|
|
79
|
+
yield AppModel.handleAppStart(mainApp, app, options);
|
|
136
80
|
yield AppModel.update({
|
|
137
81
|
status: 'running'
|
|
138
82
|
}, {
|
|
@@ -145,27 +89,6 @@ class ApplicationModel extends _database().Model {
|
|
|
145
89
|
})();
|
|
146
90
|
}
|
|
147
91
|
|
|
148
|
-
static initOptions(appName, mainApp) {
|
|
149
|
-
const rawDatabaseOptions = this.getDatabaseConfig(mainApp);
|
|
150
|
-
|
|
151
|
-
if (rawDatabaseOptions.dialect === 'sqlite') {
|
|
152
|
-
const mainAppStorage = rawDatabaseOptions.storage;
|
|
153
|
-
|
|
154
|
-
if (mainAppStorage !== ':memory:') {
|
|
155
|
-
const mainStorageDir = path().dirname(mainAppStorage);
|
|
156
|
-
rawDatabaseOptions.storage = path().join(mainStorageDir, `${appName}.sqlite`);
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
rawDatabaseOptions.database = appName;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
database: _objectSpread(_objectSpread({}, rawDatabaseOptions), {}, {
|
|
164
|
-
tablePrefix: ''
|
|
165
|
-
})
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
92
|
}
|
|
170
93
|
|
|
171
94
|
exports.ApplicationModel = ApplicationModel;
|
package/lib/server.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import { InstallOptions, Plugin } from '@nocobase/server';
|
|
1
|
+
import Application, { InstallOptions, Plugin } from '@nocobase/server';
|
|
2
|
+
import { IDatabaseOptions } from '@nocobase/database';
|
|
3
|
+
export declare type AppDbCreator = (app: Application) => Promise<void>;
|
|
4
|
+
export declare type AppOptionsFactory = (appName: string, mainApp: Application) => any;
|
|
2
5
|
export declare class PluginMultiAppManager extends Plugin {
|
|
6
|
+
appDbCreator: AppDbCreator;
|
|
7
|
+
appOptionsFactory: AppOptionsFactory;
|
|
8
|
+
setAppOptionsFactory(factory: AppOptionsFactory): void;
|
|
9
|
+
setAppDbCreator(appDbCreator: AppDbCreator): void;
|
|
10
|
+
static getDatabaseConfig(app: Application): IDatabaseOptions;
|
|
3
11
|
install(options?: InstallOptions): Promise<void>;
|
|
12
|
+
beforeLoad(): void;
|
|
4
13
|
load(): Promise<void>;
|
|
5
14
|
}
|
package/lib/server.js
CHANGED
|
@@ -15,10 +15,10 @@ function _server() {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function
|
|
19
|
-
const data = require("path");
|
|
18
|
+
function path() {
|
|
19
|
+
const data = _interopRequireWildcard(require("path"));
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
path = function path() {
|
|
22
22
|
return data;
|
|
23
23
|
};
|
|
24
24
|
|
|
@@ -27,11 +27,136 @@ function _path() {
|
|
|
27
27
|
|
|
28
28
|
var _application = require("./models/application");
|
|
29
29
|
|
|
30
|
+
function _database() {
|
|
31
|
+
const data = _interopRequireDefault(require("@nocobase/database"));
|
|
32
|
+
|
|
33
|
+
_database = function _database() {
|
|
34
|
+
return data;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return data;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function _lodash() {
|
|
41
|
+
const data = _interopRequireDefault(require("lodash"));
|
|
42
|
+
|
|
43
|
+
_lodash = function _lodash() {
|
|
44
|
+
return data;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return data;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
51
|
+
|
|
52
|
+
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); }
|
|
53
|
+
|
|
54
|
+
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; }
|
|
55
|
+
|
|
56
|
+
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; }
|
|
57
|
+
|
|
58
|
+
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; }
|
|
59
|
+
|
|
60
|
+
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; }
|
|
61
|
+
|
|
30
62
|
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
63
|
|
|
32
64
|
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
65
|
|
|
66
|
+
const defaultDbCreator = /*#__PURE__*/function () {
|
|
67
|
+
var _ref = _asyncToGenerator(function* (app) {
|
|
68
|
+
const databaseOptions = app.options.database;
|
|
69
|
+
const host = databaseOptions.host,
|
|
70
|
+
port = databaseOptions.port,
|
|
71
|
+
username = databaseOptions.username,
|
|
72
|
+
password = databaseOptions.password,
|
|
73
|
+
dialect = databaseOptions.dialect,
|
|
74
|
+
database = databaseOptions.database;
|
|
75
|
+
|
|
76
|
+
if (dialect === 'mysql') {
|
|
77
|
+
const mysql = require('mysql2/promise');
|
|
78
|
+
|
|
79
|
+
const connection = yield mysql.createConnection({
|
|
80
|
+
host,
|
|
81
|
+
port,
|
|
82
|
+
user: username,
|
|
83
|
+
password
|
|
84
|
+
});
|
|
85
|
+
yield connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
|
|
86
|
+
yield connection.close();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (dialect === 'postgres') {
|
|
90
|
+
const _require = require('pg'),
|
|
91
|
+
Client = _require.Client;
|
|
92
|
+
|
|
93
|
+
const client = new Client({
|
|
94
|
+
host,
|
|
95
|
+
port,
|
|
96
|
+
user: username,
|
|
97
|
+
password,
|
|
98
|
+
database: 'postgres'
|
|
99
|
+
});
|
|
100
|
+
yield client.connect();
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
yield client.query(`CREATE DATABASE "${database}"`);
|
|
104
|
+
} catch (e) {}
|
|
105
|
+
|
|
106
|
+
yield client.end();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return function defaultDbCreator(_x) {
|
|
111
|
+
return _ref.apply(this, arguments);
|
|
112
|
+
};
|
|
113
|
+
}();
|
|
114
|
+
|
|
115
|
+
const defaultAppOptionsFactory = (appName, mainApp) => {
|
|
116
|
+
const rawDatabaseOptions = PluginMultiAppManager.getDatabaseConfig(mainApp);
|
|
117
|
+
|
|
118
|
+
if (rawDatabaseOptions.dialect === 'sqlite') {
|
|
119
|
+
const mainAppStorage = rawDatabaseOptions.storage;
|
|
120
|
+
|
|
121
|
+
if (mainAppStorage !== ':memory:') {
|
|
122
|
+
const mainStorageDir = path().dirname(mainAppStorage);
|
|
123
|
+
rawDatabaseOptions.storage = path().join(mainStorageDir, `${appName}.sqlite`);
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
rawDatabaseOptions.database = appName;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
database: _objectSpread(_objectSpread({}, rawDatabaseOptions), {}, {
|
|
131
|
+
tablePrefix: ''
|
|
132
|
+
}),
|
|
133
|
+
plugins: ['nocobase'],
|
|
134
|
+
resourcer: {
|
|
135
|
+
prefix: '/api'
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
34
140
|
class PluginMultiAppManager extends _server().Plugin {
|
|
141
|
+
constructor(...args) {
|
|
142
|
+
super(...args);
|
|
143
|
+
this.appDbCreator = defaultDbCreator;
|
|
144
|
+
this.appOptionsFactory = defaultAppOptionsFactory;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
setAppOptionsFactory(factory) {
|
|
148
|
+
this.appOptionsFactory = factory;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
setAppDbCreator(appDbCreator) {
|
|
152
|
+
this.appDbCreator = appDbCreator;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
static getDatabaseConfig(app) {
|
|
156
|
+
const oldConfig = app.options.database instanceof _database().default ? app.options.database.options : app.options.database;
|
|
157
|
+
return _lodash().default.cloneDeep(_lodash().default.omit(oldConfig, ['migrator']));
|
|
158
|
+
}
|
|
159
|
+
|
|
35
160
|
install(options) {
|
|
36
161
|
var _this = this;
|
|
37
162
|
|
|
@@ -44,6 +169,12 @@ class PluginMultiAppManager extends _server().Plugin {
|
|
|
44
169
|
})();
|
|
45
170
|
}
|
|
46
171
|
|
|
172
|
+
beforeLoad() {
|
|
173
|
+
this.app.appManager.setAppSelector(req => {
|
|
174
|
+
return req.headers['x-app'] || null;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
47
178
|
load() {
|
|
48
179
|
var _this2 = this;
|
|
49
180
|
|
|
@@ -53,57 +184,58 @@ class PluginMultiAppManager extends _server().Plugin {
|
|
|
53
184
|
});
|
|
54
185
|
|
|
55
186
|
yield _this2.db.import({
|
|
56
|
-
directory: (0,
|
|
187
|
+
directory: (0, path().resolve)(__dirname, 'collections')
|
|
57
188
|
});
|
|
58
189
|
|
|
59
190
|
_this2.db.on('applications.afterCreateWithAssociations', /*#__PURE__*/function () {
|
|
60
|
-
var
|
|
191
|
+
var _ref2 = _asyncToGenerator(function* (model, options) {
|
|
61
192
|
const transaction = options.transaction;
|
|
62
193
|
yield model.registerToMainApp(_this2.app, {
|
|
63
|
-
transaction
|
|
194
|
+
transaction,
|
|
195
|
+
dbCreator: _this2.appDbCreator,
|
|
196
|
+
appOptionsFactory: _this2.appOptionsFactory
|
|
64
197
|
});
|
|
65
198
|
});
|
|
66
199
|
|
|
67
|
-
return function (
|
|
68
|
-
return
|
|
200
|
+
return function (_x2, _x3) {
|
|
201
|
+
return _ref2.apply(this, arguments);
|
|
69
202
|
};
|
|
70
203
|
}());
|
|
71
204
|
|
|
72
205
|
_this2.db.on('applications.afterDestroy', /*#__PURE__*/function () {
|
|
73
|
-
var
|
|
206
|
+
var _ref3 = _asyncToGenerator(function* (model) {
|
|
74
207
|
yield _this2.app.appManager.removeApplication(model.get('name'));
|
|
75
208
|
});
|
|
76
209
|
|
|
77
|
-
return function (
|
|
78
|
-
return
|
|
210
|
+
return function (_x4) {
|
|
211
|
+
return _ref3.apply(this, arguments);
|
|
79
212
|
};
|
|
80
213
|
}());
|
|
81
214
|
|
|
82
215
|
_this2.app.appManager.on('beforeGetApplication', /*#__PURE__*/function () {
|
|
83
|
-
var
|
|
216
|
+
var _ref4 = _asyncToGenerator(function* ({
|
|
84
217
|
appManager,
|
|
85
218
|
name
|
|
86
219
|
}) {
|
|
87
220
|
if (!appManager.applications.has(name)) {
|
|
88
|
-
const existsApplication = yield
|
|
221
|
+
const existsApplication = yield _this2.app.db.getRepository('applications').findOne({
|
|
89
222
|
filter: {
|
|
90
223
|
name
|
|
91
224
|
}
|
|
92
225
|
});
|
|
93
226
|
|
|
94
227
|
if (existsApplication) {
|
|
95
|
-
yield existsApplication.registerToMainApp(
|
|
96
|
-
|
|
228
|
+
yield existsApplication.registerToMainApp(_this2.app, {
|
|
229
|
+
dbCreator: _this2.appDbCreator,
|
|
230
|
+
appOptionsFactory: _this2.appOptionsFactory
|
|
97
231
|
});
|
|
98
232
|
}
|
|
99
233
|
}
|
|
100
234
|
});
|
|
101
235
|
|
|
102
|
-
function
|
|
103
|
-
return
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return lazyLoadApplication;
|
|
236
|
+
return function (_x5) {
|
|
237
|
+
return _ref4.apply(this, arguments);
|
|
238
|
+
};
|
|
107
239
|
}());
|
|
108
240
|
|
|
109
241
|
_this2.app.acl.registerSnippet({
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-multi-app-manager",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/server": "0.9.
|
|
9
|
+
"@nocobase/server": "0.9.1-alpha.1"
|
|
10
10
|
},
|
|
11
|
-
"gitHead": "
|
|
11
|
+
"gitHead": "56cb184b00dc383b853015d525bf6e79dea92169"
|
|
12
12
|
}
|