@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.
Files changed (130) hide show
  1. package/lib/acl/available-action.js +37 -35
  2. package/lib/acl/index.js +45 -21
  3. package/lib/app-manager.d.ts +3 -3
  4. package/lib/app-manager.js +151 -72
  5. package/lib/application.d.ts +16 -4
  6. package/lib/application.js +414 -152
  7. package/lib/commands/console.d.ts +2 -3
  8. package/lib/commands/console.js +33 -24
  9. package/lib/commands/db-auth.d.ts +3 -0
  10. package/lib/commands/db-auth.js +26 -0
  11. package/lib/commands/db-clean.d.ts +3 -0
  12. package/lib/commands/db-clean.js +27 -0
  13. package/lib/commands/db-sync.d.ts +2 -4
  14. package/lib/commands/db-sync.js +25 -23
  15. package/lib/commands/index.d.ts +1 -2
  16. package/lib/commands/index.js +31 -29
  17. package/lib/commands/install.d.ts +2 -4
  18. package/lib/commands/install.js +66 -20
  19. package/lib/commands/migrator.d.ts +3 -0
  20. package/lib/commands/migrator.js +27 -0
  21. package/lib/commands/start.d.ts +2 -4
  22. package/lib/commands/start.js +28 -22
  23. package/lib/commands/upgrade.d.ts +6 -0
  24. package/lib/commands/upgrade.js +39 -0
  25. package/lib/helper.js +132 -61
  26. package/lib/index.d.ts +1 -0
  27. package/lib/index.js +100 -33
  28. package/lib/middlewares/data-wrapping.js +65 -55
  29. package/lib/middlewares/index.js +30 -14
  30. package/lib/middlewares/table2resource.js +89 -52
  31. package/lib/migration.d.ts +7 -0
  32. package/lib/migration.js +29 -0
  33. package/lib/plugin-manager.js +124 -55
  34. package/lib/plugin.d.ts +1 -0
  35. package/lib/plugin.js +67 -45
  36. package/lib/read-config.js +159 -64
  37. package/package.json +13 -14
  38. package/esm/acl/available-action.d.ts +0 -5
  39. package/esm/acl/available-action.js +0 -36
  40. package/esm/acl/available-action.js.map +0 -1
  41. package/esm/acl/index.d.ts +0 -2
  42. package/esm/acl/index.js +0 -19
  43. package/esm/acl/index.js.map +0 -1
  44. package/esm/app-manager.d.ts +0 -19
  45. package/esm/app-manager.js +0 -69
  46. package/esm/app-manager.js.map +0 -1
  47. package/esm/application.d.ts +0 -97
  48. package/esm/application.js +0 -156
  49. package/esm/application.js.map +0 -1
  50. package/esm/commands/console.d.ts +0 -4
  51. package/esm/commands/console.js +0 -25
  52. package/esm/commands/console.js.map +0 -1
  53. package/esm/commands/create-plugin/create-plugin.d.ts +0 -2
  54. package/esm/commands/create-plugin/create-plugin.js +0 -29
  55. package/esm/commands/create-plugin/create-plugin.js.map +0 -1
  56. package/esm/commands/create-plugin/index.d.ts +0 -5
  57. package/esm/commands/create-plugin/index.js +0 -6
  58. package/esm/commands/create-plugin/index.js.map +0 -1
  59. package/esm/commands/create-plugin/resources/templates/package-json.d.ts +0 -11
  60. package/esm/commands/create-plugin/resources/templates/package-json.js +0 -11
  61. package/esm/commands/create-plugin/resources/templates/package-json.js.map +0 -1
  62. package/esm/commands/create-plugin/resources/templates/plugin.d.ts +0 -4
  63. package/esm/commands/create-plugin/resources/templates/plugin.js +0 -12
  64. package/esm/commands/create-plugin/resources/templates/plugin.js.map +0 -1
  65. package/esm/commands/db-sync.d.ts +0 -5
  66. package/esm/commands/db-sync.js +0 -25
  67. package/esm/commands/db-sync.js.map +0 -1
  68. package/esm/commands/index.d.ts +0 -3
  69. package/esm/commands/index.js +0 -26
  70. package/esm/commands/index.js.map +0 -1
  71. package/esm/commands/install.d.ts +0 -5
  72. package/esm/commands/install.js +0 -23
  73. package/esm/commands/install.js.map +0 -1
  74. package/esm/commands/start.d.ts +0 -5
  75. package/esm/commands/start.js +0 -23
  76. package/esm/commands/start.js.map +0 -1
  77. package/esm/helper.d.ts +0 -7
  78. package/esm/helper.js +0 -59
  79. package/esm/helper.js.map +0 -1
  80. package/esm/index.d.ts +0 -7
  81. package/esm/index.js +0 -9
  82. package/esm/index.js.map +0 -1
  83. package/esm/middlewares/data-wrapping.d.ts +0 -3
  84. package/esm/middlewares/data-wrapping.js +0 -54
  85. package/esm/middlewares/data-wrapping.js.map +0 -1
  86. package/esm/middlewares/index.d.ts +0 -2
  87. package/esm/middlewares/index.js +0 -3
  88. package/esm/middlewares/index.js.map +0 -1
  89. package/esm/middlewares/table2resource.d.ts +0 -6
  90. package/esm/middlewares/table2resource.js +0 -51
  91. package/esm/middlewares/table2resource.js.map +0 -1
  92. package/esm/plugin-manager.d.ts +0 -23
  93. package/esm/plugin-manager.js +0 -57
  94. package/esm/plugin-manager.js.map +0 -1
  95. package/esm/plugin.d.ts +0 -32
  96. package/esm/plugin.js +0 -43
  97. package/esm/plugin.js.map +0 -1
  98. package/esm/read-config.d.ts +0 -8
  99. package/esm/read-config.js +0 -63
  100. package/esm/read-config.js.map +0 -1
  101. package/lib/acl/available-action.js.map +0 -1
  102. package/lib/acl/index.js.map +0 -1
  103. package/lib/app-manager.js.map +0 -1
  104. package/lib/application.js.map +0 -1
  105. package/lib/commands/console.js.map +0 -1
  106. package/lib/commands/create-plugin/create-plugin.d.ts +0 -2
  107. package/lib/commands/create-plugin/create-plugin.js +0 -31
  108. package/lib/commands/create-plugin/create-plugin.js.map +0 -1
  109. package/lib/commands/create-plugin/index.d.ts +0 -5
  110. package/lib/commands/create-plugin/index.js +0 -8
  111. package/lib/commands/create-plugin/index.js.map +0 -1
  112. package/lib/commands/create-plugin/resources/templates/package-json.d.ts +0 -11
  113. package/lib/commands/create-plugin/resources/templates/package-json.js +0 -13
  114. package/lib/commands/create-plugin/resources/templates/package-json.js.map +0 -1
  115. package/lib/commands/create-plugin/resources/templates/plugin.d.ts +0 -4
  116. package/lib/commands/create-plugin/resources/templates/plugin.js +0 -33
  117. package/lib/commands/create-plugin/resources/templates/plugin.js.map +0 -1
  118. package/lib/commands/db-sync.js.map +0 -1
  119. package/lib/commands/index.js.map +0 -1
  120. package/lib/commands/install.js.map +0 -1
  121. package/lib/commands/start.js.map +0 -1
  122. package/lib/helper.js.map +0 -1
  123. package/lib/index.js.map +0 -1
  124. package/lib/middlewares/data-wrapping.js.map +0 -1
  125. package/lib/middlewares/index.js.map +0 -1
  126. package/lib/middlewares/table2resource.js.map +0 -1
  127. package/lib/plugin-manager.js.map +0 -1
  128. package/lib/plugin.js.map +0 -1
  129. package/lib/read-config.js.map +0 -1
  130. package/tsconfig.build.json +0 -9
@@ -1,163 +1,425 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.Application = void 0;
16
- const actions_1 = require("@nocobase/actions");
17
- const utils_1 = require("@nocobase/utils");
18
- const koa_1 = __importDefault(require("koa"));
19
- const lodash_1 = require("lodash");
20
- const acl_1 = require("./acl");
21
- const app_manager_1 = require("./app-manager");
22
- const commands_1 = require("./commands");
23
- const helper_1 = require("./helper");
24
- const plugin_manager_1 = require("./plugin-manager");
25
- class Application extends koa_1.default {
26
- constructor(options) {
27
- super();
28
- this.options = options;
29
- this.plugins = new Map();
30
- this.acl = (0, acl_1.createACL)();
31
- this.db = (0, helper_1.createDatabase)(options);
32
- this.resourcer = (0, helper_1.createResourcer)(options);
33
- this.cli = (0, commands_1.createCli)(this);
34
- this.i18n = (0, helper_1.createI18n)(options);
35
- this.pm = new plugin_manager_1.PluginManager({
36
- app: this,
37
- });
38
- this.appManager = new app_manager_1.AppManager(this);
39
- (0, helper_1.registerMiddlewares)(this, options);
40
- if (options.registerActions !== false) {
41
- (0, actions_1.registerActions)(this);
42
- }
43
- this.loadPluginConfig(options.plugins || []);
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
- plugin(pluginClass, options) {
46
- return this.pm.add(pluginClass, options);
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
- loadPluginConfig(pluginsConfigurations) {
49
- for (let pluginConfiguration of pluginsConfigurations) {
50
- if (typeof pluginConfiguration == 'string') {
51
- pluginConfiguration = [pluginConfiguration, {}];
52
- }
53
- const plugin = plugin_manager_1.PluginManager.resolvePlugin(pluginConfiguration[0]);
54
- const pluginOptions = pluginConfiguration[1];
55
- this.plugin(plugin, pluginOptions);
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
- use(middleware, options) {
59
- // @ts-ignore
60
- return super.use(middleware);
61
- }
62
- collection(options) {
63
- return this.db.collection(options);
64
- }
65
- resource(options) {
66
- return this.resourcer.define(options);
67
- }
68
- actions(handlers, options) {
69
- return this.resourcer.registerActions(handlers);
70
- }
71
- command(name, desc, opts) {
72
- return this.cli.command(name, desc, opts);
73
- }
74
- findCommand(name) {
75
- return this.cli._findCommand(name);
76
- }
77
- load() {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- yield this.pm.load();
80
- });
81
- }
82
- getPlugin(name) {
83
- return this.pm.get(name);
84
- }
85
- parse(argv = process.argv) {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- yield this.load();
88
- return this.cli.parseAsync(argv);
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
- destroy(options) {
142
- return __awaiter(this, void 0, void 0, function* () {
143
- yield this.emitAsync('beforeDestroy', this, options);
144
- yield this.stop(options);
145
- yield this.emitAsync('afterDestroy', this, options);
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
- install(options) {
149
- return __awaiter(this, void 0, void 0, function* () {
150
- yield this.emitAsync('beforeInstall', this, options);
151
- if (options === null || options === void 0 ? void 0 : options.clean) {
152
- yield this.db.clean((0, lodash_1.isBoolean)(options.clean) ? { drop: options.clean } : options.clean);
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
- yield this.db.sync(options === null || options === void 0 ? void 0 : options.sync);
155
- yield this.pm.install(options);
156
- yield this.emitAsync('afterInstall', this, options);
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, utils_1.applyMixins)(Application, [utils_1.AsyncEmitter]);
162
- exports.default = Application;
163
- //# sourceMappingURL=application.js.map
423
+ (0, _utils().applyMixins)(Application, [_utils().AsyncEmitter]);
424
+ var _default = Application;
425
+ exports.default = _default;
@@ -1,4 +1,3 @@
1
- declare const _default: ({ app }: {
2
- app: any;
3
- }) => Promise<void>;
1
+ import Application from '../application';
2
+ declare const _default: (app: Application) => void;
4
3
  export default _default;
@@ -1,27 +1,36 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
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
- exports.default = ({ app }) => __awaiter(void 0, void 0, void 0, function* () {
13
+
14
+ var _default = app => {
15
+ app.command('console').action( /*#__PURE__*/_asyncToGenerator(function* () {
14
16
  yield app.start();
15
- const repl = (REPL.start('nocobase > ').context.app = app);
16
- repl.on('exit', function (err) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- if (err) {
19
- console.log(err);
20
- process.exit(1);
21
- }
22
- yield app.stop();
23
- process.exit(0);
24
- });
25
- });
26
- });
27
- //# sourceMappingURL=console.js.map
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,3 @@
1
+ import Application from '../application';
2
+ declare const _default: (app: Application) => void;
3
+ export 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;