@nocobase/server 0.13.0-alpha.4 → 0.13.0-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.
- package/lib/acl/available-action.js +31 -12
- package/lib/acl/index.js +43 -26
- package/lib/app-supervisor.d.ts +1 -1
- package/lib/app-supervisor.js +161 -154
- package/lib/application.d.ts +4 -2
- package/lib/application.js +363 -488
- package/lib/commands/console.js +37 -28
- package/lib/commands/db-auth.js +27 -20
- package/lib/commands/db-clean.js +29 -20
- package/lib/commands/db-sync.js +29 -15
- package/lib/commands/destroy.js +27 -13
- package/lib/commands/index.js +68 -25
- package/lib/commands/install.js +28 -14
- package/lib/commands/migrator.js +30 -21
- package/lib/commands/pm.js +49 -67
- package/lib/commands/restart.js +27 -13
- package/lib/commands/start.js +33 -19
- package/lib/commands/stop.js +27 -13
- package/lib/commands/upgrade.js +41 -27
- package/lib/errors/application-not-install.js +32 -10
- package/lib/errors/handler.d.ts +3 -0
- package/lib/errors/handler.js +38 -0
- package/lib/errors/plugin-command-error.d.ts +2 -0
- package/lib/errors/plugin-command-error.js +31 -0
- package/lib/gateway/errors.js +75 -83
- package/lib/gateway/handle-plugin-static-file.js +78 -84
- package/lib/gateway/index.js +196 -258
- package/lib/gateway/ipc-socket-client.d.ts +9 -2
- package/lib/gateway/ipc-socket-client.js +83 -36
- package/lib/gateway/ipc-socket-server.d.ts +1 -1
- package/lib/gateway/ipc-socket-server.js +81 -66
- package/lib/gateway/ws-server.js +132 -148
- package/lib/helper.d.ts +1 -1
- package/lib/helper.js +108 -122
- package/lib/helpers/application-version.js +74 -65
- package/lib/index.js +51 -100
- package/lib/locale/index.js +20 -15
- package/lib/locale/locale.js +77 -120
- package/lib/locale/resource.js +53 -44
- package/lib/middlewares/data-template.js +62 -87
- package/lib/middlewares/data-wrapping.js +76 -68
- package/lib/middlewares/db2resource.js +43 -36
- package/lib/middlewares/i18n.js +40 -28
- package/lib/middlewares/index.js +28 -35
- package/lib/middlewares/parse-variables.js +72 -70
- package/lib/migration.js +31 -15
- package/lib/plugin-manager/clientStaticMiddleware.js +29 -16
- package/lib/plugin-manager/index.js +22 -26
- package/lib/plugin-manager/options/collection.js +35 -38
- package/lib/plugin-manager/options/resource.js +65 -68
- package/lib/plugin-manager/plugin-manager-repository.js +115 -163
- package/lib/plugin-manager/plugin-manager.js +375 -549
- package/lib/plugin.js +53 -42
- package/lib/read-config.js +75 -108
- package/package.json +12 -12
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 available_action_exports = {};
|
|
19
|
+
__export(available_action_exports, {
|
|
20
|
+
availableActions: () => availableActions
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
22
|
+
module.exports = __toCommonJS(available_action_exports);
|
|
7
23
|
const availableActions = {
|
|
8
24
|
create: {
|
|
9
25
|
displayName: '{{t("Add new")}}',
|
|
10
|
-
type:
|
|
26
|
+
type: "new-data",
|
|
11
27
|
onNewRecord: true,
|
|
12
28
|
allowConfigureFields: true
|
|
13
29
|
},
|
|
@@ -23,19 +39,22 @@ const availableActions = {
|
|
|
23
39
|
// },
|
|
24
40
|
view: {
|
|
25
41
|
displayName: '{{t("View")}}',
|
|
26
|
-
type:
|
|
27
|
-
aliases: [
|
|
42
|
+
type: "old-data",
|
|
43
|
+
aliases: ["get", "list"],
|
|
28
44
|
allowConfigureFields: true
|
|
29
45
|
},
|
|
30
46
|
update: {
|
|
31
47
|
displayName: '{{t("Edit")}}',
|
|
32
|
-
type:
|
|
33
|
-
aliases: [
|
|
48
|
+
type: "old-data",
|
|
49
|
+
aliases: ["update", "move"],
|
|
34
50
|
allowConfigureFields: true
|
|
35
51
|
},
|
|
36
52
|
destroy: {
|
|
37
53
|
displayName: '{{t("Delete")}}',
|
|
38
|
-
type:
|
|
54
|
+
type: "old-data"
|
|
39
55
|
}
|
|
40
56
|
};
|
|
41
|
-
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
availableActions
|
|
60
|
+
});
|
package/lib/acl/index.js
CHANGED
|
@@ -1,32 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var acl_exports = {};
|
|
20
|
+
__export(acl_exports, {
|
|
21
|
+
createACL: () => createACL
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
-
const configureResources = ['roles', 'users', 'collections', 'fields', 'collections.fields', 'roles.collections', 'roles.resources', 'rolesResourcesScopes', 'availableActions'];
|
|
23
|
+
module.exports = __toCommonJS(acl_exports);
|
|
24
|
+
var import_acl = require("@nocobase/acl");
|
|
25
|
+
var import_available_action = require("./available-action");
|
|
26
|
+
const configureResources = [
|
|
27
|
+
"roles",
|
|
28
|
+
"users",
|
|
29
|
+
"collections",
|
|
30
|
+
"fields",
|
|
31
|
+
"collections.fields",
|
|
32
|
+
"roles.collections",
|
|
33
|
+
"roles.resources",
|
|
34
|
+
"rolesResourcesScopes",
|
|
35
|
+
"availableActions"
|
|
36
|
+
];
|
|
22
37
|
function createACL() {
|
|
23
|
-
const acl = new
|
|
24
|
-
for (
|
|
25
|
-
const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
26
|
-
actionName = _Object$entries$_i[0],
|
|
27
|
-
actionParams = _Object$entries$_i[1];
|
|
38
|
+
const acl = new import_acl.ACL();
|
|
39
|
+
for (const [actionName, actionParams] of Object.entries(import_available_action.availableActions)) {
|
|
28
40
|
acl.setAvailableAction(actionName, actionParams);
|
|
29
41
|
}
|
|
30
42
|
acl.registerConfigResources(configureResources);
|
|
31
43
|
return acl;
|
|
32
|
-
}
|
|
44
|
+
}
|
|
45
|
+
__name(createACL, "createACL");
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
createACL
|
|
49
|
+
});
|
package/lib/app-supervisor.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter
|
|
|
38
38
|
clearAppError(appName: string): void;
|
|
39
39
|
reset(): Promise<void>;
|
|
40
40
|
destroy(): Promise<void>;
|
|
41
|
-
setAppStatus(appName: string, status: AppStatus): void;
|
|
41
|
+
setAppStatus(appName: string, status: AppStatus, options?: {}): void;
|
|
42
42
|
getMutexOfApp(appName: string): any;
|
|
43
43
|
bootStrapApp(appName: string, options?: {}): Promise<void>;
|
|
44
44
|
getApp(appName: string, options?: {
|
package/lib/app-supervisor.js
CHANGED
|
@@ -1,61 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __publicField = (obj, key, value) => {
|
|
31
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
var app_supervisor_exports = {};
|
|
35
|
+
__export(app_supervisor_exports, {
|
|
36
|
+
AppSupervisor: () => AppSupervisor
|
|
5
37
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const data = require("events");
|
|
23
|
-
_events = function _events() {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
var _application = _interopRequireDefault(require("./application"));
|
|
29
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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
|
-
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); }); }; }
|
|
32
|
-
class AppSupervisor extends _events().EventEmitter {
|
|
38
|
+
module.exports = __toCommonJS(app_supervisor_exports);
|
|
39
|
+
var import_utils = require("@nocobase/utils");
|
|
40
|
+
var import_async_mutex = require("async-mutex");
|
|
41
|
+
var import_events = require("events");
|
|
42
|
+
var import_application = __toESM(require("./application"));
|
|
43
|
+
var import_handler = require("./errors/handler");
|
|
44
|
+
const _AppSupervisor = class _AppSupervisor extends import_events.EventEmitter {
|
|
45
|
+
runningMode = "multiple";
|
|
46
|
+
singleAppName = null;
|
|
47
|
+
apps = {};
|
|
48
|
+
appErrors = {};
|
|
49
|
+
appStatus = {};
|
|
50
|
+
lastMaintainingMessage = {};
|
|
51
|
+
statusBeforeCommanding = {};
|
|
52
|
+
appMutexes = {};
|
|
53
|
+
appBootstrapper = null;
|
|
33
54
|
constructor() {
|
|
34
55
|
super();
|
|
35
|
-
this.runningMode = 'multiple';
|
|
36
|
-
this.singleAppName = null;
|
|
37
|
-
this.apps = {};
|
|
38
|
-
this.appErrors = {};
|
|
39
|
-
this.appStatus = {};
|
|
40
|
-
this.lastMaintainingMessage = {};
|
|
41
|
-
this.statusBeforeCommanding = {};
|
|
42
|
-
this.appMutexes = {};
|
|
43
|
-
this.appBootstrapper = null;
|
|
44
56
|
if (process.env.STARTUP_SUBAPP) {
|
|
45
|
-
this.runningMode =
|
|
57
|
+
this.runningMode = "single";
|
|
46
58
|
this.singleAppName = process.env.STARTUP_SUBAPP;
|
|
47
59
|
}
|
|
48
60
|
}
|
|
49
61
|
static getInstance() {
|
|
50
|
-
if (!
|
|
51
|
-
|
|
62
|
+
if (!_AppSupervisor.instance) {
|
|
63
|
+
_AppSupervisor.instance = new _AppSupervisor();
|
|
52
64
|
}
|
|
53
|
-
return
|
|
65
|
+
return _AppSupervisor.instance;
|
|
54
66
|
}
|
|
55
67
|
setAppError(appName, error) {
|
|
56
68
|
this.appErrors[appName] = error;
|
|
57
|
-
this.emit(
|
|
58
|
-
appName
|
|
69
|
+
this.emit("appError", {
|
|
70
|
+
appName,
|
|
59
71
|
error
|
|
60
72
|
});
|
|
61
73
|
}
|
|
@@ -65,130 +77,110 @@ class AppSupervisor extends _events().EventEmitter {
|
|
|
65
77
|
clearAppError(appName) {
|
|
66
78
|
delete this.appErrors[appName];
|
|
67
79
|
}
|
|
68
|
-
reset() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
_this.appBootstrapper = null;
|
|
77
|
-
_this.removeAllListeners();
|
|
78
|
-
})();
|
|
80
|
+
async reset() {
|
|
81
|
+
const appNames = Object.keys(this.apps);
|
|
82
|
+
for (const appName of appNames) {
|
|
83
|
+
await this.removeApp(appName);
|
|
84
|
+
}
|
|
85
|
+
this.appBootstrapper = null;
|
|
86
|
+
this.removeAllListeners();
|
|
79
87
|
}
|
|
80
|
-
destroy() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
yield _this2.reset();
|
|
84
|
-
AppSupervisor.instance = null;
|
|
85
|
-
})();
|
|
88
|
+
async destroy() {
|
|
89
|
+
await this.reset();
|
|
90
|
+
_AppSupervisor.instance = null;
|
|
86
91
|
}
|
|
87
|
-
setAppStatus(appName, status) {
|
|
92
|
+
setAppStatus(appName, status, options = {}) {
|
|
88
93
|
if (this.appStatus[appName] === status) {
|
|
89
94
|
return;
|
|
90
95
|
}
|
|
91
96
|
this.appStatus[appName] = status;
|
|
92
|
-
this.emit(
|
|
97
|
+
this.emit("appStatusChanged", {
|
|
93
98
|
appName,
|
|
94
|
-
status
|
|
99
|
+
status,
|
|
100
|
+
options
|
|
95
101
|
});
|
|
96
102
|
}
|
|
97
103
|
getMutexOfApp(appName) {
|
|
98
104
|
if (!this.appMutexes[appName]) {
|
|
99
|
-
this.appMutexes[appName] = new
|
|
105
|
+
this.appMutexes[appName] = new import_async_mutex.Mutex();
|
|
100
106
|
}
|
|
101
107
|
return this.appMutexes[appName];
|
|
102
108
|
}
|
|
103
|
-
bootStrapApp(appName, options = {}) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
} else if (!_this3.getAppStatus(appName) || _this3.getAppStatus(appName) == 'initializing') {
|
|
119
|
-
_this3.setAppStatus(appName, 'initialized');
|
|
120
|
-
}
|
|
109
|
+
async bootStrapApp(appName, options = {}) {
|
|
110
|
+
await this.getMutexOfApp(appName).runExclusive(async () => {
|
|
111
|
+
if (!this.hasApp(appName)) {
|
|
112
|
+
this.setAppStatus(appName, "initializing");
|
|
113
|
+
if (this.appBootstrapper) {
|
|
114
|
+
await this.appBootstrapper({
|
|
115
|
+
appSupervisor: this,
|
|
116
|
+
appName,
|
|
117
|
+
options
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (!this.hasApp(appName)) {
|
|
121
|
+
this.setAppStatus(appName, "not_found");
|
|
122
|
+
} else if (!this.getAppStatus(appName) || this.getAppStatus(appName) == "initializing") {
|
|
123
|
+
this.setAppStatus(appName, "initialized");
|
|
121
124
|
}
|
|
122
|
-
}));
|
|
123
|
-
})();
|
|
124
|
-
}
|
|
125
|
-
getApp(appName, options = {}) {
|
|
126
|
-
var _this4 = this;
|
|
127
|
-
return _asyncToGenerator(function* () {
|
|
128
|
-
if (!options.withOutBootStrap) {
|
|
129
|
-
yield _this4.bootStrapApp(appName, options);
|
|
130
125
|
}
|
|
131
|
-
|
|
132
|
-
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async getApp(appName, options = {}) {
|
|
129
|
+
if (!options.withOutBootStrap) {
|
|
130
|
+
await this.bootStrapApp(appName, options);
|
|
131
|
+
}
|
|
132
|
+
return this.apps[appName];
|
|
133
133
|
}
|
|
134
134
|
setAppBootstrapper(appBootstrapper) {
|
|
135
135
|
this.appBootstrapper = appBootstrapper;
|
|
136
136
|
}
|
|
137
137
|
getAppStatus(appName, defaultStatus) {
|
|
138
138
|
const status = this.appStatus[appName];
|
|
139
|
-
if (status ===
|
|
139
|
+
if (status === void 0 && defaultStatus !== void 0) {
|
|
140
140
|
return defaultStatus;
|
|
141
141
|
}
|
|
142
142
|
return status;
|
|
143
143
|
}
|
|
144
144
|
bootMainApp(options) {
|
|
145
|
-
return new
|
|
145
|
+
return new import_application.default(options);
|
|
146
146
|
}
|
|
147
147
|
hasApp(appName) {
|
|
148
148
|
return !!this.apps[appName];
|
|
149
149
|
}
|
|
150
150
|
// add app into supervisor
|
|
151
151
|
addApp(app) {
|
|
152
|
-
// if there is already an app with the same name, throw error
|
|
153
152
|
if (this.apps[app.name]) {
|
|
154
153
|
throw new Error(`app ${app.name} already exists`);
|
|
155
154
|
}
|
|
156
155
|
console.log(`add app ${app.name} into supervisor`);
|
|
157
156
|
this.bindAppEvents(app);
|
|
158
157
|
this.apps[app.name] = app;
|
|
159
|
-
this.emit(
|
|
160
|
-
if (!this.getAppStatus(app.name) || this.getAppStatus(app.name) ==
|
|
161
|
-
this.setAppStatus(app.name,
|
|
158
|
+
this.emit("afterAppAdded", app);
|
|
159
|
+
if (!this.getAppStatus(app.name) || this.getAppStatus(app.name) == "not_found") {
|
|
160
|
+
this.setAppStatus(app.name, "initialized");
|
|
162
161
|
}
|
|
163
162
|
return app;
|
|
164
163
|
}
|
|
165
164
|
// get registered app names
|
|
166
|
-
getAppsNames() {
|
|
167
|
-
|
|
168
|
-
return
|
|
169
|
-
const apps = Object.values(_this5.apps);
|
|
170
|
-
return apps.map(app => app.name);
|
|
171
|
-
})();
|
|
165
|
+
async getAppsNames() {
|
|
166
|
+
const apps = Object.values(this.apps);
|
|
167
|
+
return apps.map((app) => app.name);
|
|
172
168
|
}
|
|
173
|
-
removeApp(appName) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
// call app.destroy
|
|
181
|
-
yield _this6.apps[appName].runCommand('destroy');
|
|
182
|
-
})();
|
|
169
|
+
async removeApp(appName) {
|
|
170
|
+
if (!this.apps[appName]) {
|
|
171
|
+
console.log(`app ${appName} not exists`);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
await this.apps[appName].runCommand("destroy");
|
|
183
175
|
}
|
|
184
176
|
subApps() {
|
|
185
|
-
return Object.values(this.apps).filter(app => app.name !==
|
|
177
|
+
return Object.values(this.apps).filter((app) => app.name !== "main");
|
|
186
178
|
}
|
|
187
179
|
on(eventName, listener) {
|
|
188
180
|
const listeners = this.listeners(eventName);
|
|
189
181
|
const listenerName = listener.name;
|
|
190
|
-
if (listenerName !==
|
|
191
|
-
const exists = listeners.find(l => l.name === listenerName);
|
|
182
|
+
if (listenerName !== "") {
|
|
183
|
+
const exists = listeners.find((l) => l.name === listenerName);
|
|
192
184
|
if (exists) {
|
|
193
185
|
super.removeListener(eventName, exists);
|
|
194
186
|
}
|
|
@@ -196,73 +188,88 @@ class AppSupervisor extends _events().EventEmitter {
|
|
|
196
188
|
return super.on(eventName, listener);
|
|
197
189
|
}
|
|
198
190
|
bindAppEvents(app) {
|
|
199
|
-
|
|
200
|
-
app.on('afterDestroy', () => {
|
|
191
|
+
app.on("afterDestroy", () => {
|
|
201
192
|
delete this.apps[app.name];
|
|
202
193
|
delete this.appStatus[app.name];
|
|
203
194
|
delete this.appErrors[app.name];
|
|
204
195
|
delete this.lastMaintainingMessage[app.name];
|
|
205
196
|
delete this.statusBeforeCommanding[app.name];
|
|
206
197
|
});
|
|
207
|
-
app.on(
|
|
208
|
-
message,
|
|
209
|
-
maintainingStatus
|
|
210
|
-
}) => {
|
|
198
|
+
app.on("maintainingMessageChanged", ({ message, maintainingStatus }) => {
|
|
211
199
|
if (this.lastMaintainingMessage[app.name] === message) {
|
|
212
200
|
return;
|
|
213
201
|
}
|
|
214
202
|
this.lastMaintainingMessage[app.name] = message;
|
|
215
203
|
const appStatus = this.getAppStatus(app.name);
|
|
216
|
-
if (!maintainingStatus && appStatus !==
|
|
204
|
+
if (!maintainingStatus && appStatus !== "running") {
|
|
217
205
|
return;
|
|
218
206
|
}
|
|
219
|
-
this.emit(
|
|
207
|
+
this.emit("appMaintainingMessageChanged", {
|
|
220
208
|
appName: app.name,
|
|
221
209
|
message,
|
|
222
210
|
status: appStatus,
|
|
223
|
-
command: appStatus ==
|
|
211
|
+
command: appStatus == "running" ? null : maintainingStatus.command
|
|
224
212
|
});
|
|
225
213
|
});
|
|
226
|
-
app.on(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
214
|
+
app.on("__started", async (_app, options) => {
|
|
215
|
+
const { maintainingStatus } = options;
|
|
216
|
+
if (maintainingStatus && ["install", "upgrade", "pm.enable", "pm.disable"].includes(maintainingStatus.command.name)) {
|
|
217
|
+
this.setAppStatus(app.name, "running", {
|
|
218
|
+
refresh: true
|
|
219
|
+
});
|
|
220
|
+
} else {
|
|
221
|
+
this.setAppStatus(app.name, "running");
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
app.on("afterStop", async () => {
|
|
225
|
+
this.setAppStatus(app.name, "stopped");
|
|
226
|
+
});
|
|
227
|
+
app.on("maintaining", (maintainingStatus) => {
|
|
228
|
+
const { status, command } = maintainingStatus;
|
|
234
229
|
switch (status) {
|
|
235
|
-
case
|
|
230
|
+
case "command_begin":
|
|
236
231
|
{
|
|
237
232
|
this.statusBeforeCommanding[app.name] = this.getAppStatus(app.name);
|
|
238
|
-
this.setAppStatus(app.name,
|
|
233
|
+
this.setAppStatus(app.name, "commanding");
|
|
239
234
|
}
|
|
240
235
|
break;
|
|
241
|
-
case
|
|
242
|
-
// emit status changed
|
|
243
|
-
// this.emit('appMaintainingStatusChanged', maintainingStatus);
|
|
236
|
+
case "command_running":
|
|
244
237
|
break;
|
|
245
|
-
case
|
|
238
|
+
case "command_end":
|
|
246
239
|
{
|
|
247
240
|
const appStatus = this.getAppStatus(app.name);
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
// not change
|
|
251
|
-
if (appStatus == 'commanding') {
|
|
241
|
+
this.emit("appMaintainingStatusChanged", maintainingStatus);
|
|
242
|
+
if (appStatus == "commanding") {
|
|
252
243
|
this.setAppStatus(app.name, this.statusBeforeCommanding[app.name]);
|
|
253
244
|
}
|
|
254
245
|
}
|
|
255
246
|
break;
|
|
256
|
-
case
|
|
247
|
+
case "command_error":
|
|
257
248
|
{
|
|
258
|
-
|
|
259
|
-
|
|
249
|
+
const errorLevel = (0, import_handler.getErrorLevel)(maintainingStatus.error);
|
|
250
|
+
if (errorLevel === "fatal") {
|
|
251
|
+
this.setAppError(app.name, maintainingStatus.error);
|
|
252
|
+
this.setAppStatus(app.name, "error");
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
if (errorLevel === "warn") {
|
|
256
|
+
this.emit("appError", {
|
|
257
|
+
appName: app.name,
|
|
258
|
+
error: maintainingStatus.error
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
this.setAppStatus(app.name, this.statusBeforeCommanding[app.name]);
|
|
260
262
|
}
|
|
261
263
|
break;
|
|
262
264
|
}
|
|
263
265
|
});
|
|
264
266
|
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
};
|
|
268
|
+
__name(_AppSupervisor, "AppSupervisor");
|
|
269
|
+
__publicField(_AppSupervisor, "instance");
|
|
270
|
+
let AppSupervisor = _AppSupervisor;
|
|
271
|
+
(0, import_utils.applyMixins)(AppSupervisor, [import_utils.AsyncEmitter]);
|
|
272
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
273
|
+
0 && (module.exports = {
|
|
274
|
+
AppSupervisor
|
|
275
|
+
});
|
package/lib/application.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { AuthManager } from '@nocobase/auth';
|
|
|
5
5
|
import { Cache, ICacheConfig } from '@nocobase/cache';
|
|
6
6
|
import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';
|
|
7
7
|
import { AppLoggerOptions, Logger } from '@nocobase/logger';
|
|
8
|
-
import Resourcer,
|
|
8
|
+
import { Resourcer, ResourceOptions } from '@nocobase/resourcer';
|
|
9
9
|
import { AsyncEmitter, ToposortOptions } from '@nocobase/utils';
|
|
10
10
|
import { Command, CommandOptions, ParseOptions } from 'commander';
|
|
11
11
|
import { IncomingMessage, Server, ServerResponse } from 'http';
|
|
@@ -132,7 +132,9 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
132
132
|
authenticate(): Promise<void>;
|
|
133
133
|
runCommand(command: string, ...args: any[]): Promise<Command>;
|
|
134
134
|
createCli(): Command;
|
|
135
|
-
runAsCLI(argv?: string[], options?: ParseOptions
|
|
135
|
+
runAsCLI(argv?: string[], options?: ParseOptions & {
|
|
136
|
+
throwError?: boolean;
|
|
137
|
+
}): Promise<Command>;
|
|
136
138
|
start(options?: StartOptions): Promise<void>;
|
|
137
139
|
isStarted(): Promise<boolean>;
|
|
138
140
|
tryReloadOrRestart(): Promise<void>;
|