@nocobase/server 0.7.0-alpha.9 → 0.7.1-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 +37 -35
- package/lib/acl/index.js +45 -21
- package/lib/app-manager.d.ts +3 -3
- package/lib/app-manager.js +151 -72
- package/lib/application.d.ts +16 -4
- package/lib/application.js +414 -152
- package/lib/commands/console.d.ts +2 -3
- package/lib/commands/console.js +33 -24
- package/lib/commands/db-auth.d.ts +3 -0
- package/lib/commands/db-auth.js +26 -0
- package/lib/commands/db-clean.d.ts +3 -0
- package/lib/commands/db-clean.js +27 -0
- package/lib/commands/db-sync.d.ts +2 -4
- package/lib/commands/db-sync.js +25 -23
- package/lib/commands/index.d.ts +1 -2
- package/lib/commands/index.js +31 -29
- package/lib/commands/install.d.ts +2 -4
- package/lib/commands/install.js +66 -20
- package/lib/commands/migrator.d.ts +3 -0
- package/lib/commands/migrator.js +27 -0
- package/lib/commands/start.d.ts +2 -4
- package/lib/commands/start.js +28 -22
- package/lib/commands/upgrade.d.ts +6 -0
- package/lib/commands/upgrade.js +39 -0
- package/lib/helper.js +132 -61
- package/lib/index.d.ts +1 -0
- package/lib/index.js +100 -33
- package/lib/middlewares/data-wrapping.js +65 -55
- package/lib/middlewares/index.js +30 -14
- package/lib/middlewares/table2resource.js +89 -52
- package/lib/migration.d.ts +7 -0
- package/lib/migration.js +29 -0
- package/lib/plugin-manager.js +124 -55
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +67 -45
- package/lib/read-config.js +159 -64
- package/package.json +13 -14
- package/esm/acl/available-action.d.ts +0 -5
- package/esm/acl/available-action.js +0 -36
- package/esm/acl/available-action.js.map +0 -1
- package/esm/acl/index.d.ts +0 -2
- package/esm/acl/index.js +0 -19
- package/esm/acl/index.js.map +0 -1
- package/esm/app-manager.d.ts +0 -19
- package/esm/app-manager.js +0 -69
- package/esm/app-manager.js.map +0 -1
- package/esm/application.d.ts +0 -97
- package/esm/application.js +0 -156
- package/esm/application.js.map +0 -1
- package/esm/commands/console.d.ts +0 -4
- package/esm/commands/console.js +0 -25
- package/esm/commands/console.js.map +0 -1
- package/esm/commands/create-plugin/create-plugin.d.ts +0 -2
- package/esm/commands/create-plugin/create-plugin.js +0 -29
- package/esm/commands/create-plugin/create-plugin.js.map +0 -1
- package/esm/commands/create-plugin/index.d.ts +0 -5
- package/esm/commands/create-plugin/index.js +0 -6
- package/esm/commands/create-plugin/index.js.map +0 -1
- package/esm/commands/create-plugin/resources/templates/package-json.d.ts +0 -11
- package/esm/commands/create-plugin/resources/templates/package-json.js +0 -11
- package/esm/commands/create-plugin/resources/templates/package-json.js.map +0 -1
- package/esm/commands/create-plugin/resources/templates/plugin.d.ts +0 -4
- package/esm/commands/create-plugin/resources/templates/plugin.js +0 -12
- package/esm/commands/create-plugin/resources/templates/plugin.js.map +0 -1
- package/esm/commands/db-sync.d.ts +0 -5
- package/esm/commands/db-sync.js +0 -25
- package/esm/commands/db-sync.js.map +0 -1
- package/esm/commands/index.d.ts +0 -3
- package/esm/commands/index.js +0 -26
- package/esm/commands/index.js.map +0 -1
- package/esm/commands/install.d.ts +0 -5
- package/esm/commands/install.js +0 -23
- package/esm/commands/install.js.map +0 -1
- package/esm/commands/start.d.ts +0 -5
- package/esm/commands/start.js +0 -23
- package/esm/commands/start.js.map +0 -1
- package/esm/helper.d.ts +0 -7
- package/esm/helper.js +0 -59
- package/esm/helper.js.map +0 -1
- package/esm/index.d.ts +0 -7
- package/esm/index.js +0 -9
- package/esm/index.js.map +0 -1
- package/esm/middlewares/data-wrapping.d.ts +0 -3
- package/esm/middlewares/data-wrapping.js +0 -54
- package/esm/middlewares/data-wrapping.js.map +0 -1
- package/esm/middlewares/index.d.ts +0 -2
- package/esm/middlewares/index.js +0 -3
- package/esm/middlewares/index.js.map +0 -1
- package/esm/middlewares/table2resource.d.ts +0 -6
- package/esm/middlewares/table2resource.js +0 -51
- package/esm/middlewares/table2resource.js.map +0 -1
- package/esm/plugin-manager.d.ts +0 -23
- package/esm/plugin-manager.js +0 -57
- package/esm/plugin-manager.js.map +0 -1
- package/esm/plugin.d.ts +0 -32
- package/esm/plugin.js +0 -43
- package/esm/plugin.js.map +0 -1
- package/esm/read-config.d.ts +0 -8
- package/esm/read-config.js +0 -63
- package/esm/read-config.js.map +0 -1
- package/lib/acl/available-action.js.map +0 -1
- package/lib/acl/index.js.map +0 -1
- package/lib/app-manager.js.map +0 -1
- package/lib/application.js.map +0 -1
- package/lib/commands/console.js.map +0 -1
- package/lib/commands/create-plugin/create-plugin.d.ts +0 -2
- package/lib/commands/create-plugin/create-plugin.js +0 -31
- package/lib/commands/create-plugin/create-plugin.js.map +0 -1
- package/lib/commands/create-plugin/index.d.ts +0 -5
- package/lib/commands/create-plugin/index.js +0 -8
- package/lib/commands/create-plugin/index.js.map +0 -1
- package/lib/commands/create-plugin/resources/templates/package-json.d.ts +0 -11
- package/lib/commands/create-plugin/resources/templates/package-json.js +0 -13
- package/lib/commands/create-plugin/resources/templates/package-json.js.map +0 -1
- package/lib/commands/create-plugin/resources/templates/plugin.d.ts +0 -4
- package/lib/commands/create-plugin/resources/templates/plugin.js +0 -33
- package/lib/commands/create-plugin/resources/templates/plugin.js.map +0 -1
- package/lib/commands/db-sync.js.map +0 -1
- package/lib/commands/index.js.map +0 -1
- package/lib/commands/install.js.map +0 -1
- package/lib/commands/start.js.map +0 -1
- package/lib/helper.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/middlewares/data-wrapping.js.map +0 -1
- package/lib/middlewares/index.js.map +0 -1
- package/lib/middlewares/table2resource.js.map +0 -1
- package/lib/plugin-manager.js.map +0 -1
- package/lib/plugin.js.map +0 -1
- package/lib/read-config.js.map +0 -1
- package/tsconfig.build.json +0 -9
package/lib/application.js
CHANGED
|
@@ -1,163 +1,425 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.ApplicationVersion = exports.Application = void 0;
|
|
7
|
+
|
|
8
|
+
function _actions() {
|
|
9
|
+
const data = require("@nocobase/actions");
|
|
10
|
+
|
|
11
|
+
_actions = function _actions() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function _database() {
|
|
19
|
+
const data = _interopRequireDefault(require("@nocobase/database"));
|
|
20
|
+
|
|
21
|
+
_database = function _database() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _utils() {
|
|
29
|
+
const data = require("@nocobase/utils");
|
|
30
|
+
|
|
31
|
+
_utils = function _utils() {
|
|
32
|
+
return data;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function _commander() {
|
|
39
|
+
const data = require("commander");
|
|
40
|
+
|
|
41
|
+
_commander = function _commander() {
|
|
42
|
+
return data;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return data;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function _koa() {
|
|
49
|
+
const data = _interopRequireDefault(require("koa"));
|
|
50
|
+
|
|
51
|
+
_koa = function _koa() {
|
|
52
|
+
return data;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function _lodash() {
|
|
59
|
+
const data = require("lodash");
|
|
60
|
+
|
|
61
|
+
_lodash = function _lodash() {
|
|
62
|
+
return data;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function _semver() {
|
|
69
|
+
const data = _interopRequireDefault(require("semver"));
|
|
70
|
+
|
|
71
|
+
_semver = function _semver() {
|
|
72
|
+
return data;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return data;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var _acl = require("./acl");
|
|
79
|
+
|
|
80
|
+
var _appManager = require("./app-manager");
|
|
81
|
+
|
|
82
|
+
var _commands = require("./commands");
|
|
83
|
+
|
|
84
|
+
var _helper = require("./helper");
|
|
85
|
+
|
|
86
|
+
var _pluginManager = require("./plugin-manager");
|
|
87
|
+
|
|
88
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
89
|
+
|
|
90
|
+
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; } } }; }
|
|
91
|
+
|
|
92
|
+
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); }
|
|
93
|
+
|
|
94
|
+
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; }
|
|
95
|
+
|
|
96
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
97
|
+
|
|
98
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
99
|
+
|
|
100
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
101
|
+
|
|
102
|
+
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); } }
|
|
103
|
+
|
|
104
|
+
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); }); }; }
|
|
105
|
+
|
|
106
|
+
const packageJson = require('../package.json');
|
|
107
|
+
|
|
108
|
+
class ApplicationVersion {
|
|
109
|
+
constructor(app) {
|
|
110
|
+
this.app = void 0;
|
|
111
|
+
this.collection = void 0;
|
|
112
|
+
this.app = app;
|
|
113
|
+
|
|
114
|
+
if (!app.db.hasCollection('applicationVersion')) {
|
|
115
|
+
app.db.collection({
|
|
116
|
+
name: 'applicationVersion',
|
|
117
|
+
timestamps: false,
|
|
118
|
+
fields: [{
|
|
119
|
+
name: 'value',
|
|
120
|
+
type: 'string'
|
|
121
|
+
}]
|
|
122
|
+
});
|
|
44
123
|
}
|
|
45
|
-
|
|
46
|
-
|
|
124
|
+
|
|
125
|
+
this.collection = this.app.db.getCollection('applicationVersion');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
get() {
|
|
129
|
+
var _this = this;
|
|
130
|
+
|
|
131
|
+
return _asyncToGenerator(function* () {
|
|
132
|
+
if (yield _this.app.db.collectionExistsInDb('applicationVersion')) {
|
|
133
|
+
const model = yield _this.collection.model.findOne();
|
|
134
|
+
return model.get('value');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return null;
|
|
138
|
+
})();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
update() {
|
|
142
|
+
var _this2 = this;
|
|
143
|
+
|
|
144
|
+
return _asyncToGenerator(function* () {
|
|
145
|
+
yield _this2.collection.sync();
|
|
146
|
+
yield _this2.collection.model.destroy({
|
|
147
|
+
truncate: true
|
|
148
|
+
});
|
|
149
|
+
yield _this2.collection.model.create({
|
|
150
|
+
value: _this2.app.getVersion()
|
|
151
|
+
});
|
|
152
|
+
})();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
satisfies(range) {
|
|
156
|
+
var _this3 = this;
|
|
157
|
+
|
|
158
|
+
return _asyncToGenerator(function* () {
|
|
159
|
+
if (yield _this3.app.db.collectionExistsInDb('applicationVersion')) {
|
|
160
|
+
const model = yield _this3.collection.model.findOne();
|
|
161
|
+
const version = model.get('value');
|
|
162
|
+
return _semver().default.satisfies(version, range);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return true;
|
|
166
|
+
})();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
exports.ApplicationVersion = ApplicationVersion;
|
|
172
|
+
|
|
173
|
+
class Application extends _koa().default {
|
|
174
|
+
constructor(options) {
|
|
175
|
+
super();
|
|
176
|
+
this.options = void 0;
|
|
177
|
+
this.db = void 0;
|
|
178
|
+
this.resourcer = void 0;
|
|
179
|
+
this.cli = void 0;
|
|
180
|
+
this.i18n = void 0;
|
|
181
|
+
this.pm = void 0;
|
|
182
|
+
this.acl = void 0;
|
|
183
|
+
this.appManager = void 0;
|
|
184
|
+
this.version = void 0;
|
|
185
|
+
this.plugins = new Map();
|
|
186
|
+
this.listenServer = void 0;
|
|
187
|
+
this.options = options;
|
|
188
|
+
this.acl = (0, _acl.createACL)();
|
|
189
|
+
this.db = this.createDatabase(options);
|
|
190
|
+
this.resourcer = (0, _helper.createResourcer)(options);
|
|
191
|
+
this.cli = new (_commander().Command)('nocobase').usage('[command] [options]');
|
|
192
|
+
this.i18n = (0, _helper.createI18n)(options);
|
|
193
|
+
this.pm = new _pluginManager.PluginManager({
|
|
194
|
+
app: this
|
|
195
|
+
});
|
|
196
|
+
this.appManager = new _appManager.AppManager(this);
|
|
197
|
+
(0, _helper.registerMiddlewares)(this, options);
|
|
198
|
+
|
|
199
|
+
if (options.registerActions !== false) {
|
|
200
|
+
(0, _actions().registerActions)(this);
|
|
47
201
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
202
|
+
|
|
203
|
+
this.loadPluginConfig(options.plugins || []);
|
|
204
|
+
(0, _commands.registerCli)(this);
|
|
205
|
+
this.version = new ApplicationVersion(this);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
createDatabase(options) {
|
|
209
|
+
if (options.database instanceof _database().default) {
|
|
210
|
+
return options.database;
|
|
211
|
+
} else {
|
|
212
|
+
return new (_database().default)(_objectSpread(_objectSpread({}, options.database), {}, {
|
|
213
|
+
migrator: {
|
|
214
|
+
context: {
|
|
215
|
+
app: this
|
|
216
|
+
}
|
|
56
217
|
}
|
|
218
|
+
}));
|
|
57
219
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
start(options) {
|
|
92
|
-
var _a;
|
|
93
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
// reconnect database
|
|
95
|
-
if (this.db.closed()) {
|
|
96
|
-
yield this.db.reconnect();
|
|
97
|
-
}
|
|
98
|
-
yield this.emitAsync('beforeStart', this, options);
|
|
99
|
-
if ((_a = options === null || options === void 0 ? void 0 : options.listen) === null || _a === void 0 ? void 0 : _a.port) {
|
|
100
|
-
const listen = () => new Promise((resolve) => {
|
|
101
|
-
const Server = this.listen(options === null || options === void 0 ? void 0 : options.listen, () => {
|
|
102
|
-
resolve(Server);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
// @ts-ignore
|
|
106
|
-
this.listenServer = yield listen();
|
|
107
|
-
}
|
|
108
|
-
yield this.emitAsync('afterStart', this, options);
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
listen(...args) {
|
|
112
|
-
return this.appManager.listen(...args);
|
|
113
|
-
}
|
|
114
|
-
stop(options) {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
yield this.emitAsync('beforeStop', this, options);
|
|
117
|
-
try {
|
|
118
|
-
// close database connection
|
|
119
|
-
// silent if database already closed
|
|
120
|
-
yield this.db.close();
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
console.log(e);
|
|
124
|
-
}
|
|
125
|
-
// close http server
|
|
126
|
-
if (this.listenServer) {
|
|
127
|
-
const closeServer = () => new Promise((resolve, reject) => {
|
|
128
|
-
this.listenServer.close((err) => {
|
|
129
|
-
if (err) {
|
|
130
|
-
return reject(err);
|
|
131
|
-
}
|
|
132
|
-
this.listenServer = null;
|
|
133
|
-
resolve(true);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
yield closeServer();
|
|
137
|
-
}
|
|
138
|
-
yield this.emitAsync('afterStop', this, options);
|
|
139
|
-
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
getVersion() {
|
|
223
|
+
return packageJson.version;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
plugin(pluginClass, options) {
|
|
227
|
+
return this.pm.add(pluginClass, options);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
loadPluginConfig(pluginsConfigurations) {
|
|
231
|
+
var _iterator = _createForOfIteratorHelper(pluginsConfigurations),
|
|
232
|
+
_step;
|
|
233
|
+
|
|
234
|
+
try {
|
|
235
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
236
|
+
let pluginConfiguration = _step.value;
|
|
237
|
+
|
|
238
|
+
if (typeof pluginConfiguration == 'string') {
|
|
239
|
+
pluginConfiguration = [pluginConfiguration, {}];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const plugin = _pluginManager.PluginManager.resolvePlugin(pluginConfiguration[0]);
|
|
243
|
+
|
|
244
|
+
const pluginOptions = pluginConfiguration[1];
|
|
245
|
+
this.plugin(plugin, pluginOptions);
|
|
246
|
+
}
|
|
247
|
+
} catch (err) {
|
|
248
|
+
_iterator.e(err);
|
|
249
|
+
} finally {
|
|
250
|
+
_iterator.f();
|
|
140
251
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
use(middleware, options) {
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
return super.use(middleware);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
collection(options) {
|
|
260
|
+
return this.db.collection(options);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
resource(options) {
|
|
264
|
+
return this.resourcer.define(options);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
actions(handlers, options) {
|
|
268
|
+
return this.resourcer.registerActions(handlers);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
command(name, desc, opts) {
|
|
272
|
+
return this.cli.command(name, desc, opts).allowUnknownOption();
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
findCommand(name) {
|
|
276
|
+
return this.cli._findCommand(name);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
load() {
|
|
280
|
+
var _this4 = this;
|
|
281
|
+
|
|
282
|
+
return _asyncToGenerator(function* () {
|
|
283
|
+
yield _this4.pm.load();
|
|
284
|
+
})();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
getPlugin(name) {
|
|
288
|
+
return this.pm.get(name);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
parse(argv = process.argv) {
|
|
292
|
+
var _this5 = this;
|
|
293
|
+
|
|
294
|
+
return _asyncToGenerator(function* () {
|
|
295
|
+
yield _this5.load();
|
|
296
|
+
return _this5.cli.parseAsync(argv);
|
|
297
|
+
})();
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
start(options = {}) {
|
|
301
|
+
var _this6 = this;
|
|
302
|
+
|
|
303
|
+
return _asyncToGenerator(function* () {
|
|
304
|
+
var _options$listen;
|
|
305
|
+
|
|
306
|
+
// reconnect database
|
|
307
|
+
if (_this6.db.closed()) {
|
|
308
|
+
yield _this6.db.reconnect();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
yield _this6.emitAsync('beforeStart', _this6, options);
|
|
312
|
+
|
|
313
|
+
if (options === null || options === void 0 ? void 0 : (_options$listen = options.listen) === null || _options$listen === void 0 ? void 0 : _options$listen.port) {
|
|
314
|
+
const listen = () => new Promise((resolve, reject) => {
|
|
315
|
+
const Server = _this6.listen(options === null || options === void 0 ? void 0 : options.listen, () => {
|
|
316
|
+
resolve(Server);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
Server.on('error', err => {
|
|
320
|
+
reject(err);
|
|
321
|
+
});
|
|
146
322
|
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
323
|
+
|
|
324
|
+
try {
|
|
325
|
+
//@ts-ignore
|
|
326
|
+
_this6.listenServer = yield listen();
|
|
327
|
+
} catch (e) {
|
|
328
|
+
console.error(e);
|
|
329
|
+
process.exit(1);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
yield _this6.emitAsync('afterStart', _this6, options);
|
|
334
|
+
})();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
listen(...args) {
|
|
338
|
+
return this.appManager.listen(...args);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
stop(options = {}) {
|
|
342
|
+
var _this7 = this;
|
|
343
|
+
|
|
344
|
+
return _asyncToGenerator(function* () {
|
|
345
|
+
yield _this7.emitAsync('beforeStop', _this7, options);
|
|
346
|
+
|
|
347
|
+
try {
|
|
348
|
+
// close database connection
|
|
349
|
+
// silent if database already closed
|
|
350
|
+
yield _this7.db.close();
|
|
351
|
+
} catch (e) {
|
|
352
|
+
console.log(e);
|
|
353
|
+
} // close http server
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
if (_this7.listenServer) {
|
|
357
|
+
const closeServer = () => new Promise((resolve, reject) => {
|
|
358
|
+
_this7.listenServer.close(err => {
|
|
359
|
+
if (err) {
|
|
360
|
+
return reject(err);
|
|
153
361
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
362
|
+
|
|
363
|
+
_this7.listenServer = null;
|
|
364
|
+
resolve(true);
|
|
365
|
+
});
|
|
157
366
|
});
|
|
158
|
-
|
|
367
|
+
|
|
368
|
+
yield closeServer();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
yield _this7.emitAsync('afterStop', _this7, options);
|
|
372
|
+
})();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
destroy(options = {}) {
|
|
376
|
+
var _this8 = this;
|
|
377
|
+
|
|
378
|
+
return _asyncToGenerator(function* () {
|
|
379
|
+
yield _this8.emitAsync('beforeDestroy', _this8, options);
|
|
380
|
+
yield _this8.stop(options);
|
|
381
|
+
yield _this8.emitAsync('afterDestroy', _this8, options);
|
|
382
|
+
})();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
install(options = {}) {
|
|
386
|
+
var _this9 = this;
|
|
387
|
+
|
|
388
|
+
return _asyncToGenerator(function* () {
|
|
389
|
+
yield _this9.emitAsync('beforeInstall', _this9, options);
|
|
390
|
+
|
|
391
|
+
if (options === null || options === void 0 ? void 0 : options.clean) {
|
|
392
|
+
yield _this9.db.clean((0, _lodash().isBoolean)(options.clean) ? {
|
|
393
|
+
drop: options.clean
|
|
394
|
+
} : options.clean);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
yield _this9.db.sync(options === null || options === void 0 ? void 0 : options.sync);
|
|
398
|
+
yield _this9.pm.install(options);
|
|
399
|
+
yield _this9.version.update();
|
|
400
|
+
yield _this9.emitAsync('afterInstall', _this9, options);
|
|
401
|
+
})();
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
upgrade(options = {}) {
|
|
405
|
+
var _this10 = this;
|
|
406
|
+
|
|
407
|
+
return _asyncToGenerator(function* () {
|
|
408
|
+
const force = false;
|
|
409
|
+
yield _this10.db.migrator.up();
|
|
410
|
+
yield _this10.db.sync({
|
|
411
|
+
force,
|
|
412
|
+
alter: {
|
|
413
|
+
drop: force
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
yield _this10.version.update();
|
|
417
|
+
})();
|
|
418
|
+
}
|
|
419
|
+
|
|
159
420
|
}
|
|
421
|
+
|
|
160
422
|
exports.Application = Application;
|
|
161
|
-
(0,
|
|
162
|
-
|
|
163
|
-
|
|
423
|
+
(0, _utils().applyMixins)(Application, [_utils().AsyncEmitter]);
|
|
424
|
+
var _default = Application;
|
|
425
|
+
exports.default = _default;
|
package/lib/commands/console.js
CHANGED
|
@@ -1,27 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
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); } }
|
|
9
|
+
|
|
10
|
+
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); }); }; }
|
|
11
|
+
|
|
12
12
|
const REPL = require('repl');
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
var _default = app => {
|
|
15
|
+
app.command('console').action( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
14
16
|
yield app.start();
|
|
15
|
-
const repl =
|
|
16
|
-
repl.on('exit', function (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
const repl = REPL.start('nocobase > ').context.app = app;
|
|
18
|
+
repl.on('exit', /*#__PURE__*/function () {
|
|
19
|
+
var _ref2 = _asyncToGenerator(function* (err) {
|
|
20
|
+
if (err) {
|
|
21
|
+
console.log(err);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
yield app.stop();
|
|
26
|
+
process.exit(0);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return function (_x) {
|
|
30
|
+
return _ref2.apply(this, arguments);
|
|
31
|
+
};
|
|
32
|
+
}());
|
|
33
|
+
}));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.default = _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
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); } }
|
|
9
|
+
|
|
10
|
+
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); }); }; }
|
|
11
|
+
|
|
12
|
+
var _default = app => {
|
|
13
|
+
app.command('db:auth').option('-r, --retry [retry]').action( /*#__PURE__*/function () {
|
|
14
|
+
var _ref = _asyncToGenerator(function* (opts) {
|
|
15
|
+
yield app.db.auth({
|
|
16
|
+
retry: opts.retry || 10
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return function (_x) {
|
|
21
|
+
return _ref.apply(this, arguments);
|
|
22
|
+
};
|
|
23
|
+
}());
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.default = _default;
|