@nocobase/server 0.9.0-alpha.2 → 0.9.1-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.
@@ -4,7 +4,7 @@ import http, { IncomingMessage, ServerResponse } from 'http';
4
4
  import Application, { ApplicationOptions } from './application';
5
5
  declare type AppSelector = (req: IncomingMessage) => Application | string | undefined | null;
6
6
  export declare class AppManager extends EventEmitter {
7
- private app;
7
+ app: Application;
8
8
  applications: Map<string, Application>;
9
9
  constructor(app: Application);
10
10
  appSelector: AppSelector;
@@ -12,7 +12,7 @@ export declare class AppManager extends EventEmitter {
12
12
  removeApplication(name: string): Promise<void>;
13
13
  setAppSelector(selector: AppSelector): void;
14
14
  listen(...args: any[]): http.Server;
15
- getApplication(appName: string): Promise<null | Application>;
15
+ getApplication(appName: string, options?: {}): Promise<null | Application>;
16
16
  callback(): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
17
17
  emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
18
18
  }
@@ -107,13 +107,14 @@ class AppManager extends _events().default {
107
107
  return server.listen(...args);
108
108
  }
109
109
 
110
- getApplication(appName) {
110
+ getApplication(appName, options = {}) {
111
111
  var _this3 = this;
112
112
 
113
113
  return _asyncToGenerator(function* () {
114
114
  yield _this3.emitAsync('beforeGetApplication', {
115
115
  appManager: _this3,
116
- name: appName
116
+ name: appName,
117
+ options
117
118
  });
118
119
  return _this3.applications.get(appName);
119
120
  })();
@@ -124,17 +125,18 @@ class AppManager extends _events().default {
124
125
 
125
126
  return /*#__PURE__*/function () {
126
127
  var _ref3 = _asyncToGenerator(function* (req, res) {
127
- let handleApp = _this4.appSelector(req) || _this4.app;
128
+ const appManager = _this4.app.appManager;
129
+ let handleApp = appManager.appSelector(req) || appManager.app;
128
130
 
129
131
  if (typeof handleApp === 'string') {
130
- handleApp = yield _this4.getApplication(handleApp);
132
+ handleApp = yield appManager.getApplication(handleApp);
131
133
 
132
134
  if (!handleApp) {
133
135
  res.statusCode = 404;
134
136
  return res.end(JSON.stringify({
135
137
  redirectTo: process.env.APP_NOT_FOUND_REDIRECT_TO,
136
138
  errors: [{
137
- message: 'Not Found'
139
+ message: 'Application Not Found'
138
140
  }]
139
141
  }));
140
142
  }
@@ -30,6 +30,7 @@ export interface ApplicationOptions {
30
30
  acl?: boolean;
31
31
  logger?: AppLoggerOptions;
32
32
  pmSock?: string;
33
+ name?: string;
33
34
  }
34
35
  export interface DefaultState extends KoaDefaultState {
35
36
  currentUser?: any;
@@ -100,6 +101,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
100
101
  get appManager(): AppManager;
101
102
  get logger(): Logger;
102
103
  get log(): Logger;
104
+ get name(): string;
103
105
  protected init(): void;
104
106
  private createDatabase;
105
107
  getVersion(): any;
@@ -127,5 +129,8 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
127
129
  install(options?: InstallOptions): Promise<void>;
128
130
  upgrade(options?: any): Promise<void>;
129
131
  emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
132
+ toJSON(): {
133
+ appName: string;
134
+ };
130
135
  }
131
136
  export default Application;
@@ -148,6 +148,8 @@ class ApplicationVersion {
148
148
  if (!app.db.hasCollection('applicationVersion')) {
149
149
  app.db.collection({
150
150
  name: 'applicationVersion',
151
+ namespace: 'core',
152
+ duplicator: 'required',
151
153
  timestamps: false,
152
154
  fields: [{
153
155
  name: 'value',
@@ -280,6 +282,10 @@ class Application extends _koa().default {
280
282
  return this._logger;
281
283
  }
282
284
 
285
+ get name() {
286
+ return this.options.name || 'main';
287
+ }
288
+
283
289
  init() {
284
290
  const options = this.options;
285
291
  const logger = (0, _logger().createAppLogger)(options.logger);
@@ -453,6 +459,7 @@ class Application extends _koa().default {
453
459
  yield _this7.dbVersionCheck({
454
460
  exit: true
455
461
  });
462
+ yield _this7.db.prepare();
456
463
 
457
464
  if ((argv === null || argv === void 0 ? void 0 : argv[2]) !== 'upgrade') {
458
465
  yield _this7.load({
@@ -576,8 +583,8 @@ class Application extends _koa().default {
576
583
  plain: true
577
584
  });
578
585
 
579
- if ((result === null || result === void 0 ? void 0 : result.Value) === '1') {
580
- console.log(_chalk().default.red(`mysql variable 'lower_case_table_names' must be set to '0' or '2'`));
586
+ if ((result === null || result === void 0 ? void 0 : result.Value) === '1' && !_this11.db.options.underscored) {
587
+ console.log(`Your database lower_case_table_names=1, please add ${_chalk().default.yellow('DB_UNDERSCORED=true')} to the .env file`);
581
588
 
582
589
  if (options === null || options === void 0 ? void 0 : options.exit) {
583
590
  process.exit();
@@ -643,6 +650,12 @@ class Application extends _koa().default {
643
650
  })();
644
651
  }
645
652
 
653
+ toJSON() {
654
+ return {
655
+ appName: this.name
656
+ };
657
+ }
658
+
646
659
  }
647
660
 
648
661
  exports.Application = Application;
package/lib/helper.js CHANGED
@@ -81,7 +81,9 @@ function createI18n(options) {
81
81
 
82
82
  instance.init(_objectSpread({
83
83
  lng: 'en-US',
84
- resources: {}
84
+ resources: {},
85
+ keySeparator: false,
86
+ nsSeparator: false
85
87
  }, options.i18n));
86
88
  return instance;
87
89
  }
@@ -93,7 +93,10 @@ class PluginManagerRepository extends _database().Repository {
93
93
  var _this4 = this;
94
94
 
95
95
  return _asyncToGenerator(function* () {
96
- const items = yield _this4.find();
96
+ // sort plugins by id
97
+ const items = yield _this4.find({
98
+ sort: 'id'
99
+ });
97
100
 
98
101
  var _iterator = _createForOfIteratorHelper(items),
99
102
  _step;
@@ -1,5 +1,7 @@
1
1
  declare const _default: {
2
2
  name: string;
3
+ namespace: string;
4
+ duplicator: string;
3
5
  repository: string;
4
6
  fields: ({
5
7
  type: string;
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _default = {
8
8
  name: 'applicationPlugins',
9
+ namespace: 'core',
10
+ duplicator: 'required',
9
11
  repository: 'PluginManagerRepository',
10
12
  fields: [{
11
13
  type: 'string',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "0.9.0-alpha.2",
3
+ "version": "0.9.1-alpha.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -8,11 +8,11 @@
8
8
  "@hapi/topo": "^6.0.0",
9
9
  "@koa/cors": "^3.1.0",
10
10
  "@koa/router": "^9.4.0",
11
- "@nocobase/acl": "0.9.0-alpha.2",
12
- "@nocobase/actions": "0.9.0-alpha.2",
13
- "@nocobase/database": "0.9.0-alpha.2",
14
- "@nocobase/logger": "0.9.0-alpha.2",
15
- "@nocobase/resourcer": "0.9.0-alpha.2",
11
+ "@nocobase/acl": "0.9.1-alpha.1",
12
+ "@nocobase/actions": "0.9.1-alpha.1",
13
+ "@nocobase/database": "0.9.1-alpha.1",
14
+ "@nocobase/logger": "0.9.1-alpha.1",
15
+ "@nocobase/resourcer": "0.9.1-alpha.1",
16
16
  "chalk": "^4.1.1",
17
17
  "commander": "^9.2.0",
18
18
  "find-package-json": "^1.2.0",
@@ -27,5 +27,5 @@
27
27
  "devDependencies": {
28
28
  "@types/semver": "^7.3.9"
29
29
  },
30
- "gitHead": "b8f76ad38e60e677c5bb4aab0a4cdb28d98a0f49"
30
+ "gitHead": "56cb184b00dc383b853015d525bf6e79dea92169"
31
31
  }