@nocobase/server 0.9.1-alpha.1 → 0.9.2-alpha.1
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.d.ts +1 -0
- package/lib/application.js +35 -170
- 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} +3 -2
- package/lib/plugin-manager/{PluginManager.js → plugin-manager.js} +140 -242
- 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/application.js
CHANGED
|
@@ -4,151 +4,106 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.ApplicationVersion = exports.Application = void 0;
|
|
7
|
-
|
|
8
7
|
function _actions() {
|
|
9
8
|
const data = require("@nocobase/actions");
|
|
10
|
-
|
|
11
9
|
_actions = function _actions() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _cache() {
|
|
19
15
|
const data = require("@nocobase/cache");
|
|
20
|
-
|
|
21
16
|
_cache = function _cache() {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _database() {
|
|
29
22
|
const data = _interopRequireDefault(require("@nocobase/database"));
|
|
30
|
-
|
|
31
23
|
_database = function _database() {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _logger() {
|
|
39
29
|
const data = require("@nocobase/logger");
|
|
40
|
-
|
|
41
30
|
_logger = function _logger() {
|
|
42
31
|
return data;
|
|
43
32
|
};
|
|
44
|
-
|
|
45
33
|
return data;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
function _utils() {
|
|
49
36
|
const data = require("@nocobase/utils");
|
|
50
|
-
|
|
51
37
|
_utils = function _utils() {
|
|
52
38
|
return data;
|
|
53
39
|
};
|
|
54
|
-
|
|
55
40
|
return data;
|
|
56
41
|
}
|
|
57
|
-
|
|
58
42
|
function _chalk() {
|
|
59
43
|
const data = _interopRequireDefault(require("chalk"));
|
|
60
|
-
|
|
61
44
|
_chalk = function _chalk() {
|
|
62
45
|
return data;
|
|
63
46
|
};
|
|
64
|
-
|
|
65
47
|
return data;
|
|
66
48
|
}
|
|
67
|
-
|
|
68
49
|
function _commander() {
|
|
69
50
|
const data = require("commander");
|
|
70
|
-
|
|
71
51
|
_commander = function _commander() {
|
|
72
52
|
return data;
|
|
73
53
|
};
|
|
74
|
-
|
|
75
54
|
return data;
|
|
76
55
|
}
|
|
77
|
-
|
|
78
56
|
function _koa() {
|
|
79
57
|
const data = _interopRequireDefault(require("koa"));
|
|
80
|
-
|
|
81
58
|
_koa = function _koa() {
|
|
82
59
|
return data;
|
|
83
60
|
};
|
|
84
|
-
|
|
85
61
|
return data;
|
|
86
62
|
}
|
|
87
|
-
|
|
88
63
|
function _koaCompose() {
|
|
89
64
|
const data = _interopRequireDefault(require("koa-compose"));
|
|
90
|
-
|
|
91
65
|
_koaCompose = function _koaCompose() {
|
|
92
66
|
return data;
|
|
93
67
|
};
|
|
94
|
-
|
|
95
68
|
return data;
|
|
96
69
|
}
|
|
97
|
-
|
|
98
70
|
function _semver() {
|
|
99
71
|
const data = _interopRequireDefault(require("semver"));
|
|
100
|
-
|
|
101
72
|
_semver = function _semver() {
|
|
102
73
|
return data;
|
|
103
74
|
};
|
|
104
|
-
|
|
105
75
|
return data;
|
|
106
76
|
}
|
|
107
|
-
|
|
108
77
|
function _util() {
|
|
109
78
|
const data = require("util");
|
|
110
|
-
|
|
111
79
|
_util = function _util() {
|
|
112
80
|
return data;
|
|
113
81
|
};
|
|
114
|
-
|
|
115
82
|
return data;
|
|
116
83
|
}
|
|
117
|
-
|
|
118
84
|
var _acl = require("./acl");
|
|
119
|
-
|
|
120
85
|
var _appManager = require("./app-manager");
|
|
121
|
-
|
|
122
86
|
var _commands = require("./commands");
|
|
123
|
-
|
|
124
87
|
var _helper = require("./helper");
|
|
125
|
-
|
|
126
88
|
var _pluginManager = require("./plugin-manager");
|
|
127
|
-
|
|
128
89
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
129
|
-
|
|
130
90
|
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; }
|
|
131
|
-
|
|
132
91
|
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; }
|
|
133
|
-
|
|
134
|
-
function
|
|
135
|
-
|
|
92
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
93
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
94
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
136
95
|
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); } }
|
|
137
|
-
|
|
138
96
|
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); }); }; }
|
|
139
|
-
|
|
140
97
|
const packageJson = require('../package.json');
|
|
141
|
-
|
|
142
98
|
class ApplicationVersion {
|
|
143
99
|
constructor(app) {
|
|
144
100
|
this.app = void 0;
|
|
145
101
|
this.collection = void 0;
|
|
146
102
|
this.app = app;
|
|
147
|
-
|
|
148
103
|
if (!app.db.hasCollection('applicationVersion')) {
|
|
149
104
|
app.db.collection({
|
|
150
105
|
name: 'applicationVersion',
|
|
151
|
-
namespace: 'core',
|
|
106
|
+
namespace: 'core.applicationVersion',
|
|
152
107
|
duplicator: 'required',
|
|
153
108
|
timestamps: false,
|
|
154
109
|
fields: [{
|
|
@@ -157,31 +112,23 @@ class ApplicationVersion {
|
|
|
157
112
|
}]
|
|
158
113
|
});
|
|
159
114
|
}
|
|
160
|
-
|
|
161
115
|
this.collection = this.app.db.getCollection('applicationVersion');
|
|
162
116
|
}
|
|
163
|
-
|
|
164
117
|
get() {
|
|
165
118
|
var _this = this;
|
|
166
|
-
|
|
167
119
|
return _asyncToGenerator(function* () {
|
|
168
120
|
if (yield _this.app.db.collectionExistsInDb('applicationVersion')) {
|
|
169
121
|
const model = yield _this.collection.model.findOne();
|
|
170
|
-
|
|
171
122
|
if (!model) {
|
|
172
123
|
return null;
|
|
173
124
|
}
|
|
174
|
-
|
|
175
125
|
return model.get('value');
|
|
176
126
|
}
|
|
177
|
-
|
|
178
127
|
return null;
|
|
179
128
|
})();
|
|
180
129
|
}
|
|
181
|
-
|
|
182
130
|
update() {
|
|
183
131
|
var _this2 = this;
|
|
184
|
-
|
|
185
132
|
return _asyncToGenerator(function* () {
|
|
186
133
|
yield _this2.collection.sync();
|
|
187
134
|
yield _this2.collection.model.destroy({
|
|
@@ -192,32 +139,24 @@ class ApplicationVersion {
|
|
|
192
139
|
});
|
|
193
140
|
})();
|
|
194
141
|
}
|
|
195
|
-
|
|
196
142
|
satisfies(range) {
|
|
197
143
|
var _this3 = this;
|
|
198
|
-
|
|
199
144
|
return _asyncToGenerator(function* () {
|
|
200
145
|
if (yield _this3.app.db.collectionExistsInDb('applicationVersion')) {
|
|
201
146
|
const model = yield _this3.collection.model.findOne();
|
|
202
147
|
const version = model === null || model === void 0 ? void 0 : model.value;
|
|
203
|
-
|
|
204
148
|
if (!version) {
|
|
205
149
|
return true;
|
|
206
150
|
}
|
|
207
|
-
|
|
208
151
|
return _semver().default.satisfies(version, range, {
|
|
209
152
|
includePrerelease: true
|
|
210
153
|
});
|
|
211
154
|
}
|
|
212
|
-
|
|
213
155
|
return true;
|
|
214
156
|
})();
|
|
215
157
|
}
|
|
216
|
-
|
|
217
158
|
}
|
|
218
|
-
|
|
219
159
|
exports.ApplicationVersion = ApplicationVersion;
|
|
220
|
-
|
|
221
160
|
class Application extends _koa().default {
|
|
222
161
|
constructor(options) {
|
|
223
162
|
super();
|
|
@@ -234,65 +173,53 @@ class Application extends _koa().default {
|
|
|
234
173
|
this._version = void 0;
|
|
235
174
|
this.plugins = new Map();
|
|
236
175
|
this.listenServer = void 0;
|
|
176
|
+
this.stopped = false;
|
|
237
177
|
this.options = options;
|
|
238
178
|
this.init();
|
|
239
179
|
}
|
|
240
|
-
|
|
241
180
|
get db() {
|
|
242
181
|
return this._db;
|
|
243
182
|
}
|
|
244
|
-
|
|
245
183
|
get cache() {
|
|
246
184
|
return this._cache;
|
|
247
185
|
}
|
|
248
|
-
|
|
249
186
|
get resourcer() {
|
|
250
187
|
return this._resourcer;
|
|
251
188
|
}
|
|
252
|
-
|
|
253
189
|
get cli() {
|
|
254
190
|
return this._cli;
|
|
255
191
|
}
|
|
256
|
-
|
|
257
192
|
get acl() {
|
|
258
193
|
return this._acl;
|
|
259
194
|
}
|
|
260
|
-
|
|
261
195
|
get i18n() {
|
|
262
196
|
return this._i18n;
|
|
263
197
|
}
|
|
264
|
-
|
|
265
198
|
get pm() {
|
|
266
199
|
return this._pm;
|
|
267
200
|
}
|
|
268
|
-
|
|
269
201
|
get version() {
|
|
270
202
|
return this._version;
|
|
271
203
|
}
|
|
272
|
-
|
|
273
204
|
get appManager() {
|
|
274
205
|
return this._appManager;
|
|
275
206
|
}
|
|
276
|
-
|
|
277
207
|
get logger() {
|
|
278
208
|
return this._logger;
|
|
279
209
|
}
|
|
280
|
-
|
|
281
210
|
get log() {
|
|
282
211
|
return this._logger;
|
|
283
212
|
}
|
|
284
|
-
|
|
285
213
|
get name() {
|
|
286
214
|
return this.options.name || 'main';
|
|
287
215
|
}
|
|
288
|
-
|
|
289
216
|
init() {
|
|
290
217
|
const options = this.options;
|
|
291
218
|
const logger = (0, _logger().createAppLogger)(options.logger);
|
|
292
|
-
this._logger = logger.instance;
|
|
293
|
-
|
|
294
|
-
this._events = [];
|
|
295
|
-
|
|
219
|
+
this._logger = logger.instance;
|
|
220
|
+
// @ts-ignore
|
|
221
|
+
this._events = [];
|
|
222
|
+
// @ts-ignore
|
|
296
223
|
this._eventsCount = [];
|
|
297
224
|
this.removeAllListeners();
|
|
298
225
|
this.middleware = new (_utils().Toposort)();
|
|
@@ -301,12 +228,10 @@ class Application extends _koa().default {
|
|
|
301
228
|
this.use(logger.middleware, {
|
|
302
229
|
tag: 'logger'
|
|
303
230
|
});
|
|
304
|
-
|
|
305
231
|
if (this._db) {
|
|
306
232
|
// MaxListenersExceededWarning
|
|
307
233
|
this._db.removeAllListeners();
|
|
308
234
|
}
|
|
309
|
-
|
|
310
235
|
this._db = this.createDatabase(options);
|
|
311
236
|
this._resourcer = (0, _helper.createResourcer)(options);
|
|
312
237
|
this._cli = new (_commander().Command)('nocobase').usage('[command] [options]');
|
|
@@ -316,7 +241,6 @@ class Application extends _koa().default {
|
|
|
316
241
|
this.context.logger = this._logger;
|
|
317
242
|
this.context.resourcer = this._resourcer;
|
|
318
243
|
this.context.cache = this._cache;
|
|
319
|
-
|
|
320
244
|
if (this._pm) {
|
|
321
245
|
this._pm = this._pm.clone();
|
|
322
246
|
} else {
|
|
@@ -325,127 +249,105 @@ class Application extends _koa().default {
|
|
|
325
249
|
plugins: options.plugins
|
|
326
250
|
});
|
|
327
251
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
252
|
+
if (this._appManager) {
|
|
253
|
+
this._appManager.bindMainApplication(this);
|
|
254
|
+
} else {
|
|
255
|
+
this._appManager = new _appManager.AppManager(this);
|
|
256
|
+
}
|
|
331
257
|
if (this.options.acl !== false) {
|
|
332
258
|
this._resourcer.use(this._acl.middleware(), {
|
|
333
259
|
tag: 'acl',
|
|
334
260
|
after: ['parseToken']
|
|
335
261
|
});
|
|
336
262
|
}
|
|
337
|
-
|
|
338
263
|
(0, _helper.registerMiddlewares)(this, options);
|
|
339
|
-
|
|
340
264
|
if (options.registerActions !== false) {
|
|
341
265
|
(0, _actions().registerActions)(this);
|
|
342
266
|
}
|
|
343
|
-
|
|
344
267
|
(0, _commands.registerCli)(this);
|
|
345
268
|
this._version = new ApplicationVersion(this);
|
|
346
269
|
}
|
|
347
|
-
|
|
348
270
|
createDatabase(options) {
|
|
349
|
-
|
|
271
|
+
const db = new (_database().default)(_objectSpread(_objectSpread({}, options.database instanceof _database().default ? options.database.options : options.database), {}, {
|
|
350
272
|
migrator: {
|
|
351
273
|
context: {
|
|
352
274
|
app: this
|
|
353
275
|
}
|
|
354
276
|
}
|
|
355
277
|
}));
|
|
278
|
+
db.setLogger(this._logger);
|
|
279
|
+
return db;
|
|
356
280
|
}
|
|
357
|
-
|
|
358
281
|
getVersion() {
|
|
359
282
|
return packageJson.version;
|
|
360
283
|
}
|
|
361
|
-
|
|
362
284
|
plugin(pluginClass, options) {
|
|
363
285
|
return this.pm.addStatic(pluginClass, options);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
|
|
286
|
+
}
|
|
287
|
+
// @ts-ignore
|
|
367
288
|
use(middleware, options) {
|
|
368
289
|
this.middleware.add(middleware, options);
|
|
369
290
|
return this;
|
|
370
291
|
}
|
|
371
|
-
|
|
372
292
|
callback() {
|
|
373
293
|
const fn = (0, _koaCompose().default)(this.middleware.nodes);
|
|
374
294
|
if (!this.listenerCount('error')) this.on('error', this.onerror);
|
|
375
|
-
|
|
376
295
|
const handleRequest = (req, res) => {
|
|
377
|
-
const ctx = this.createContext(req, res);
|
|
378
|
-
|
|
296
|
+
const ctx = this.createContext(req, res);
|
|
297
|
+
// @ts-ignore
|
|
379
298
|
return this.handleRequest(ctx, fn);
|
|
380
299
|
};
|
|
381
|
-
|
|
382
300
|
return handleRequest;
|
|
383
301
|
}
|
|
384
|
-
|
|
385
302
|
collection(options) {
|
|
386
303
|
return this.db.collection(options);
|
|
387
304
|
}
|
|
388
|
-
|
|
389
305
|
resource(options) {
|
|
390
306
|
return this.resourcer.define(options);
|
|
391
307
|
}
|
|
392
|
-
|
|
393
308
|
actions(handlers, options) {
|
|
394
309
|
return this.resourcer.registerActions(handlers);
|
|
395
310
|
}
|
|
396
|
-
|
|
397
311
|
command(name, desc, opts) {
|
|
398
312
|
return this.cli.command(name, desc, opts).allowUnknownOption();
|
|
399
313
|
}
|
|
400
|
-
|
|
401
314
|
findCommand(name) {
|
|
402
315
|
return this.cli._findCommand(name);
|
|
403
316
|
}
|
|
404
|
-
|
|
405
317
|
load(options) {
|
|
406
318
|
var _this4 = this;
|
|
407
|
-
|
|
408
319
|
return _asyncToGenerator(function* () {
|
|
409
320
|
if (options === null || options === void 0 ? void 0 : options.reload) {
|
|
410
|
-
console.log(`Reload the application configuration`);
|
|
321
|
+
console.log(`Reload the ${_this4.name} application configuration`);
|
|
411
322
|
const oldDb = _this4._db;
|
|
412
|
-
|
|
413
323
|
_this4.init();
|
|
414
|
-
|
|
415
324
|
yield oldDb.close();
|
|
416
325
|
}
|
|
417
|
-
|
|
418
326
|
yield _this4.emitAsync('beforeLoad', _this4, options);
|
|
419
327
|
yield _this4.pm.load(options);
|
|
420
328
|
yield _this4.emitAsync('afterLoad', _this4, options);
|
|
421
329
|
})();
|
|
422
330
|
}
|
|
423
|
-
|
|
424
331
|
reload(options) {
|
|
425
332
|
var _this5 = this;
|
|
426
|
-
|
|
427
333
|
return _asyncToGenerator(function* () {
|
|
428
334
|
yield _this5.load(_objectSpread(_objectSpread({}, options), {}, {
|
|
429
335
|
reload: true
|
|
430
336
|
}));
|
|
337
|
+
yield _this5.emitAsync('afterReload', _this5, options);
|
|
431
338
|
})();
|
|
432
339
|
}
|
|
433
|
-
|
|
434
340
|
getPlugin(name) {
|
|
435
341
|
return this.pm.get(name);
|
|
436
342
|
}
|
|
437
|
-
|
|
438
343
|
parse(argv = process.argv) {
|
|
439
344
|
var _this6 = this;
|
|
440
|
-
|
|
441
345
|
return _asyncToGenerator(function* () {
|
|
442
346
|
return _this6.runAsCLI(argv);
|
|
443
347
|
})();
|
|
444
348
|
}
|
|
445
|
-
|
|
446
349
|
runAsCLI(argv = process.argv, options) {
|
|
447
350
|
var _this7 = this;
|
|
448
|
-
|
|
449
351
|
return _asyncToGenerator(function* () {
|
|
450
352
|
try {
|
|
451
353
|
yield _this7.db.auth({
|
|
@@ -455,48 +357,36 @@ class Application extends _koa().default {
|
|
|
455
357
|
console.log(_chalk().default.red(error.message));
|
|
456
358
|
process.exit(1);
|
|
457
359
|
}
|
|
458
|
-
|
|
459
360
|
yield _this7.dbVersionCheck({
|
|
460
361
|
exit: true
|
|
461
362
|
});
|
|
462
363
|
yield _this7.db.prepare();
|
|
463
|
-
|
|
464
364
|
if ((argv === null || argv === void 0 ? void 0 : argv[2]) !== 'upgrade') {
|
|
465
365
|
yield _this7.load({
|
|
466
366
|
method: argv === null || argv === void 0 ? void 0 : argv[2]
|
|
467
367
|
});
|
|
468
368
|
}
|
|
469
|
-
|
|
470
369
|
return _this7.cli.parseAsync(argv, options);
|
|
471
370
|
})();
|
|
472
371
|
}
|
|
473
|
-
|
|
474
372
|
start(options = {}) {
|
|
475
373
|
var _this8 = this;
|
|
476
|
-
|
|
477
374
|
return _asyncToGenerator(function* () {
|
|
478
375
|
var _options$listen;
|
|
479
|
-
|
|
480
|
-
// reconnect database
|
|
481
376
|
if (_this8.db.closed()) {
|
|
482
377
|
yield _this8.db.reconnect();
|
|
483
378
|
}
|
|
484
|
-
|
|
485
379
|
if (options.dbSync) {
|
|
486
380
|
console.log('db sync...');
|
|
487
381
|
yield _this8.db.sync();
|
|
488
382
|
}
|
|
489
|
-
|
|
490
383
|
yield _this8.emitAsync('beforeStart', _this8, options);
|
|
491
|
-
|
|
492
384
|
if (options === null || options === void 0 ? void 0 : (_options$listen = options.listen) === null || _options$listen === void 0 ? void 0 : _options$listen.port) {
|
|
493
385
|
const pmServer = yield _this8.pm.listen();
|
|
494
|
-
|
|
495
386
|
const listen = () => new Promise((resolve, reject) => {
|
|
496
387
|
const Server = _this8.listen(options === null || options === void 0 ? void 0 : options.listen, () => {
|
|
497
388
|
resolve(Server);
|
|
498
389
|
});
|
|
499
|
-
|
|
500
390
|
Server.on('error', err => {
|
|
501
391
|
reject(err);
|
|
502
392
|
});
|
|
@@ -504,7 +394,6 @@ class Application extends _koa().default {
|
|
|
504
394
|
pmServer.close();
|
|
505
395
|
});
|
|
506
396
|
});
|
|
507
|
-
|
|
508
397
|
try {
|
|
509
398
|
//@ts-ignore
|
|
510
399
|
_this8.listenServer = yield listen();
|
|
@@ -513,21 +402,26 @@ class Application extends _koa().default {
|
|
|
513
402
|
process.exit(1);
|
|
514
403
|
}
|
|
515
404
|
}
|
|
516
|
-
|
|
517
405
|
yield _this8.emitAsync('afterStart', _this8, options);
|
|
406
|
+
_this8.stopped = false;
|
|
518
407
|
})();
|
|
519
408
|
}
|
|
520
|
-
|
|
521
409
|
listen(...args) {
|
|
522
410
|
return this.appManager.listen(...args);
|
|
523
411
|
}
|
|
524
|
-
|
|
525
412
|
stop(options = {}) {
|
|
526
413
|
var _this9 = this;
|
|
527
|
-
|
|
528
414
|
return _asyncToGenerator(function* () {
|
|
415
|
+
if (_this9.stopped) {
|
|
416
|
+
_this9.log.warn(`Application ${_this9.name} already stopped`);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
529
419
|
yield _this9.emitAsync('beforeStop', _this9, options);
|
|
530
|
-
|
|
420
|
+
// close http server
|
|
421
|
+
if (_this9.listenServer) {
|
|
422
|
+
yield (0, _util().promisify)(_this9.listenServer.close).call(_this9.listenServer);
|
|
423
|
+
_this9.listenServer = null;
|
|
424
|
+
}
|
|
531
425
|
try {
|
|
532
426
|
// close database connection
|
|
533
427
|
// silent if database already closed
|
|
@@ -536,84 +430,61 @@ class Application extends _koa().default {
|
|
|
536
430
|
}
|
|
537
431
|
} catch (e) {
|
|
538
432
|
console.log(e);
|
|
539
|
-
} // close http server
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
if (_this9.listenServer) {
|
|
543
|
-
yield (0, _util().promisify)(_this9.listenServer.close).call(_this9.listenServer);
|
|
544
|
-
_this9.listenServer = null;
|
|
545
433
|
}
|
|
546
|
-
|
|
547
434
|
yield _this9.emitAsync('afterStop', _this9, options);
|
|
435
|
+
_this9.stopped = true;
|
|
436
|
+
console.log(`${_this9.name} is stopped`);
|
|
548
437
|
})();
|
|
549
438
|
}
|
|
550
|
-
|
|
551
439
|
destroy(options = {}) {
|
|
552
440
|
var _this10 = this;
|
|
553
|
-
|
|
554
441
|
return _asyncToGenerator(function* () {
|
|
555
442
|
yield _this10.emitAsync('beforeDestroy', _this10, options);
|
|
556
443
|
yield _this10.stop(options);
|
|
557
444
|
yield _this10.emitAsync('afterDestroy', _this10, options);
|
|
558
445
|
})();
|
|
559
446
|
}
|
|
560
|
-
|
|
561
447
|
dbVersionCheck(options) {
|
|
562
448
|
var _this11 = this;
|
|
563
|
-
|
|
564
449
|
return _asyncToGenerator(function* () {
|
|
565
450
|
const r = yield _this11.db.version.satisfies({
|
|
566
451
|
mysql: '>=8.0.17',
|
|
567
452
|
sqlite: '3.x',
|
|
568
453
|
postgres: '>=10'
|
|
569
454
|
});
|
|
570
|
-
|
|
571
455
|
if (!r) {
|
|
572
456
|
console.log(_chalk().default.red('The database only supports MySQL 8.0.17 and above, SQLite 3.x and PostgreSQL 10+'));
|
|
573
|
-
|
|
574
457
|
if (options === null || options === void 0 ? void 0 : options.exit) {
|
|
575
458
|
process.exit();
|
|
576
459
|
}
|
|
577
|
-
|
|
578
460
|
return false;
|
|
579
461
|
}
|
|
580
|
-
|
|
581
462
|
if (_this11.db.inDialect('mysql')) {
|
|
582
463
|
const result = yield _this11.db.sequelize.query(`SHOW VARIABLES LIKE 'lower_case_table_names'`, {
|
|
583
464
|
plain: true
|
|
584
465
|
});
|
|
585
|
-
|
|
586
466
|
if ((result === null || result === void 0 ? void 0 : result.Value) === '1' && !_this11.db.options.underscored) {
|
|
587
467
|
console.log(`Your database lower_case_table_names=1, please add ${_chalk().default.yellow('DB_UNDERSCORED=true')} to the .env file`);
|
|
588
|
-
|
|
589
468
|
if (options === null || options === void 0 ? void 0 : options.exit) {
|
|
590
469
|
process.exit();
|
|
591
470
|
}
|
|
592
|
-
|
|
593
471
|
return false;
|
|
594
472
|
}
|
|
595
473
|
}
|
|
596
|
-
|
|
597
474
|
return true;
|
|
598
475
|
})();
|
|
599
476
|
}
|
|
600
|
-
|
|
601
477
|
isInstalled() {
|
|
602
478
|
var _this12 = this;
|
|
603
|
-
|
|
604
479
|
return _asyncToGenerator(function* () {
|
|
605
480
|
return (yield _this12.db.collectionExistsInDb('applicationVersion')) || (yield _this12.db.collectionExistsInDb('collections'));
|
|
606
481
|
})();
|
|
607
482
|
}
|
|
608
|
-
|
|
609
483
|
install(options = {}) {
|
|
610
484
|
var _this13 = this;
|
|
611
|
-
|
|
612
485
|
return _asyncToGenerator(function* () {
|
|
613
486
|
var _options$sync;
|
|
614
|
-
|
|
615
487
|
console.log('Database dialect: ' + _this13.db.sequelize.getDialect());
|
|
616
|
-
|
|
617
488
|
if ((options === null || options === void 0 ? void 0 : options.clean) || (options === null || options === void 0 ? void 0 : (_options$sync = options.sync) === null || _options$sync === void 0 ? void 0 : _options$sync.force)) {
|
|
618
489
|
console.log('Truncate database and reload app configuration');
|
|
619
490
|
yield _this13.db.clean({
|
|
@@ -623,7 +494,6 @@ class Application extends _koa().default {
|
|
|
623
494
|
method: 'install'
|
|
624
495
|
});
|
|
625
496
|
}
|
|
626
|
-
|
|
627
497
|
yield _this13.emitAsync('beforeInstall', _this13, options);
|
|
628
498
|
yield _this13.db.sync();
|
|
629
499
|
yield _this13.pm.install(options);
|
|
@@ -631,10 +501,8 @@ class Application extends _koa().default {
|
|
|
631
501
|
yield _this13.emitAsync('afterInstall', _this13, options);
|
|
632
502
|
})();
|
|
633
503
|
}
|
|
634
|
-
|
|
635
504
|
upgrade(options = {}) {
|
|
636
505
|
var _this14 = this;
|
|
637
|
-
|
|
638
506
|
return _asyncToGenerator(function* () {
|
|
639
507
|
yield _this14.emitAsync('beforeUpgrade', _this14, options);
|
|
640
508
|
const force = false;
|
|
@@ -649,15 +517,12 @@ class Application extends _koa().default {
|
|
|
649
517
|
yield _this14.emitAsync('afterUpgrade', _this14, options);
|
|
650
518
|
})();
|
|
651
519
|
}
|
|
652
|
-
|
|
653
520
|
toJSON() {
|
|
654
521
|
return {
|
|
655
522
|
appName: this.name
|
|
656
523
|
};
|
|
657
524
|
}
|
|
658
|
-
|
|
659
525
|
}
|
|
660
|
-
|
|
661
526
|
exports.Application = Application;
|
|
662
527
|
(0, _utils().applyMixins)(Application, [_utils().AsyncEmitter]);
|
|
663
528
|
var _default = Application;
|
package/lib/commands/console.js
CHANGED
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
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
8
|
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
9
|
const REPL = require('repl');
|
|
13
|
-
|
|
14
10
|
var _default = app => {
|
|
15
11
|
app.command('console').action( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
16
12
|
yield app.start();
|
|
@@ -21,16 +17,13 @@ var _default = app => {
|
|
|
21
17
|
console.log(err);
|
|
22
18
|
process.exit(1);
|
|
23
19
|
}
|
|
24
|
-
|
|
25
20
|
yield app.stop();
|
|
26
21
|
process.exit(0);
|
|
27
22
|
});
|
|
28
|
-
|
|
29
23
|
return function (_x) {
|
|
30
24
|
return _ref2.apply(this, arguments);
|
|
31
25
|
};
|
|
32
26
|
}());
|
|
33
27
|
}));
|
|
34
28
|
};
|
|
35
|
-
|
|
36
29
|
exports.default = _default;
|