@nocobase/server 0.13.0-alpha.3 → 0.13.0-alpha.5

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.
Files changed (56) hide show
  1. package/lib/acl/available-action.js +31 -12
  2. package/lib/acl/index.js +43 -26
  3. package/lib/app-supervisor.d.ts +1 -1
  4. package/lib/app-supervisor.js +161 -154
  5. package/lib/application.d.ts +4 -2
  6. package/lib/application.js +363 -488
  7. package/lib/commands/console.js +37 -28
  8. package/lib/commands/db-auth.js +27 -20
  9. package/lib/commands/db-clean.js +29 -20
  10. package/lib/commands/db-sync.js +29 -15
  11. package/lib/commands/destroy.js +27 -13
  12. package/lib/commands/index.js +68 -25
  13. package/lib/commands/install.js +28 -14
  14. package/lib/commands/migrator.js +30 -21
  15. package/lib/commands/pm.js +49 -67
  16. package/lib/commands/restart.js +27 -13
  17. package/lib/commands/start.js +33 -19
  18. package/lib/commands/stop.js +27 -13
  19. package/lib/commands/upgrade.js +41 -27
  20. package/lib/errors/application-not-install.js +32 -10
  21. package/lib/errors/handler.d.ts +3 -0
  22. package/lib/errors/handler.js +38 -0
  23. package/lib/errors/plugin-command-error.d.ts +2 -0
  24. package/lib/errors/plugin-command-error.js +31 -0
  25. package/lib/gateway/errors.js +75 -83
  26. package/lib/gateway/handle-plugin-static-file.js +78 -84
  27. package/lib/gateway/index.js +196 -258
  28. package/lib/gateway/ipc-socket-client.d.ts +9 -2
  29. package/lib/gateway/ipc-socket-client.js +83 -36
  30. package/lib/gateway/ipc-socket-server.d.ts +1 -1
  31. package/lib/gateway/ipc-socket-server.js +81 -66
  32. package/lib/gateway/ws-server.js +132 -148
  33. package/lib/helper.d.ts +1 -1
  34. package/lib/helper.js +108 -122
  35. package/lib/helpers/application-version.js +74 -65
  36. package/lib/index.js +51 -100
  37. package/lib/locale/index.js +20 -15
  38. package/lib/locale/locale.js +77 -120
  39. package/lib/locale/resource.js +53 -44
  40. package/lib/middlewares/data-template.js +62 -87
  41. package/lib/middlewares/data-wrapping.js +76 -68
  42. package/lib/middlewares/db2resource.js +43 -36
  43. package/lib/middlewares/i18n.js +40 -28
  44. package/lib/middlewares/index.js +28 -35
  45. package/lib/middlewares/parse-variables.js +72 -70
  46. package/lib/migration.js +31 -15
  47. package/lib/plugin-manager/clientStaticMiddleware.js +29 -16
  48. package/lib/plugin-manager/index.js +22 -26
  49. package/lib/plugin-manager/options/collection.js +35 -38
  50. package/lib/plugin-manager/options/resource.js +65 -68
  51. package/lib/plugin-manager/plugin-manager-repository.js +115 -163
  52. package/lib/plugin-manager/plugin-manager.d.ts +1 -1
  53. package/lib/plugin-manager/plugin-manager.js +375 -539
  54. package/lib/plugin.js +53 -42
  55. package/lib/read-config.js +75 -108
  56. package/package.json +12 -12
@@ -1,13 +1,29 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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.availableActions = void 0;
22
+ module.exports = __toCommonJS(available_action_exports);
7
23
  const availableActions = {
8
24
  create: {
9
25
  displayName: '{{t("Add new")}}',
10
- type: 'new-data',
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: 'old-data',
27
- aliases: ['get', 'list'],
42
+ type: "old-data",
43
+ aliases: ["get", "list"],
28
44
  allowConfigureFields: true
29
45
  },
30
46
  update: {
31
47
  displayName: '{{t("Edit")}}',
32
- type: 'old-data',
33
- aliases: ['update', 'move'],
48
+ type: "old-data",
49
+ aliases: ["update", "move"],
34
50
  allowConfigureFields: true
35
51
  },
36
52
  destroy: {
37
53
  displayName: '{{t("Delete")}}',
38
- type: 'old-data'
54
+ type: "old-data"
39
55
  }
40
56
  };
41
- exports.availableActions = availableActions;
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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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.createACL = createACL;
7
- function _acl() {
8
- const data = require("@nocobase/acl");
9
- _acl = function _acl() {
10
- return data;
11
- };
12
- return data;
13
- }
14
- var _availableAction = require("./available-action");
15
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
16
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
17
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
18
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
19
- function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
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 (_acl().ACL)();
24
- for (var _i = 0, _Object$entries = Object.entries(_availableAction.availableActions); _i < _Object$entries.length; _i++) {
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
+ });
@@ -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?: {
@@ -1,61 +1,73 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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.AppSupervisor = void 0;
7
- function _utils() {
8
- const data = require("@nocobase/utils");
9
- _utils = function _utils() {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _asyncMutex() {
15
- const data = require("async-mutex");
16
- _asyncMutex = function _asyncMutex() {
17
- return data;
18
- };
19
- return data;
20
- }
21
- function _events() {
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 = 'single';
57
+ this.runningMode = "single";
46
58
  this.singleAppName = process.env.STARTUP_SUBAPP;
47
59
  }
48
60
  }
49
61
  static getInstance() {
50
- if (!AppSupervisor.instance) {
51
- AppSupervisor.instance = new AppSupervisor();
62
+ if (!_AppSupervisor.instance) {
63
+ _AppSupervisor.instance = new _AppSupervisor();
52
64
  }
53
- return AppSupervisor.instance;
65
+ return _AppSupervisor.instance;
54
66
  }
55
67
  setAppError(appName, error) {
56
68
  this.appErrors[appName] = error;
57
- this.emit('appError', {
58
- appName: 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
- var _this = this;
70
- return _asyncToGenerator(function* () {
71
- const appNames = Object.keys(_this.apps);
72
- for (var _i = 0, _appNames = appNames; _i < _appNames.length; _i++) {
73
- const appName = _appNames[_i];
74
- yield _this.removeApp(appName);
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
- var _this2 = this;
82
- return _asyncToGenerator(function* () {
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('appStatusChanged', {
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 (_asyncMutex().Mutex)();
105
+ this.appMutexes[appName] = new import_async_mutex.Mutex();
100
106
  }
101
107
  return this.appMutexes[appName];
102
108
  }
103
- bootStrapApp(appName, options = {}) {
104
- var _this3 = this;
105
- return _asyncToGenerator(function* () {
106
- yield _this3.getMutexOfApp(appName).runExclusive( /*#__PURE__*/_asyncToGenerator(function* () {
107
- if (!_this3.hasApp(appName)) {
108
- _this3.setAppStatus(appName, 'initializing');
109
- if (_this3.appBootstrapper) {
110
- yield _this3.appBootstrapper({
111
- appSupervisor: _this3,
112
- appName,
113
- options
114
- });
115
- }
116
- if (!_this3.hasApp(appName)) {
117
- _this3.setAppStatus(appName, 'not_found');
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
- return _this4.apps[appName];
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 === undefined && defaultStatus !== undefined) {
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 _application.default(options);
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('afterAppAdded', app);
160
- if (!this.getAppStatus(app.name) || this.getAppStatus(app.name) == 'not_found') {
161
- this.setAppStatus(app.name, 'initialized');
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
- var _this5 = this;
168
- return _asyncToGenerator(function* () {
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
- var _this6 = this;
175
- return _asyncToGenerator(function* () {
176
- if (!_this6.apps[appName]) {
177
- console.log(`app ${appName} not exists`);
178
- return;
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 !== 'main');
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
- var _this7 = this;
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('maintainingMessageChanged', ({
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 !== 'running') {
204
+ if (!maintainingStatus && appStatus !== "running") {
217
205
  return;
218
206
  }
219
- this.emit('appMaintainingMessageChanged', {
207
+ this.emit("appMaintainingMessageChanged", {
220
208
  appName: app.name,
221
209
  message,
222
210
  status: appStatus,
223
- command: appStatus == 'running' ? null : maintainingStatus.command
211
+ command: appStatus == "running" ? null : maintainingStatus.command
224
212
  });
225
213
  });
226
- app.on('__started', /*#__PURE__*/_asyncToGenerator(function* () {
227
- _this7.setAppStatus(app.name, 'running');
228
- }));
229
- app.on('afterStop', /*#__PURE__*/_asyncToGenerator(function* () {
230
- _this7.setAppStatus(app.name, 'stopped');
231
- }));
232
- app.on('maintaining', maintainingStatus => {
233
- const status = maintainingStatus.status;
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 'command_begin':
230
+ case "command_begin":
236
231
  {
237
232
  this.statusBeforeCommanding[app.name] = this.getAppStatus(app.name);
238
- this.setAppStatus(app.name, 'commanding');
233
+ this.setAppStatus(app.name, "commanding");
239
234
  }
240
235
  break;
241
- case 'command_running':
242
- // emit status changed
243
- // this.emit('appMaintainingStatusChanged', maintainingStatus);
236
+ case "command_running":
244
237
  break;
245
- case 'command_end':
238
+ case "command_end":
246
239
  {
247
240
  const appStatus = this.getAppStatus(app.name);
248
- // emit status changed
249
- this.emit('appMaintainingStatusChanged', maintainingStatus);
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 'command_error':
247
+ case "command_error":
257
248
  {
258
- this.setAppError(app.name, maintainingStatus.error);
259
- this.setAppStatus(app.name, 'error');
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
- exports.AppSupervisor = AppSupervisor;
267
- AppSupervisor.instance = void 0;
268
- (0, _utils().applyMixins)(AppSupervisor, [_utils().AsyncEmitter]);
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
+ });
@@ -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, { ResourceOptions } from '@nocobase/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): Promise<Command>;
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>;