@nocobase/server 0.7.4-alpha.7 → 0.7.6-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.
@@ -11,6 +11,7 @@ import Koa from 'koa';
11
11
  import { AppManager } from './app-manager';
12
12
  import { Plugin } from './plugin';
13
13
  import { InstallOptions, PluginManager } from './plugin-manager';
14
+ import { ICacheConfig, Cache } from '@nocobase/cache';
14
15
  export declare type PluginConfiguration = string | [string, any];
15
16
  export declare type PluginsConfigurations = Array<PluginConfiguration>;
16
17
  export interface ResourcerOptions {
@@ -18,6 +19,7 @@ export interface ResourcerOptions {
18
19
  }
19
20
  export interface ApplicationOptions {
20
21
  database?: IDatabaseOptions | Database;
22
+ cache?: ICacheConfig | ICacheConfig[];
21
23
  resourcer?: ResourcerOptions;
22
24
  bodyParser?: any;
23
25
  cors?: any;
@@ -32,6 +34,7 @@ export interface DefaultState {
32
34
  }
33
35
  export interface DefaultContext {
34
36
  db: Database;
37
+ cache: Cache;
35
38
  resourcer: Resourcer;
36
39
  [key: string]: any;
37
40
  }
@@ -75,6 +78,7 @@ export declare class ApplicationVersion {
75
78
  export declare class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {
76
79
  options: ApplicationOptions;
77
80
  readonly db: Database;
81
+ readonly cache: Cache;
78
82
  readonly resourcer: Resourcer;
79
83
  readonly cli: Command;
80
84
  readonly i18n: i18n;
@@ -85,6 +85,16 @@ var _helper = require("./helper");
85
85
 
86
86
  var _pluginManager = require("./plugin-manager");
87
87
 
88
+ function _cache() {
89
+ const data = require("@nocobase/cache");
90
+
91
+ _cache = function _cache() {
92
+ return data;
93
+ };
94
+
95
+ return data;
96
+ }
97
+
88
98
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
89
99
 
90
100
  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; } } }; }
@@ -164,7 +174,9 @@ class ApplicationVersion {
164
174
  return true;
165
175
  }
166
176
 
167
- return _semver().default.satisfies(version, range);
177
+ return _semver().default.satisfies(version, range, {
178
+ includePrerelease: true
179
+ });
168
180
  }
169
181
 
170
182
  return true;
@@ -180,6 +192,7 @@ class Application extends _koa().default {
180
192
  super();
181
193
  this.options = void 0;
182
194
  this.db = void 0;
195
+ this.cache = void 0;
183
196
  this.resourcer = void 0;
184
197
  this.cli = void 0;
185
198
  this.i18n = void 0;
@@ -192,6 +205,7 @@ class Application extends _koa().default {
192
205
  this.options = options;
193
206
  this.acl = (0, _acl.createACL)();
194
207
  this.db = this.createDatabase(options);
208
+ this.cache = (0, _cache().createCache)(options.cache);
195
209
  this.resourcer = (0, _helper.createResourcer)(options);
196
210
  this.cli = new (_commander().Command)('nocobase').usage('[command] [options]');
197
211
  this.i18n = (0, _helper.createI18n)(options);
package/lib/helper.js CHANGED
@@ -111,13 +111,14 @@ function registerMiddlewares(app, options) {
111
111
  };
112
112
 
113
113
  ctx.db = app.db;
114
+ ctx.cache = app.cache;
114
115
  ctx.resourcer = app.resourcer;
115
116
  const i18n = app.i18n.cloneInstance({
116
117
  initImmediate: false
117
118
  });
118
119
  ctx.i18n = i18n;
119
120
  ctx.t = i18n.t.bind(i18n);
120
- const lng = ctx.get('X-Locale') || ctx.request.query.locale || ctx.acceptsLanguages().shift() || 'en-US';
121
+ const lng = ctx.get('X-Locale') || ctx.request.query.locale || app.i18n.language || ctx.acceptsLanguages().shift() || 'en-US';
121
122
 
122
123
  if (lng !== '*' && lng) {
123
124
  i18n.changeLanguage(lng);
@@ -135,6 +136,6 @@ function registerMiddlewares(app, options) {
135
136
  app.use((0, _dataWrapping.dataWrapping)());
136
137
  }
137
138
 
138
- app.use((0, _table2resource.table2resource)());
139
+ app.use(_table2resource.table2resource);
139
140
  app.use(app.resourcer.restApiMiddleware());
140
141
  }
@@ -1,6 +1,6 @@
1
1
  import { ResourcerContext } from '@nocobase/resourcer';
2
2
  import Database from '@nocobase/database';
3
- export declare function table2resource(): (ctx: ResourcerContext & {
3
+ export declare function table2resource(ctx: ResourcerContext & {
4
4
  db: Database;
5
- }, next: () => Promise<any>) => Promise<any>;
5
+ }, next: () => Promise<any>): Promise<any>;
6
6
  export default table2resource;
@@ -28,64 +28,50 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
28
28
 
29
29
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
30
30
 
31
- 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); } }
32
-
33
- 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); }); }; }
34
-
35
- function table2resource() {
36
- return /*#__PURE__*/function () {
37
- var _table2resource = _asyncToGenerator(function* (ctx, next) {
38
- const resourcer = ctx.resourcer;
39
- const database = ctx.db;
40
- let params = (0, _resourcer().parseRequest)({
41
- path: ctx.request.path,
42
- method: ctx.request.method
43
- }, {
44
- prefix: resourcer.options.prefix,
45
- accessors: resourcer.options.accessors
46
- });
47
-
48
- if (!params) {
49
- return next();
50
- }
51
-
52
- const resourceName = (0, _resourcer().getNameByParams)(params); // 如果资源名称未被定义
53
-
54
- if (resourcer.isDefined(resourceName)) {
55
- return next();
56
- }
57
-
58
- const _resourceName$split = resourceName.split('.'),
59
- _resourceName$split2 = _slicedToArray(_resourceName$split, 2),
60
- collectionName = _resourceName$split2[0],
61
- fieldName = _resourceName$split2[1]; // 如果经过加载后是已经定义的表
62
-
63
-
64
- if (!database.hasCollection(collectionName)) {
65
- return next();
66
- }
67
-
68
- const collection = database.getCollection(collectionName);
69
- let resourceType = 'single';
70
-
71
- if (fieldName && collection.hasField(fieldName)) {
72
- const field = collection.getField(fieldName);
73
- resourceType = field.type;
74
- }
75
-
76
- resourcer.define({
77
- type: resourceType,
78
- name: resourceName
79
- });
80
- return next();
81
- });
82
-
83
- function table2resource(_x, _x2) {
84
- return _table2resource.apply(this, arguments);
85
- }
86
-
87
- return table2resource;
88
- }();
31
+ function table2resource(ctx, next) {
32
+ const resourcer = ctx.resourcer;
33
+ const database = ctx.db;
34
+ let params = (0, _resourcer().parseRequest)({
35
+ path: ctx.request.path,
36
+ method: ctx.request.method
37
+ }, {
38
+ prefix: resourcer.options.prefix,
39
+ accessors: resourcer.options.accessors
40
+ });
41
+
42
+ if (!params) {
43
+ return next();
44
+ }
45
+
46
+ const resourceName = (0, _resourcer().getNameByParams)(params); // 如果资源名称未被定义
47
+
48
+ if (resourcer.isDefined(resourceName)) {
49
+ return next();
50
+ }
51
+
52
+ const _resourceName$split = resourceName.split('.'),
53
+ _resourceName$split2 = _slicedToArray(_resourceName$split, 2),
54
+ collectionName = _resourceName$split2[0],
55
+ fieldName = _resourceName$split2[1]; // 如果经过加载后是已经定义的表
56
+
57
+
58
+ if (!database.hasCollection(collectionName)) {
59
+ return next();
60
+ }
61
+
62
+ const collection = database.getCollection(collectionName);
63
+ let resourceType = 'single';
64
+
65
+ if (fieldName && collection.hasField(fieldName)) {
66
+ const field = collection.getField(fieldName);
67
+ resourceType = field.type;
68
+ }
69
+
70
+ resourcer.define({
71
+ type: resourceType,
72
+ name: resourceName
73
+ });
74
+ return next();
89
75
  }
90
76
 
91
77
  var _default = table2resource;
@@ -9,13 +9,16 @@ export interface InstallOptions {
9
9
  clean?: CleanOptions | boolean;
10
10
  sync?: SyncOptions;
11
11
  }
12
+ declare type PluginConstructor<P, O = any> = {
13
+ new (app: Application, options: O): P;
14
+ };
12
15
  export declare class PluginManager {
13
16
  app: Application;
14
17
  protected plugins: Map<string, Plugin<any>>;
15
18
  constructor(options: PluginManagerOptions);
16
19
  getPlugins(): Map<string, Plugin<any>>;
17
20
  get(name: string): Plugin<any>;
18
- add<P = Plugin, O = any>(pluginClass: any, options?: O): P;
21
+ add<P extends Plugin = Plugin, O = any>(pluginClass: PluginConstructor<P, O>, options?: O): P;
19
22
  load(): Promise<void>;
20
23
  install(options?: InstallOptions): Promise<void>;
21
24
  static resolvePlugin(pluginName: string): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "0.7.4-alpha.7",
3
+ "version": "0.7.6-alpha.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -13,14 +13,14 @@
13
13
  "dependencies": {
14
14
  "@koa/cors": "^3.1.0",
15
15
  "@koa/router": "^9.4.0",
16
- "@nocobase/acl": "0.7.4-alpha.7",
17
- "@nocobase/actions": "0.7.4-alpha.7",
18
- "@nocobase/database": "0.7.4-alpha.7",
19
- "@nocobase/resourcer": "0.7.4-alpha.7",
16
+ "@nocobase/acl": "0.7.6-alpha.1",
17
+ "@nocobase/actions": "0.7.6-alpha.1",
18
+ "@nocobase/database": "0.7.6-alpha.1",
19
+ "@nocobase/resourcer": "0.7.6-alpha.1",
20
20
  "chalk": "^4.1.1",
21
21
  "commander": "^9.2.0",
22
22
  "find-package-json": "^1.2.0",
23
- "i18next": "^21.3.2",
23
+ "i18next": "^21.6.0",
24
24
  "koa": "^2.13.4",
25
25
  "koa-bodyparser": "^4.3.0",
26
26
  "koa-static": "^5.0.0",
@@ -30,5 +30,5 @@
30
30
  "devDependencies": {
31
31
  "@types/semver": "^7.3.9"
32
32
  },
33
- "gitHead": "77f22e6da464d19be111835316faf4b94cd80413"
33
+ "gitHead": "f20ce011a9ac516dc6aec110979f063a0e63f923"
34
34
  }