@nocobase/server 0.7.0-alpha.82 → 0.7.1-alpha.4
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/application.d.ts +13 -2
- package/lib/application.js +159 -35
- package/lib/commands/db-auth.js +2 -2
- package/lib/commands/db-sync.js +2 -2
- package/lib/commands/index.js +2 -0
- package/lib/commands/install.js +3 -5
- package/lib/commands/migrator.d.ts +3 -0
- package/lib/commands/migrator.js +27 -0
- package/lib/commands/upgrade.js +1 -7
- package/lib/index.d.ts +1 -0
- package/lib/index.js +14 -0
- package/lib/middlewares/data-wrapping.js +1 -1
- package/lib/migration.d.ts +7 -0
- package/lib/migration.js +29 -0
- package/lib/plugin.d.ts +1 -0
- package/lib/plugin.js +4 -2
- package/package.json +11 -7
package/lib/application.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="koa-bodyparser" />
|
|
3
3
|
import { ACL } from '@nocobase/acl';
|
|
4
|
-
import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';
|
|
4
|
+
import Database, { Collection, CollectionOptions, IDatabaseOptions } from '@nocobase/database';
|
|
5
5
|
import Resourcer, { ResourceOptions } from '@nocobase/resourcer';
|
|
6
6
|
import { AsyncEmitter } from '@nocobase/utils';
|
|
7
7
|
import { Command, CommandOptions } from 'commander';
|
|
@@ -64,6 +64,14 @@ interface StartOptions {
|
|
|
64
64
|
cliArgs?: any[];
|
|
65
65
|
listen?: ListenOptions;
|
|
66
66
|
}
|
|
67
|
+
export declare class ApplicationVersion {
|
|
68
|
+
protected app: Application;
|
|
69
|
+
protected collection: Collection;
|
|
70
|
+
constructor(app: Application);
|
|
71
|
+
get(): Promise<any>;
|
|
72
|
+
update(): Promise<void>;
|
|
73
|
+
satisfies(range: string): Promise<boolean>;
|
|
74
|
+
}
|
|
67
75
|
export declare class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {
|
|
68
76
|
options: ApplicationOptions;
|
|
69
77
|
readonly db: Database;
|
|
@@ -73,14 +81,16 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
73
81
|
readonly pm: PluginManager;
|
|
74
82
|
readonly acl: ACL;
|
|
75
83
|
readonly appManager: AppManager;
|
|
84
|
+
readonly version: ApplicationVersion;
|
|
76
85
|
protected plugins: Map<string, Plugin<any>>;
|
|
77
86
|
listenServer: Server;
|
|
78
87
|
constructor(options: ApplicationOptions);
|
|
88
|
+
private createDatabase;
|
|
79
89
|
getVersion(): any;
|
|
80
90
|
plugin<O = any>(pluginClass: any, options?: O): Plugin<O>;
|
|
81
91
|
loadPluginConfig(pluginsConfigurations: PluginsConfigurations): void;
|
|
82
92
|
use<NewStateT = {}, NewContextT = {}>(middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>, options?: MiddlewareOptions): Koa<Koa.DefaultState & StateT & NewStateT, Koa.DefaultContext & ContextT & NewContextT>;
|
|
83
|
-
collection(options: CollectionOptions):
|
|
93
|
+
collection(options: CollectionOptions): Collection<any, any>;
|
|
84
94
|
resource(options: ResourceOptions): import("@nocobase/resourcer").Resource;
|
|
85
95
|
actions(handlers: any, options?: ActionsOptions): void;
|
|
86
96
|
command(name: string, desc?: string, opts?: CommandOptions): Command;
|
|
@@ -93,6 +103,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
93
103
|
stop(options?: any): Promise<void>;
|
|
94
104
|
destroy(options?: any): Promise<void>;
|
|
95
105
|
install(options?: InstallOptions): Promise<void>;
|
|
106
|
+
upgrade(options?: any): Promise<void>;
|
|
96
107
|
emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
|
|
97
108
|
}
|
|
98
109
|
export default Application;
|
package/lib/application.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.Application = void 0;
|
|
6
|
+
exports.default = exports.ApplicationVersion = exports.Application = void 0;
|
|
7
7
|
|
|
8
8
|
function _actions() {
|
|
9
9
|
const data = require("@nocobase/actions");
|
|
@@ -15,6 +15,16 @@ function _actions() {
|
|
|
15
15
|
return data;
|
|
16
16
|
}
|
|
17
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
|
+
|
|
18
28
|
function _utils() {
|
|
19
29
|
const data = require("@nocobase/utils");
|
|
20
30
|
|
|
@@ -55,6 +65,16 @@ function _lodash() {
|
|
|
55
65
|
return data;
|
|
56
66
|
}
|
|
57
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
|
+
|
|
58
78
|
var _acl = require("./acl");
|
|
59
79
|
|
|
60
80
|
var _appManager = require("./app-manager");
|
|
@@ -67,18 +87,89 @@ var _pluginManager = require("./plugin-manager");
|
|
|
67
87
|
|
|
68
88
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
69
89
|
|
|
70
|
-
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); } }
|
|
71
|
-
|
|
72
|
-
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); }); }; }
|
|
73
|
-
|
|
74
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; } } }; }
|
|
75
91
|
|
|
76
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); }
|
|
77
93
|
|
|
78
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; }
|
|
79
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
|
+
|
|
80
106
|
const packageJson = require('../package.json');
|
|
81
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
|
+
});
|
|
123
|
+
}
|
|
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
|
+
|
|
82
173
|
class Application extends _koa().default {
|
|
83
174
|
constructor(options) {
|
|
84
175
|
super();
|
|
@@ -90,11 +181,12 @@ class Application extends _koa().default {
|
|
|
90
181
|
this.pm = void 0;
|
|
91
182
|
this.acl = void 0;
|
|
92
183
|
this.appManager = void 0;
|
|
184
|
+
this.version = void 0;
|
|
93
185
|
this.plugins = new Map();
|
|
94
186
|
this.listenServer = void 0;
|
|
95
187
|
this.options = options;
|
|
96
188
|
this.acl = (0, _acl.createACL)();
|
|
97
|
-
this.db =
|
|
189
|
+
this.db = this.createDatabase(options);
|
|
98
190
|
this.resourcer = (0, _helper.createResourcer)(options);
|
|
99
191
|
this.cli = new (_commander().Command)('nocobase').usage('[command] [options]');
|
|
100
192
|
this.i18n = (0, _helper.createI18n)(options);
|
|
@@ -110,6 +202,21 @@ class Application extends _koa().default {
|
|
|
110
202
|
|
|
111
203
|
this.loadPluginConfig(options.plugins || []);
|
|
112
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
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
113
220
|
}
|
|
114
221
|
|
|
115
222
|
getVersion() {
|
|
@@ -170,10 +277,10 @@ class Application extends _koa().default {
|
|
|
170
277
|
}
|
|
171
278
|
|
|
172
279
|
load() {
|
|
173
|
-
var
|
|
280
|
+
var _this4 = this;
|
|
174
281
|
|
|
175
282
|
return _asyncToGenerator(function* () {
|
|
176
|
-
yield
|
|
283
|
+
yield _this4.pm.load();
|
|
177
284
|
})();
|
|
178
285
|
}
|
|
179
286
|
|
|
@@ -182,30 +289,30 @@ class Application extends _koa().default {
|
|
|
182
289
|
}
|
|
183
290
|
|
|
184
291
|
parse(argv = process.argv) {
|
|
185
|
-
var
|
|
292
|
+
var _this5 = this;
|
|
186
293
|
|
|
187
294
|
return _asyncToGenerator(function* () {
|
|
188
|
-
yield
|
|
189
|
-
return
|
|
295
|
+
yield _this5.load();
|
|
296
|
+
return _this5.cli.parseAsync(argv);
|
|
190
297
|
})();
|
|
191
298
|
}
|
|
192
299
|
|
|
193
300
|
start(options = {}) {
|
|
194
|
-
var
|
|
301
|
+
var _this6 = this;
|
|
195
302
|
|
|
196
303
|
return _asyncToGenerator(function* () {
|
|
197
304
|
var _options$listen;
|
|
198
305
|
|
|
199
306
|
// reconnect database
|
|
200
|
-
if (
|
|
201
|
-
yield
|
|
307
|
+
if (_this6.db.closed()) {
|
|
308
|
+
yield _this6.db.reconnect();
|
|
202
309
|
}
|
|
203
310
|
|
|
204
|
-
yield
|
|
311
|
+
yield _this6.emitAsync('beforeStart', _this6, options);
|
|
205
312
|
|
|
206
313
|
if (options === null || options === void 0 ? void 0 : (_options$listen = options.listen) === null || _options$listen === void 0 ? void 0 : _options$listen.port) {
|
|
207
314
|
const listen = () => new Promise((resolve, reject) => {
|
|
208
|
-
const Server =
|
|
315
|
+
const Server = _this6.listen(options === null || options === void 0 ? void 0 : options.listen, () => {
|
|
209
316
|
resolve(Server);
|
|
210
317
|
});
|
|
211
318
|
|
|
@@ -216,14 +323,14 @@ class Application extends _koa().default {
|
|
|
216
323
|
|
|
217
324
|
try {
|
|
218
325
|
//@ts-ignore
|
|
219
|
-
|
|
326
|
+
_this6.listenServer = yield listen();
|
|
220
327
|
} catch (e) {
|
|
221
328
|
console.error(e);
|
|
222
329
|
process.exit(1);
|
|
223
330
|
}
|
|
224
331
|
}
|
|
225
332
|
|
|
226
|
-
yield
|
|
333
|
+
yield _this6.emitAsync('afterStart', _this6, options);
|
|
227
334
|
})();
|
|
228
335
|
}
|
|
229
336
|
|
|
@@ -232,28 +339,28 @@ class Application extends _koa().default {
|
|
|
232
339
|
}
|
|
233
340
|
|
|
234
341
|
stop(options = {}) {
|
|
235
|
-
var
|
|
342
|
+
var _this7 = this;
|
|
236
343
|
|
|
237
344
|
return _asyncToGenerator(function* () {
|
|
238
|
-
yield
|
|
345
|
+
yield _this7.emitAsync('beforeStop', _this7, options);
|
|
239
346
|
|
|
240
347
|
try {
|
|
241
348
|
// close database connection
|
|
242
349
|
// silent if database already closed
|
|
243
|
-
yield
|
|
350
|
+
yield _this7.db.close();
|
|
244
351
|
} catch (e) {
|
|
245
352
|
console.log(e);
|
|
246
353
|
} // close http server
|
|
247
354
|
|
|
248
355
|
|
|
249
|
-
if (
|
|
356
|
+
if (_this7.listenServer) {
|
|
250
357
|
const closeServer = () => new Promise((resolve, reject) => {
|
|
251
|
-
|
|
358
|
+
_this7.listenServer.close(err => {
|
|
252
359
|
if (err) {
|
|
253
360
|
return reject(err);
|
|
254
361
|
}
|
|
255
362
|
|
|
256
|
-
|
|
363
|
+
_this7.listenServer = null;
|
|
257
364
|
resolve(true);
|
|
258
365
|
});
|
|
259
366
|
});
|
|
@@ -261,35 +368,52 @@ class Application extends _koa().default {
|
|
|
261
368
|
yield closeServer();
|
|
262
369
|
}
|
|
263
370
|
|
|
264
|
-
yield
|
|
371
|
+
yield _this7.emitAsync('afterStop', _this7, options);
|
|
265
372
|
})();
|
|
266
373
|
}
|
|
267
374
|
|
|
268
375
|
destroy(options = {}) {
|
|
269
|
-
var
|
|
376
|
+
var _this8 = this;
|
|
270
377
|
|
|
271
378
|
return _asyncToGenerator(function* () {
|
|
272
|
-
yield
|
|
273
|
-
yield
|
|
274
|
-
yield
|
|
379
|
+
yield _this8.emitAsync('beforeDestroy', _this8, options);
|
|
380
|
+
yield _this8.stop(options);
|
|
381
|
+
yield _this8.emitAsync('afterDestroy', _this8, options);
|
|
275
382
|
})();
|
|
276
383
|
}
|
|
277
384
|
|
|
278
385
|
install(options = {}) {
|
|
279
|
-
var
|
|
386
|
+
var _this9 = this;
|
|
280
387
|
|
|
281
388
|
return _asyncToGenerator(function* () {
|
|
282
|
-
yield
|
|
389
|
+
yield _this9.emitAsync('beforeInstall', _this9, options);
|
|
283
390
|
|
|
284
391
|
if (options === null || options === void 0 ? void 0 : options.clean) {
|
|
285
|
-
yield
|
|
392
|
+
yield _this9.db.clean((0, _lodash().isBoolean)(options.clean) ? {
|
|
286
393
|
drop: options.clean
|
|
287
394
|
} : options.clean);
|
|
288
395
|
}
|
|
289
396
|
|
|
290
|
-
yield
|
|
291
|
-
yield
|
|
292
|
-
yield
|
|
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();
|
|
293
417
|
})();
|
|
294
418
|
}
|
|
295
419
|
|
package/lib/commands/db-auth.js
CHANGED
|
@@ -10,10 +10,10 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
10
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
11
|
|
|
12
12
|
var _default = app => {
|
|
13
|
-
app.command('db:auth').option('-r, --
|
|
13
|
+
app.command('db:auth').option('-r, --retry [retry]').action( /*#__PURE__*/function () {
|
|
14
14
|
var _ref = _asyncToGenerator(function* (opts) {
|
|
15
15
|
yield app.db.auth({
|
|
16
|
-
|
|
16
|
+
retry: opts.retry || 10
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
19
|
|
package/lib/commands/db-sync.js
CHANGED
|
@@ -10,10 +10,10 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
10
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
11
|
|
|
12
12
|
var _default = app => {
|
|
13
|
-
app.command('db:sync').
|
|
13
|
+
app.command('db:sync').action( /*#__PURE__*/_asyncToGenerator(function* (...cliArgs) {
|
|
14
14
|
const opts = cliArgs[0];
|
|
15
15
|
console.log('db sync...');
|
|
16
|
-
const force =
|
|
16
|
+
const force = false;
|
|
17
17
|
yield app.db.sync({
|
|
18
18
|
force,
|
|
19
19
|
alter: {
|
package/lib/commands/index.js
CHANGED
package/lib/commands/install.js
CHANGED
|
@@ -22,13 +22,13 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
22
22
|
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); }); }; }
|
|
23
23
|
|
|
24
24
|
var _default = app => {
|
|
25
|
-
app.command('install').option('-f, --force').option('-c, --clean').option('-s, --silent').option('-r, --
|
|
25
|
+
app.command('install').option('-f, --force').option('-c, --clean').option('-s, --silent').option('-r, --retry [retry]').action( /*#__PURE__*/_asyncToGenerator(function* (...cliArgs) {
|
|
26
26
|
let installed = false;
|
|
27
27
|
const opts = cliArgs[0];
|
|
28
28
|
|
|
29
29
|
try {
|
|
30
30
|
yield app.db.auth({
|
|
31
|
-
|
|
31
|
+
retry: opts.retry || 1
|
|
32
32
|
});
|
|
33
33
|
} catch (error) {
|
|
34
34
|
console.log(_chalk().default.red('Unable to connect to the database. Please check the database environment variables in the .env file.'));
|
|
@@ -36,9 +36,7 @@ var _default = app => {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
if (!(opts === null || opts === void 0 ? void 0 : opts.clean) && !(opts === null || opts === void 0 ? void 0 : opts.force)) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (tables.includes('collections')) {
|
|
39
|
+
if (yield app.db.collectionExistsInDb('applicationVersion')) {
|
|
42
40
|
installed = true;
|
|
43
41
|
|
|
44
42
|
if (!opts.silent) {
|
|
@@ -0,0 +1,27 @@
|
|
|
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('migrator').action( /*#__PURE__*/function () {
|
|
14
|
+
var _ref = _asyncToGenerator(function* (opts) {
|
|
15
|
+
yield app.start();
|
|
16
|
+
console.log('migrating...');
|
|
17
|
+
yield app.db.migrator.runAsCLI(process.argv.slice(3));
|
|
18
|
+
yield app.stop();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return function (_x) {
|
|
22
|
+
return _ref.apply(this, arguments);
|
|
23
|
+
};
|
|
24
|
+
}());
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.default = _default;
|
package/lib/commands/upgrade.js
CHANGED
|
@@ -28,13 +28,7 @@ var _default = app => {
|
|
|
28
28
|
app.command('upgrade').action( /*#__PURE__*/_asyncToGenerator(function* (...cliArgs) {
|
|
29
29
|
const opts = cliArgs[0];
|
|
30
30
|
console.log('upgrading...');
|
|
31
|
-
|
|
32
|
-
yield app.db.sync({
|
|
33
|
-
force,
|
|
34
|
-
alter: {
|
|
35
|
-
drop: force
|
|
36
|
-
}
|
|
37
|
-
});
|
|
31
|
+
yield app.upgrade();
|
|
38
32
|
yield app.stop({
|
|
39
33
|
cliArgs
|
|
40
34
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { AppManager } from './app-manager';
|
|
|
2
2
|
export * from './application';
|
|
3
3
|
export { Application as default } from './application';
|
|
4
4
|
export * as middlewares from './middlewares';
|
|
5
|
+
export * from './migration';
|
|
5
6
|
export * from './plugin';
|
|
6
7
|
export * from './plugin-manager';
|
|
7
8
|
export * from './read-config';
|
package/lib/index.js
CHANGED
|
@@ -41,6 +41,20 @@ var _middlewares = _interopRequireWildcard(require("./middlewares"));
|
|
|
41
41
|
|
|
42
42
|
exports.middlewares = _middlewares;
|
|
43
43
|
|
|
44
|
+
var _migration = require("./migration");
|
|
45
|
+
|
|
46
|
+
Object.keys(_migration).forEach(function (key) {
|
|
47
|
+
if (key === "default" || key === "__esModule") return;
|
|
48
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
49
|
+
if (key in exports && exports[key] === _migration[key]) return;
|
|
50
|
+
Object.defineProperty(exports, key, {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: function get() {
|
|
53
|
+
return _migration[key];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
44
58
|
var _plugin = require("./plugin");
|
|
45
59
|
|
|
46
60
|
Object.keys(_plugin).forEach(function (key) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Migration as DbMigration } from '@nocobase/database';
|
|
2
|
+
import Application from './application';
|
|
3
|
+
import Plugin from './plugin';
|
|
4
|
+
export declare class Migration extends DbMigration {
|
|
5
|
+
get app(): Application<import("./application").DefaultState, import("./application").DefaultContext>;
|
|
6
|
+
get plugin(): Plugin<any>;
|
|
7
|
+
}
|
package/lib/migration.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Migration = void 0;
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class Migration extends _database().Migration {
|
|
19
|
+
get app() {
|
|
20
|
+
return this.context.app;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get plugin() {
|
|
24
|
+
return this.context.plugin;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.Migration = Migration;
|
package/lib/plugin.d.ts
CHANGED
package/lib/plugin.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.Plugin = void 0;
|
|
6
|
+
exports.default = exports.Plugin = void 0;
|
|
7
7
|
|
|
8
8
|
function _findPackageJson() {
|
|
9
9
|
const data = _interopRequireDefault(require("find-package-json"));
|
|
@@ -67,4 +67,6 @@ class Plugin {
|
|
|
67
67
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
exports.Plugin = Plugin;
|
|
70
|
+
exports.Plugin = Plugin;
|
|
71
|
+
var _default = Plugin;
|
|
72
|
+
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1-alpha.4",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@koa/cors": "^3.1.0",
|
|
15
15
|
"@koa/router": "^9.4.0",
|
|
16
|
-
"@nocobase/acl": "0.7.
|
|
17
|
-
"@nocobase/actions": "0.7.
|
|
18
|
-
"@nocobase/database": "0.7.
|
|
19
|
-
"@nocobase/resourcer": "0.7.
|
|
16
|
+
"@nocobase/acl": "0.7.1-alpha.4",
|
|
17
|
+
"@nocobase/actions": "0.7.1-alpha.4",
|
|
18
|
+
"@nocobase/database": "0.7.1-alpha.4",
|
|
19
|
+
"@nocobase/resourcer": "0.7.1-alpha.4",
|
|
20
20
|
"chalk": "^4.1.1",
|
|
21
21
|
"commander": "^9.2.0",
|
|
22
22
|
"find-package-json": "^1.2.0",
|
|
@@ -24,7 +24,11 @@
|
|
|
24
24
|
"koa": "^2.13.4",
|
|
25
25
|
"koa-bodyparser": "^4.3.0",
|
|
26
26
|
"koa-static": "^5.0.0",
|
|
27
|
-
"lodash": "^4.17.21"
|
|
27
|
+
"lodash": "^4.17.21",
|
|
28
|
+
"semver": "^7.3.7"
|
|
28
29
|
},
|
|
29
|
-
"
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/semver": "^7.3.9"
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "570d039f1904a041729c1967c0637b1109c278a8"
|
|
30
34
|
}
|