@tachybase/module-multi-app 0.23.8
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/.turbo/turbo-build.log +14 -0
- package/README.md +34 -0
- package/README.zh-CN.md +34 -0
- package/client.d.ts +1 -0
- package/client.js +1 -0
- package/dist/client/AppManager.d.ts +2 -0
- package/dist/client/AppNameInput.d.ts +2 -0
- package/dist/client/MultiAppBlockInitializer.d.ts +2 -0
- package/dist/client/MultiAppManagerProvider.d.ts +2 -0
- package/dist/client/MultiAppManagerProvider.style.d.ts +5 -0
- package/dist/client/Settings.d.ts +2 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.js +1 -0
- package/dist/client/settings/schemas/applications.d.ts +13 -0
- package/dist/client/utils.d.ts +4 -0
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +27 -0
- package/dist/externalVersion.js +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +27 -0
- package/dist/locale/es-ES.json +9 -0
- package/dist/locale/ko_KR.json +11 -0
- package/dist/locale/pt-BR.json +9 -0
- package/dist/locale/zh-CN.json +27 -0
- package/dist/node_modules/mariadb/LICENSE +502 -0
- package/dist/node_modules/mariadb/callback.js +41 -0
- package/dist/node_modules/mariadb/lib/cmd/batch-bulk.js +278 -0
- package/dist/node_modules/mariadb/lib/cmd/batch-rewrite.js +372 -0
- package/dist/node_modules/mariadb/lib/cmd/change-user.js +149 -0
- package/dist/node_modules/mariadb/lib/cmd/class/ok-packet.js +17 -0
- package/dist/node_modules/mariadb/lib/cmd/column-definition.js +102 -0
- package/dist/node_modules/mariadb/lib/cmd/command.js +168 -0
- package/dist/node_modules/mariadb/lib/cmd/common-binary-cmd.js +327 -0
- package/dist/node_modules/mariadb/lib/cmd/common-text-cmd.js +427 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/caching-sha2-password-auth.js +168 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/clear-password-auth.js +23 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/ed25519-password-auth.js +761 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/native-password-auth.js +55 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/pam-password-auth.js +58 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/plugin-auth.js +19 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/auth/sha256-password-auth.js +142 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-capabilities.js +74 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/client-handshake-response.js +126 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/handshake.js +292 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/initial-handshake.js +74 -0
- package/dist/node_modules/mariadb/lib/cmd/handshake/ssl-request.js +29 -0
- package/dist/node_modules/mariadb/lib/cmd/ping.js +52 -0
- package/dist/node_modules/mariadb/lib/cmd/query.js +255 -0
- package/dist/node_modules/mariadb/lib/cmd/quit.js +28 -0
- package/dist/node_modules/mariadb/lib/cmd/reset.js +54 -0
- package/dist/node_modules/mariadb/lib/cmd/resultset.js +607 -0
- package/dist/node_modules/mariadb/lib/cmd/stream.js +45 -0
- package/dist/node_modules/mariadb/lib/config/connection-options.js +258 -0
- package/dist/node_modules/mariadb/lib/config/pool-cluster-options.js +19 -0
- package/dist/node_modules/mariadb/lib/config/pool-options.js +47 -0
- package/dist/node_modules/mariadb/lib/connection-callback.js +160 -0
- package/dist/node_modules/mariadb/lib/connection.js +1460 -0
- package/dist/node_modules/mariadb/lib/const/capabilities.js +64 -0
- package/dist/node_modules/mariadb/lib/const/collations.js +473 -0
- package/dist/node_modules/mariadb/lib/const/connection_status.js +13 -0
- package/dist/node_modules/mariadb/lib/const/error-code.js +1282 -0
- package/dist/node_modules/mariadb/lib/const/field-detail.js +35 -0
- package/dist/node_modules/mariadb/lib/const/field-type.js +71 -0
- package/dist/node_modules/mariadb/lib/const/server-status.js +30 -0
- package/dist/node_modules/mariadb/lib/const/state-change.js +12 -0
- package/dist/node_modules/mariadb/lib/filtered-pool-cluster.js +81 -0
- package/dist/node_modules/mariadb/lib/io/bulk-packet.js +590 -0
- package/dist/node_modules/mariadb/lib/io/compression-input-stream.js +141 -0
- package/dist/node_modules/mariadb/lib/io/compression-output-stream.js +171 -0
- package/dist/node_modules/mariadb/lib/io/packet-input-stream.js +193 -0
- package/dist/node_modules/mariadb/lib/io/packet-node-encoded.js +36 -0
- package/dist/node_modules/mariadb/lib/io/packet-node-iconv.js +37 -0
- package/dist/node_modules/mariadb/lib/io/packet-output-stream.js +502 -0
- package/dist/node_modules/mariadb/lib/io/packet.js +515 -0
- package/dist/node_modules/mariadb/lib/io/rewrite-packet.js +481 -0
- package/dist/node_modules/mariadb/lib/misc/connection-information.js +96 -0
- package/dist/node_modules/mariadb/lib/misc/errors.js +123 -0
- package/dist/node_modules/mariadb/lib/misc/parse.js +1033 -0
- package/dist/node_modules/mariadb/lib/misc/utils.js +298 -0
- package/dist/node_modules/mariadb/lib/pool-base.js +611 -0
- package/dist/node_modules/mariadb/lib/pool-callback.js +202 -0
- package/dist/node_modules/mariadb/lib/pool-cluster-callback.js +66 -0
- package/dist/node_modules/mariadb/lib/pool-cluster.js +407 -0
- package/dist/node_modules/mariadb/lib/pool-promise.js +108 -0
- package/dist/node_modules/mariadb/package.json +1 -0
- package/dist/node_modules/mariadb/promise.js +34 -0
- package/dist/node_modules/mariadb/types/index.d.ts +870 -0
- package/dist/server/actions/apps.d.ts +5 -0
- package/dist/server/actions/apps.js +117 -0
- package/dist/server/app-lifecycle.d.ts +8 -0
- package/dist/server/app-lifecycle.js +99 -0
- package/dist/server/app-start-env.d.ts +2 -0
- package/dist/server/app-start-env.js +105 -0
- package/dist/server/collections/applications.d.ts +2 -0
- package/dist/server/collections/applications.js +82 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js +29 -0
- package/dist/server/middlewares/app-selector.d.ts +1 -0
- package/dist/server/middlewares/app-selector.js +47 -0
- package/dist/server/middlewares/index.d.ts +2 -0
- package/dist/server/middlewares/index.js +23 -0
- package/dist/server/middlewares/inject-app-list.d.ts +1 -0
- package/dist/server/middlewares/inject-app-list.js +48 -0
- package/dist/server/migrations/20240820153000-add-apps-tmpl.d.ts +6 -0
- package/dist/server/migrations/20240820153000-add-apps-tmpl.js +47 -0
- package/dist/server/migrations/20241126124904-add-createdBy.d.ts +6 -0
- package/dist/server/migrations/20241126124904-add-createdBy.js +41 -0
- package/dist/server/models/application.d.ts +10 -0
- package/dist/server/models/application.js +57 -0
- package/dist/server/server.d.ts +19 -0
- package/dist/server/server.js +246 -0
- package/dist/swagger/index.d.ts +197 -0
- package/dist/swagger/index.js +227 -0
- package/package.json +38 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var add_createdBy_exports = {};
|
|
19
|
+
__export(add_createdBy_exports, {
|
|
20
|
+
default: () => add_createdBy_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(add_createdBy_exports);
|
|
23
|
+
var import_server = require("@tachybase/server");
|
|
24
|
+
class add_createdBy_default extends import_server.Migration {
|
|
25
|
+
on = "afterLoad";
|
|
26
|
+
// 'beforeLoad' or 'afterLoad'
|
|
27
|
+
appVersion = "<0.22.47";
|
|
28
|
+
async up() {
|
|
29
|
+
const userRepo = this.context.db.getRepository("users");
|
|
30
|
+
const appRepo = this.context.db.getRepository("applications");
|
|
31
|
+
const rootUser = await userRepo.findOne({ filter: { specialRole: "root" }, raw: true });
|
|
32
|
+
const { id } = rootUser;
|
|
33
|
+
const result = await appRepo.update({
|
|
34
|
+
filter: {
|
|
35
|
+
createdById: null
|
|
36
|
+
},
|
|
37
|
+
values: { createdById: id, updateById: id }
|
|
38
|
+
});
|
|
39
|
+
console.log("[applications] add createdBy", result.length, "rows");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Model, Transactionable } from '@tachybase/database';
|
|
2
|
+
import { Application } from '@tachybase/server';
|
|
3
|
+
import { AppOptionsFactory } from '../server';
|
|
4
|
+
export interface registerAppOptions extends Transactionable {
|
|
5
|
+
skipInstall?: boolean;
|
|
6
|
+
appOptionsFactory: AppOptionsFactory;
|
|
7
|
+
}
|
|
8
|
+
export declare class ApplicationModel extends Model {
|
|
9
|
+
registerToSupervisor(mainApp: Application, options: registerAppOptions): Application<import("@tachybase/server").DefaultState, import("@tachybase/server").DefaultContext>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var application_exports = {};
|
|
29
|
+
__export(application_exports, {
|
|
30
|
+
ApplicationModel: () => ApplicationModel
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(application_exports);
|
|
33
|
+
var import_database = require("@tachybase/database");
|
|
34
|
+
var import_server = require("@tachybase/server");
|
|
35
|
+
var import_utils = require("@tachybase/utils");
|
|
36
|
+
var import_app_start_env = __toESM(require("../app-start-env"));
|
|
37
|
+
class ApplicationModel extends import_database.Model {
|
|
38
|
+
registerToSupervisor(mainApp, options) {
|
|
39
|
+
const appName = this.get("name");
|
|
40
|
+
const preset = this.get("preset");
|
|
41
|
+
const tmpl = this.get("tmpl");
|
|
42
|
+
const appModelOptions = this.get("options") || {};
|
|
43
|
+
const startEnvs = appModelOptions.startEnvs || {};
|
|
44
|
+
let appOptions = options.appOptionsFactory(appName, mainApp, preset);
|
|
45
|
+
appOptions = (0, import_app_start_env.default)(appName, mainApp, appOptions, startEnvs);
|
|
46
|
+
const subAppOptions = {
|
|
47
|
+
...(0, import_utils.merge)(appOptions, appModelOptions),
|
|
48
|
+
name: appName,
|
|
49
|
+
tmpl
|
|
50
|
+
};
|
|
51
|
+
return new import_server.Application(subAppOptions);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
ApplicationModel
|
|
57
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IDatabaseOptions, Transactionable } from '@tachybase/database';
|
|
2
|
+
import Application, { Plugin } from '@tachybase/server';
|
|
3
|
+
import { AppOptionsFactory } from './app-lifecycle';
|
|
4
|
+
export type AppDbCreator = (app: Application, options?: Transactionable & {
|
|
5
|
+
context?: any;
|
|
6
|
+
}) => Promise<void>;
|
|
7
|
+
export type { AppOptionsFactory };
|
|
8
|
+
export type SubAppUpgradeHandler = (mainApp: Application) => Promise<void>;
|
|
9
|
+
export declare class PluginMultiAppManager extends Plugin {
|
|
10
|
+
appDbCreator: AppDbCreator;
|
|
11
|
+
appOptionsFactory: AppOptionsFactory;
|
|
12
|
+
subAppUpgradeHandler: SubAppUpgradeHandler;
|
|
13
|
+
static getDatabaseConfig(app: Application): IDatabaseOptions;
|
|
14
|
+
setSubAppUpgradeHandler(handler: SubAppUpgradeHandler): void;
|
|
15
|
+
setAppOptionsFactory(factory: AppOptionsFactory): void;
|
|
16
|
+
setAppDbCreator(appDbCreator: AppDbCreator): void;
|
|
17
|
+
beforeLoad(): void;
|
|
18
|
+
load(): Promise<void>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
PluginMultiAppManager: () => PluginMultiAppManager
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_path = __toESM(require("path"));
|
|
34
|
+
var import_database = require("@tachybase/database");
|
|
35
|
+
var import_server = require("@tachybase/server");
|
|
36
|
+
var import_lodash = __toESM(require("lodash"));
|
|
37
|
+
var import_server2 = require("../server");
|
|
38
|
+
var actions = __toESM(require("./actions/apps"));
|
|
39
|
+
var import_app_lifecycle = require("./app-lifecycle");
|
|
40
|
+
var import_middlewares = require("./middlewares");
|
|
41
|
+
const defaultSubAppUpgradeHandle = async (mainApp) => {
|
|
42
|
+
const repository = mainApp.db.getRepository("applications");
|
|
43
|
+
const findOptions = {};
|
|
44
|
+
const appSupervisor = import_server.AppSupervisor.getInstance();
|
|
45
|
+
if (appSupervisor.runningMode === "single") {
|
|
46
|
+
findOptions["filter"] = {
|
|
47
|
+
name: appSupervisor.singleAppName
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const instances = await repository.find(findOptions);
|
|
51
|
+
for (const instance of instances) {
|
|
52
|
+
const instanceOptions = instance.get("options");
|
|
53
|
+
if ((instanceOptions == null ? void 0 : instanceOptions.standaloneDeployment) && appSupervisor.runningMode !== "single") {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const beforeSubAppStatus = import_server.AppSupervisor.getInstance().getAppStatus(instance.name);
|
|
57
|
+
const subApp = await appSupervisor.getApp(instance.name, {
|
|
58
|
+
upgrading: true
|
|
59
|
+
});
|
|
60
|
+
console.log({ beforeSubAppStatus });
|
|
61
|
+
try {
|
|
62
|
+
mainApp.setMaintainingMessage(`upgrading sub app ${instance.name}...`);
|
|
63
|
+
console.log(`${instance.name}: upgrading...`);
|
|
64
|
+
await subApp.runAsCLI(["upgrade"], { from: "user" });
|
|
65
|
+
if (!beforeSubAppStatus && import_server.AppSupervisor.getInstance().getAppStatus(instance.name) === "initialized") {
|
|
66
|
+
await import_server.AppSupervisor.getInstance().removeApp(instance.name);
|
|
67
|
+
}
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.log(`${instance.name}: upgrade failed`);
|
|
70
|
+
mainApp.logger.error(error);
|
|
71
|
+
console.error(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const defaultDbCreator = async (app) => {
|
|
76
|
+
var _a;
|
|
77
|
+
const databaseOptions = app.options.database;
|
|
78
|
+
const { host, port, username, password, dialect, database } = databaseOptions;
|
|
79
|
+
const tmpl = (_a = app.options) == null ? void 0 : _a.tmpl;
|
|
80
|
+
if (dialect === "mysql") {
|
|
81
|
+
const mysql = require("mysql2/promise");
|
|
82
|
+
const connection = await mysql.createConnection({ host, port, user: username, password });
|
|
83
|
+
await connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
|
|
84
|
+
await connection.close();
|
|
85
|
+
}
|
|
86
|
+
if (dialect === "mariadb") {
|
|
87
|
+
const mariadb = require("mariadb");
|
|
88
|
+
const connection = await mariadb.createConnection({ host, port, user: username, password });
|
|
89
|
+
await connection.query(`CREATE DATABASE IF NOT EXISTS \`${database}\`;`);
|
|
90
|
+
await connection.end();
|
|
91
|
+
}
|
|
92
|
+
if (dialect === "postgres") {
|
|
93
|
+
const { Client } = require("pg");
|
|
94
|
+
const client = new Client({
|
|
95
|
+
host,
|
|
96
|
+
port,
|
|
97
|
+
user: username,
|
|
98
|
+
password,
|
|
99
|
+
database: "postgres"
|
|
100
|
+
});
|
|
101
|
+
await client.connect();
|
|
102
|
+
try {
|
|
103
|
+
if (tmpl) {
|
|
104
|
+
app.logger.info(`create new app db ${database} with tmpl db ${tmpl}...`);
|
|
105
|
+
const tmplExists = await client.query(`SELECT 1 FROM pg_database WHERE datname='${tmpl}'`);
|
|
106
|
+
if (tmplExists.rows.length === 0) {
|
|
107
|
+
const errMsg = `template database ${tmpl} not exists.`;
|
|
108
|
+
app.logger.error(errMsg);
|
|
109
|
+
import_server.AppSupervisor.getInstance().setAppError(database, new Error(errMsg));
|
|
110
|
+
} else {
|
|
111
|
+
const result = await client.query(`SELECT datistemplate FROM pg_database WHERE datname='${tmpl}'`);
|
|
112
|
+
const tmplDbIsTmpl = result.rows.length > 0 && result.rows[0].datistemplate;
|
|
113
|
+
if (!tmplDbIsTmpl) await client.query(`ALTER DATABASE "${tmpl}" IS_TEMPLATE true`);
|
|
114
|
+
await client.query(`ALTER DATABASE "${tmpl}" ALLOW_CONNECTIONS false`);
|
|
115
|
+
let tmplDbInUse = true;
|
|
116
|
+
do {
|
|
117
|
+
const tmp = await client.query(
|
|
118
|
+
`SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='${tmpl}' AND pid<>pg_backend_pid()`
|
|
119
|
+
);
|
|
120
|
+
tmplDbInUse = tmp.rows.length > 0;
|
|
121
|
+
} while (tmplDbInUse);
|
|
122
|
+
await client.query(`CREATE DATABASE "${database}" WITH TEMPLATE "${tmpl}"`);
|
|
123
|
+
if (!tmplDbIsTmpl) await client.query(`ALTER DATABASE "${tmpl}" IS_TEMPLATE false`);
|
|
124
|
+
await client.query(`ALTER DATABASE "${tmpl}" ALLOW_CONNECTIONS true`);
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
await client.query(`CREATE DATABASE "${database}"`);
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
app.logger.error(JSON.stringify(e));
|
|
131
|
+
import_server.AppSupervisor.getInstance().setAppError(database, e);
|
|
132
|
+
}
|
|
133
|
+
await client.end();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const defaultAppOptionsFactory = (appName, mainApp, preset) => {
|
|
137
|
+
const rawDatabaseOptions = PluginMultiAppManager.getDatabaseConfig(mainApp);
|
|
138
|
+
if (rawDatabaseOptions.dialect === "sqlite") {
|
|
139
|
+
const mainAppStorage = rawDatabaseOptions.storage;
|
|
140
|
+
if (mainAppStorage !== ":memory:") {
|
|
141
|
+
const mainStorageDir = import_path.default.dirname(mainAppStorage);
|
|
142
|
+
rawDatabaseOptions.storage = import_path.default.join(mainStorageDir, `${appName}.sqlite`);
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
rawDatabaseOptions.database = appName;
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
database: {
|
|
149
|
+
...rawDatabaseOptions,
|
|
150
|
+
tablePrefix: ""
|
|
151
|
+
},
|
|
152
|
+
plugins: [preset],
|
|
153
|
+
resourcer: {
|
|
154
|
+
prefix: process.env.API_BASE_PATH
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
class PluginMultiAppManager extends import_server.Plugin {
|
|
159
|
+
appDbCreator = defaultDbCreator;
|
|
160
|
+
appOptionsFactory = defaultAppOptionsFactory;
|
|
161
|
+
subAppUpgradeHandler = defaultSubAppUpgradeHandle;
|
|
162
|
+
static getDatabaseConfig(app) {
|
|
163
|
+
let oldConfig = app.options.database instanceof import_database.Database ? app.options.database.options : app.options.database;
|
|
164
|
+
if (!oldConfig && app.db) {
|
|
165
|
+
oldConfig = app.db.options;
|
|
166
|
+
}
|
|
167
|
+
return import_lodash.default.cloneDeep(import_lodash.default.omit(oldConfig, ["migrator"]));
|
|
168
|
+
}
|
|
169
|
+
setSubAppUpgradeHandler(handler) {
|
|
170
|
+
this.subAppUpgradeHandler = handler;
|
|
171
|
+
}
|
|
172
|
+
setAppOptionsFactory(factory) {
|
|
173
|
+
this.appOptionsFactory = factory;
|
|
174
|
+
}
|
|
175
|
+
setAppDbCreator(appDbCreator) {
|
|
176
|
+
this.appDbCreator = appDbCreator;
|
|
177
|
+
}
|
|
178
|
+
beforeLoad() {
|
|
179
|
+
this.db.registerModels({
|
|
180
|
+
ApplicationModel: import_server2.ApplicationModel
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
async load() {
|
|
184
|
+
this.db.on(
|
|
185
|
+
"applications.afterCreateWithAssociations",
|
|
186
|
+
async (model, options) => {
|
|
187
|
+
var _a;
|
|
188
|
+
const { transaction } = options;
|
|
189
|
+
const subApp = model.registerToSupervisor(this.app, {
|
|
190
|
+
appOptionsFactory: this.appOptionsFactory
|
|
191
|
+
});
|
|
192
|
+
await this.appDbCreator(subApp, {
|
|
193
|
+
transaction,
|
|
194
|
+
context: options.context
|
|
195
|
+
});
|
|
196
|
+
if (options.values.options.autoStart) {
|
|
197
|
+
const startPromise = subApp.runCommand("start", "--quickstart");
|
|
198
|
+
if ((_a = options == null ? void 0 : options.context) == null ? void 0 : _a.waitSubAppInstall) {
|
|
199
|
+
await startPromise;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
this.db.on("applications.afterDestroy", async (model) => {
|
|
205
|
+
await import_server.AppSupervisor.getInstance().removeApp(model.get("name"));
|
|
206
|
+
});
|
|
207
|
+
const self = this;
|
|
208
|
+
import_server.AppSupervisor.getInstance().setAppBootstrapper((0, import_app_lifecycle.LazyLoadApplication)(self));
|
|
209
|
+
import_server.Gateway.getInstance().addAppSelectorMiddleware((0, import_middlewares.appSelectorMiddleware)(this.app));
|
|
210
|
+
this.app.on("afterStart", (0, import_app_lifecycle.onAfterStart)(this.db));
|
|
211
|
+
this.app.on("afterUpgrade", async (app, options) => {
|
|
212
|
+
await this.subAppUpgradeHandler(app);
|
|
213
|
+
});
|
|
214
|
+
this.app.acl.allow("applications", "listPinned", "loggedIn");
|
|
215
|
+
this.app.acl.allow("applications", "list", "loggedIn");
|
|
216
|
+
this.app.acl.registerSnippet({
|
|
217
|
+
name: `pm.${this.name}.applications`,
|
|
218
|
+
actions: ["applications:*"]
|
|
219
|
+
});
|
|
220
|
+
this.app.acl.addFixedParams("applications", "destroy", () => {
|
|
221
|
+
return {
|
|
222
|
+
filter: {
|
|
223
|
+
isTemplate: false
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
const injectAppList = (0, import_middlewares.injectAppListMiddleware)();
|
|
228
|
+
this.app.use(
|
|
229
|
+
async (ctx, next) => {
|
|
230
|
+
try {
|
|
231
|
+
await injectAppList(ctx, next);
|
|
232
|
+
} catch (error) {
|
|
233
|
+
ctx.logger.error(error);
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
{ tag: "error-handling" }
|
|
237
|
+
);
|
|
238
|
+
for (const [key, action] of Object.entries(actions)) {
|
|
239
|
+
this.app.resourcer.registerActionHandler(`applications:${key}`, action);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
244
|
+
0 && (module.exports = {
|
|
245
|
+
PluginMultiAppManager
|
|
246
|
+
});
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
info: {
|
|
3
|
+
title: string;
|
|
4
|
+
};
|
|
5
|
+
tags: any[];
|
|
6
|
+
paths: {
|
|
7
|
+
'/applications:list': {
|
|
8
|
+
get: {
|
|
9
|
+
tags: string[];
|
|
10
|
+
description: string;
|
|
11
|
+
responses: {
|
|
12
|
+
200: {
|
|
13
|
+
description: string;
|
|
14
|
+
content: {
|
|
15
|
+
'application/json': {
|
|
16
|
+
schema: {
|
|
17
|
+
$ref: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
'/applications:create': {
|
|
26
|
+
post: {
|
|
27
|
+
tags: string[];
|
|
28
|
+
description: string;
|
|
29
|
+
requestBody: {
|
|
30
|
+
required: boolean;
|
|
31
|
+
content: {
|
|
32
|
+
'application/json': {
|
|
33
|
+
schema: {
|
|
34
|
+
$ref: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
responses: {
|
|
40
|
+
200: {
|
|
41
|
+
description: string;
|
|
42
|
+
content: {
|
|
43
|
+
'application/json': {
|
|
44
|
+
schema: {
|
|
45
|
+
$ref: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
'/applications:update': {
|
|
54
|
+
post: {
|
|
55
|
+
tags: string[];
|
|
56
|
+
description: string;
|
|
57
|
+
parameters: {
|
|
58
|
+
name: string;
|
|
59
|
+
in: string;
|
|
60
|
+
description: string;
|
|
61
|
+
required: boolean;
|
|
62
|
+
schema: {
|
|
63
|
+
type: string;
|
|
64
|
+
};
|
|
65
|
+
}[];
|
|
66
|
+
requestBody: {
|
|
67
|
+
required: boolean;
|
|
68
|
+
content: {
|
|
69
|
+
'application/json': {
|
|
70
|
+
schema: {
|
|
71
|
+
$ref: string;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
responses: {
|
|
77
|
+
200: {
|
|
78
|
+
description: string;
|
|
79
|
+
content: {
|
|
80
|
+
'application/json': {
|
|
81
|
+
schema: {
|
|
82
|
+
$ref: string;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
'/applications:destroy': {
|
|
91
|
+
post: {
|
|
92
|
+
tags: string[];
|
|
93
|
+
description: string;
|
|
94
|
+
parameters: {
|
|
95
|
+
name: string;
|
|
96
|
+
in: string;
|
|
97
|
+
description: string;
|
|
98
|
+
required: boolean;
|
|
99
|
+
schema: {
|
|
100
|
+
type: string;
|
|
101
|
+
};
|
|
102
|
+
}[];
|
|
103
|
+
responses: {
|
|
104
|
+
200: {
|
|
105
|
+
description: string;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
components: {
|
|
112
|
+
schemas: {
|
|
113
|
+
applicationFrom: {
|
|
114
|
+
allOf: ({
|
|
115
|
+
$ref: string;
|
|
116
|
+
type?: undefined;
|
|
117
|
+
properties?: undefined;
|
|
118
|
+
} | {
|
|
119
|
+
type: string;
|
|
120
|
+
properties: {
|
|
121
|
+
createdAt: {
|
|
122
|
+
readOnly: boolean;
|
|
123
|
+
};
|
|
124
|
+
updatedAt: {
|
|
125
|
+
readOnly: boolean;
|
|
126
|
+
};
|
|
127
|
+
status: {
|
|
128
|
+
readOnly: boolean;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
$ref?: undefined;
|
|
132
|
+
})[];
|
|
133
|
+
};
|
|
134
|
+
application: {
|
|
135
|
+
type: string;
|
|
136
|
+
properties: {
|
|
137
|
+
name: {
|
|
138
|
+
type: string;
|
|
139
|
+
example: string;
|
|
140
|
+
description: string;
|
|
141
|
+
};
|
|
142
|
+
displayName: {
|
|
143
|
+
type: string;
|
|
144
|
+
example: string;
|
|
145
|
+
description: string;
|
|
146
|
+
};
|
|
147
|
+
pinned: {
|
|
148
|
+
type: string;
|
|
149
|
+
example: boolean;
|
|
150
|
+
description: string;
|
|
151
|
+
};
|
|
152
|
+
cname: {
|
|
153
|
+
type: string;
|
|
154
|
+
example: string;
|
|
155
|
+
description: string;
|
|
156
|
+
};
|
|
157
|
+
status: {
|
|
158
|
+
type: string;
|
|
159
|
+
example: string;
|
|
160
|
+
description: string;
|
|
161
|
+
};
|
|
162
|
+
options: {
|
|
163
|
+
type: string;
|
|
164
|
+
properties: {
|
|
165
|
+
autoStart: {
|
|
166
|
+
type: string;
|
|
167
|
+
example: boolean;
|
|
168
|
+
description: string;
|
|
169
|
+
};
|
|
170
|
+
startEnvs: {
|
|
171
|
+
type: string;
|
|
172
|
+
example: string;
|
|
173
|
+
description: string;
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
tmpl: {
|
|
178
|
+
type: string;
|
|
179
|
+
example: string;
|
|
180
|
+
description: string;
|
|
181
|
+
};
|
|
182
|
+
createdAt: {
|
|
183
|
+
type: string;
|
|
184
|
+
format: string;
|
|
185
|
+
description: string;
|
|
186
|
+
};
|
|
187
|
+
updatedAt: {
|
|
188
|
+
type: string;
|
|
189
|
+
format: string;
|
|
190
|
+
description: string;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
export default _default;
|