@nocobase/server 0.9.1-alpha.2 → 0.9.2-alpha.2
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/index.js +3 -18
- package/lib/app-manager.d.ts +9 -9
- package/lib/app-manager.js +58 -89
- package/lib/application.js +25 -171
- package/lib/commands/console.js +0 -7
- package/lib/commands/db-auth.js +0 -5
- package/lib/commands/db-clean.js +0 -5
- package/lib/commands/db-sync.js +0 -4
- package/lib/commands/index.js +2 -12
- package/lib/commands/install.js +0 -14
- package/lib/commands/migrator.js +0 -5
- package/lib/commands/pm.js +3 -10
- package/lib/commands/start.js +0 -5
- package/lib/commands/upgrade.js +0 -8
- package/lib/helper.js +13 -36
- package/lib/index.js +0 -15
- package/lib/middlewares/data-template.d.ts +2 -0
- package/lib/middlewares/data-template.js +147 -0
- package/lib/middlewares/data-wrapping.js +4 -26
- package/lib/middlewares/db2resource.js +7 -25
- package/lib/middlewares/i18n.js +0 -8
- package/lib/middlewares/index.d.ts +1 -0
- package/lib/middlewares/index.js +13 -5
- package/lib/middlewares/parse-variables.d.ts +1 -0
- package/lib/middlewares/parse-variables.js +79 -0
- package/lib/migration.js +0 -7
- package/lib/plugin-manager/index.d.ts +1 -1
- package/lib/plugin-manager/index.js +4 -6
- package/lib/plugin-manager/options/collection.d.ts +1 -15
- package/lib/plugin-manager/options/collection.js +10 -3
- package/lib/plugin-manager/options/resource.js +0 -16
- package/lib/plugin-manager/{PluginManagerRepository.d.ts → plugin-manager-repository.d.ts} +1 -1
- package/lib/plugin-manager/{PluginManagerRepository.js → plugin-manager-repository.js} +49 -32
- package/lib/plugin-manager/{PluginManager.d.ts → plugin-manager.d.ts} +1 -1
- package/lib/plugin-manager/{PluginManager.js → plugin-manager.js} +83 -202
- package/lib/plugin.d.ts +2 -0
- package/lib/plugin.js +6 -20
- package/lib/read-config.js +5 -48
- package/package.json +9 -7
package/lib/acl/index.js
CHANGED
|
@@ -4,44 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createACL = createACL;
|
|
7
|
-
|
|
8
7
|
function _acl() {
|
|
9
8
|
const data = require("@nocobase/acl");
|
|
10
|
-
|
|
11
9
|
_acl = function _acl() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
var _availableAction = require("./available-action");
|
|
19
|
-
|
|
20
15
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
21
|
-
|
|
22
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."); }
|
|
23
|
-
|
|
24
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); }
|
|
25
|
-
|
|
26
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; }
|
|
27
|
-
|
|
28
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
29
|
-
|
|
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; } }
|
|
30
20
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
31
|
-
|
|
32
21
|
const configureResources = ['roles', 'users', 'collections', 'fields', 'collections.fields', 'roles.collections', 'roles.resources', 'rolesResourcesScopes', 'availableActions'];
|
|
33
|
-
|
|
34
22
|
function createACL() {
|
|
35
23
|
const acl = new (_acl().ACL)();
|
|
36
|
-
|
|
37
24
|
for (var _i = 0, _Object$entries = Object.entries(_availableAction.availableActions); _i < _Object$entries.length; _i++) {
|
|
38
25
|
const _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
actionName = _Object$entries$_i[0],
|
|
27
|
+
actionParams = _Object$entries$_i[1];
|
|
42
28
|
acl.setAvailableAction(actionName, actionParams);
|
|
43
29
|
}
|
|
44
|
-
|
|
45
30
|
acl.registerConfigResources(configureResources);
|
|
46
31
|
return acl;
|
|
47
32
|
}
|
package/lib/app-manager.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import EventEmitter from 'events';
|
|
3
2
|
import http, { IncomingMessage, ServerResponse } from 'http';
|
|
4
|
-
import Application
|
|
5
|
-
declare type
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import Application from './application';
|
|
4
|
+
declare type AppSelectorReturn = Application | string | undefined | null;
|
|
5
|
+
declare type AppSelector = (req: IncomingMessage) => AppSelectorReturn | Promise<AppSelectorReturn>;
|
|
6
|
+
export declare class AppManager {
|
|
8
7
|
applications: Map<string, Application>;
|
|
8
|
+
app: Application;
|
|
9
9
|
constructor(app: Application);
|
|
10
|
+
bindMainApplication(mainApp: Application): void;
|
|
10
11
|
appSelector: AppSelector;
|
|
11
|
-
|
|
12
|
+
addSubApp(application: any): Application;
|
|
12
13
|
removeApplication(name: string): Promise<void>;
|
|
13
14
|
setAppSelector(selector: AppSelector): void;
|
|
14
|
-
listen(...args: any[]): http.Server
|
|
15
|
+
listen(...args: any[]): http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
|
|
15
16
|
getApplication(appName: string, options?: {}): Promise<null | Application>;
|
|
16
|
-
callback(): (req: IncomingMessage, res: ServerResponse) => Promise<
|
|
17
|
-
emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
|
|
17
|
+
callback(): (req: IncomingMessage, res: ServerResponse) => Promise<http.ServerResponse<http.IncomingMessage>>;
|
|
18
18
|
}
|
|
19
19
|
export {};
|
package/lib/app-manager.js
CHANGED
|
@@ -4,133 +4,106 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.AppManager = void 0;
|
|
7
|
-
|
|
8
|
-
function _utils() {
|
|
9
|
-
const data = require("@nocobase/utils");
|
|
10
|
-
|
|
11
|
-
_utils = function _utils() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _events() {
|
|
19
|
-
const data = _interopRequireDefault(require("events"));
|
|
20
|
-
|
|
21
|
-
_events = function _events() {
|
|
22
|
-
return data;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
7
|
function _http() {
|
|
29
8
|
const data = _interopRequireDefault(require("http"));
|
|
30
|
-
|
|
31
9
|
_http = function _http() {
|
|
32
10
|
return data;
|
|
33
11
|
};
|
|
34
|
-
|
|
35
12
|
return data;
|
|
36
13
|
}
|
|
37
|
-
|
|
38
|
-
var _application = _interopRequireDefault(require("./application"));
|
|
39
|
-
|
|
40
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
41
|
-
|
|
15
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
16
|
+
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); }
|
|
17
|
+
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; }
|
|
42
18
|
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); } }
|
|
43
|
-
|
|
44
19
|
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); }); }; }
|
|
45
|
-
|
|
46
|
-
class AppManager extends _events().default {
|
|
20
|
+
class AppManager {
|
|
47
21
|
constructor(app) {
|
|
48
|
-
var _this;
|
|
49
|
-
|
|
50
|
-
super();
|
|
51
|
-
_this = this;
|
|
52
|
-
this.app = void 0;
|
|
22
|
+
var _this = this;
|
|
53
23
|
this.applications = new Map();
|
|
54
|
-
|
|
55
|
-
this.appSelector =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
app.on('beforeStop', /*#__PURE__*/function () {
|
|
59
|
-
var _ref = _asyncToGenerator(function* (mainApp, options) {
|
|
60
|
-
return yield Promise.all([..._this.applications.values()].map(application => application.stop(options)));
|
|
24
|
+
this.app = void 0;
|
|
25
|
+
this.appSelector = /*#__PURE__*/function () {
|
|
26
|
+
var _ref = _asyncToGenerator(function* (req) {
|
|
27
|
+
return _this.app;
|
|
61
28
|
});
|
|
62
|
-
|
|
63
|
-
return function (_x, _x2) {
|
|
29
|
+
return function (_x) {
|
|
64
30
|
return _ref.apply(this, arguments);
|
|
65
31
|
};
|
|
66
|
-
}()
|
|
67
|
-
|
|
68
|
-
var _ref2 = _asyncToGenerator(function* (mainApp, options) {
|
|
69
|
-
return yield Promise.all([..._this.applications.values()].map(application => application.destroy(options)));
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return function (_x3, _x4) {
|
|
73
|
-
return _ref2.apply(this, arguments);
|
|
74
|
-
};
|
|
75
|
-
}());
|
|
32
|
+
}();
|
|
33
|
+
this.bindMainApplication(app);
|
|
76
34
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
35
|
+
bindMainApplication(mainApp) {
|
|
36
|
+
var _this2 = this;
|
|
37
|
+
this.app = mainApp;
|
|
38
|
+
const passEventToSubApps = (eventName, method) => {
|
|
39
|
+
mainApp.on(eventName, /*#__PURE__*/function () {
|
|
40
|
+
var _ref2 = _asyncToGenerator(function* (mainApp, options) {
|
|
41
|
+
console.log(`receive event ${eventName} from ${mainApp.name}`);
|
|
42
|
+
var _iterator = _createForOfIteratorHelper(_this2.applications.values()),
|
|
43
|
+
_step;
|
|
44
|
+
try {
|
|
45
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
46
|
+
const application = _step.value;
|
|
47
|
+
console.log(`pass ${eventName} to ${application.name} `);
|
|
48
|
+
yield application[method](options);
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
_iterator.e(err);
|
|
52
|
+
} finally {
|
|
53
|
+
_iterator.f();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return function (_x2, _x3) {
|
|
57
|
+
return _ref2.apply(this, arguments);
|
|
58
|
+
};
|
|
59
|
+
}());
|
|
60
|
+
};
|
|
61
|
+
passEventToSubApps('beforeDestroy', 'destroy');
|
|
62
|
+
passEventToSubApps('beforeStop', 'stop');
|
|
63
|
+
}
|
|
64
|
+
addSubApp(application) {
|
|
65
|
+
this.applications.set(application.name, application);
|
|
66
|
+
this.app.emit('afterSubAppAdded', application);
|
|
81
67
|
return application;
|
|
82
68
|
}
|
|
83
|
-
|
|
84
69
|
removeApplication(name) {
|
|
85
|
-
var
|
|
86
|
-
|
|
70
|
+
var _this3 = this;
|
|
87
71
|
return _asyncToGenerator(function* () {
|
|
88
|
-
const application =
|
|
89
|
-
|
|
72
|
+
const application = _this3.applications.get(name);
|
|
90
73
|
if (!application) {
|
|
91
74
|
return;
|
|
92
75
|
}
|
|
93
|
-
|
|
94
76
|
yield application.destroy();
|
|
95
|
-
|
|
96
|
-
|
|
77
|
+
console.log(`remove application ${name}`);
|
|
78
|
+
_this3.applications.delete(name);
|
|
97
79
|
})();
|
|
98
80
|
}
|
|
99
|
-
|
|
100
81
|
setAppSelector(selector) {
|
|
101
82
|
this.appSelector = selector;
|
|
102
83
|
}
|
|
103
|
-
|
|
104
84
|
listen(...args) {
|
|
105
85
|
const server = _http().default.createServer(this.callback());
|
|
106
|
-
|
|
107
86
|
return server.listen(...args);
|
|
108
87
|
}
|
|
109
|
-
|
|
110
88
|
getApplication(appName, options = {}) {
|
|
111
|
-
var
|
|
112
|
-
|
|
89
|
+
var _this4 = this;
|
|
113
90
|
return _asyncToGenerator(function* () {
|
|
114
|
-
yield
|
|
115
|
-
appManager:
|
|
91
|
+
yield _this4.app.emitAsync('beforeGetApplication', {
|
|
92
|
+
appManager: _this4,
|
|
116
93
|
name: appName,
|
|
117
94
|
options
|
|
118
95
|
});
|
|
119
|
-
return
|
|
96
|
+
return _this4.applications.get(appName);
|
|
120
97
|
})();
|
|
121
98
|
}
|
|
122
|
-
|
|
123
99
|
callback() {
|
|
124
|
-
var
|
|
125
|
-
|
|
100
|
+
var _this5 = this;
|
|
126
101
|
return /*#__PURE__*/function () {
|
|
127
102
|
var _ref3 = _asyncToGenerator(function* (req, res) {
|
|
128
|
-
const appManager =
|
|
129
|
-
let handleApp = appManager.appSelector(req) || appManager.app;
|
|
130
|
-
|
|
103
|
+
const appManager = _this5.app.appManager;
|
|
104
|
+
let handleApp = (yield appManager.appSelector(req)) || appManager.app;
|
|
131
105
|
if (typeof handleApp === 'string') {
|
|
132
106
|
handleApp = yield appManager.getApplication(handleApp);
|
|
133
|
-
|
|
134
107
|
if (!handleApp) {
|
|
135
108
|
res.statusCode = 404;
|
|
136
109
|
return res.end(JSON.stringify({
|
|
@@ -140,18 +113,14 @@ class AppManager extends _events().default {
|
|
|
140
113
|
}]
|
|
141
114
|
}));
|
|
142
115
|
}
|
|
116
|
+
if (handleApp.stopped) yield handleApp.start();
|
|
143
117
|
}
|
|
144
|
-
|
|
145
118
|
handleApp.callback()(req, res);
|
|
146
119
|
});
|
|
147
|
-
|
|
148
|
-
return function (_x5, _x6) {
|
|
120
|
+
return function (_x4, _x5) {
|
|
149
121
|
return _ref3.apply(this, arguments);
|
|
150
122
|
};
|
|
151
123
|
}();
|
|
152
124
|
}
|
|
153
|
-
|
|
154
125
|
}
|
|
155
|
-
|
|
156
|
-
exports.AppManager = AppManager;
|
|
157
|
-
(0, _utils().applyMixins)(AppManager, [_utils().AsyncEmitter]);
|
|
126
|
+
exports.AppManager = AppManager;
|