@nocobase/server 0.15.0-alpha.4 → 0.16.0-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/application.d.ts +5 -5
- package/lib/application.js +14 -30
- package/lib/cache/index.d.ts +3 -0
- package/lib/cache/index.js +35 -0
- package/lib/locale/locale.js +10 -14
- package/package.json +12 -12
package/lib/application.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="koa-bodyparser" />
|
|
3
3
|
import { ACL } from '@nocobase/acl';
|
|
4
4
|
import { AuthManager, AuthManagerOptions } from '@nocobase/auth';
|
|
5
|
-
import { Cache,
|
|
5
|
+
import { CacheManagerOptions, Cache, CacheManager } from '@nocobase/cache';
|
|
6
6
|
import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';
|
|
7
7
|
import { AppLoggerOptions, Logger } from '@nocobase/logger';
|
|
8
8
|
import { ResourceOptions, Resourcer } from '@nocobase/resourcer';
|
|
@@ -25,7 +25,7 @@ export interface ResourcerOptions {
|
|
|
25
25
|
}
|
|
26
26
|
export interface ApplicationOptions {
|
|
27
27
|
database?: IDatabaseOptions | Database;
|
|
28
|
-
|
|
28
|
+
cacheManager?: CacheManagerOptions;
|
|
29
29
|
resourcer?: ResourcerOptions;
|
|
30
30
|
bodyParser?: any;
|
|
31
31
|
cors?: any;
|
|
@@ -101,7 +101,10 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
101
101
|
get logger(): Logger;
|
|
102
102
|
protected _resourcer: Resourcer;
|
|
103
103
|
get resourcer(): Resourcer;
|
|
104
|
+
protected _cacheManager: CacheManager;
|
|
105
|
+
get cacheManager(): CacheManager;
|
|
104
106
|
protected _cache: Cache;
|
|
107
|
+
set cache(cache: Cache);
|
|
105
108
|
get cache(): Cache;
|
|
106
109
|
protected _cli: AppCommand;
|
|
107
110
|
get cli(): AppCommand;
|
|
@@ -149,9 +152,6 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
149
152
|
restart(options?: StartOptions): Promise<void>;
|
|
150
153
|
stop(options?: any): Promise<void>;
|
|
151
154
|
destroy(options?: any): Promise<void>;
|
|
152
|
-
dbVersionCheck(options?: {
|
|
153
|
-
exit?: boolean;
|
|
154
|
-
}): Promise<boolean>;
|
|
155
155
|
isInstalled(): Promise<boolean>;
|
|
156
156
|
install(options?: InstallOptions): Promise<void>;
|
|
157
157
|
upgrade(options?: any): Promise<void>;
|
package/lib/application.js
CHANGED
|
@@ -34,7 +34,6 @@ __export(application_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(application_exports);
|
|
35
35
|
var import_actions = require("@nocobase/actions");
|
|
36
36
|
var import_auth = require("@nocobase/auth");
|
|
37
|
-
var import_cache = require("@nocobase/cache");
|
|
38
37
|
var import_database = __toESM(require("@nocobase/database"));
|
|
39
38
|
var import_logger = require("@nocobase/logger");
|
|
40
39
|
var import_utils = require("@nocobase/utils");
|
|
@@ -52,6 +51,7 @@ var import_application_version = require("./helpers/application-version");
|
|
|
52
51
|
var import_locale = require("./locale");
|
|
53
52
|
var import_plugin_manager = require("./plugin-manager");
|
|
54
53
|
var import_cron_job_manager = require("./cron/cron-job-manager");
|
|
54
|
+
var import_cache2 = require("./cache");
|
|
55
55
|
const packageJson = require("../package.json");
|
|
56
56
|
const _Application = class _Application extends import_koa.default {
|
|
57
57
|
constructor(options) {
|
|
@@ -99,7 +99,14 @@ const _Application = class _Application extends import_koa.default {
|
|
|
99
99
|
get resourcer() {
|
|
100
100
|
return this._resourcer;
|
|
101
101
|
}
|
|
102
|
+
_cacheManager;
|
|
103
|
+
get cacheManager() {
|
|
104
|
+
return this._cacheManager;
|
|
105
|
+
}
|
|
102
106
|
_cache;
|
|
107
|
+
set cache(cache) {
|
|
108
|
+
this._cache = cache;
|
|
109
|
+
}
|
|
103
110
|
get cache() {
|
|
104
111
|
return this._cache;
|
|
105
112
|
}
|
|
@@ -207,7 +214,11 @@ const _Application = class _Application extends import_koa.default {
|
|
|
207
214
|
if (!oldDb.closed()) {
|
|
208
215
|
await oldDb.close();
|
|
209
216
|
}
|
|
217
|
+
if (this._cacheManager) {
|
|
218
|
+
await this._cacheManager.close();
|
|
219
|
+
}
|
|
210
220
|
}
|
|
221
|
+
this._cacheManager = await (0, import_cache2.createCacheManager)(this, this.options.cacheManager);
|
|
211
222
|
this.setMaintainingMessage("init plugins");
|
|
212
223
|
await this.pm.initPlugins();
|
|
213
224
|
this.setMaintainingMessage("start load");
|
|
@@ -243,7 +254,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
243
254
|
}
|
|
244
255
|
this._authenticated = true;
|
|
245
256
|
await this.db.auth();
|
|
246
|
-
await this.
|
|
257
|
+
await this.db.checkVersion();
|
|
247
258
|
await this.db.prepare();
|
|
248
259
|
}
|
|
249
260
|
async runCommand(command, ...args) {
|
|
@@ -395,33 +406,6 @@ const _Application = class _Application extends import_koa.default {
|
|
|
395
406
|
await this.emitAsync("afterDestroy", this, options);
|
|
396
407
|
this.logger.debug("finish destroy app");
|
|
397
408
|
}
|
|
398
|
-
async dbVersionCheck(options) {
|
|
399
|
-
const r = await this.db.version.satisfies({
|
|
400
|
-
mysql: ">=8.0.17",
|
|
401
|
-
sqlite: "3.x",
|
|
402
|
-
postgres: ">=10"
|
|
403
|
-
});
|
|
404
|
-
if (!r) {
|
|
405
|
-
console.log(import_chalk.default.red("The database only supports MySQL 8.0.17 and above, SQLite 3.x and PostgreSQL 10+"));
|
|
406
|
-
if (options == null ? void 0 : options.exit) {
|
|
407
|
-
process.exit();
|
|
408
|
-
}
|
|
409
|
-
return false;
|
|
410
|
-
}
|
|
411
|
-
if (this.db.inDialect("mysql")) {
|
|
412
|
-
const result = await this.db.sequelize.query(`SHOW VARIABLES LIKE 'lower_case_table_names'`, { plain: true });
|
|
413
|
-
if ((result == null ? void 0 : result.Value) === "1" && !this.db.options.underscored) {
|
|
414
|
-
console.log(
|
|
415
|
-
`Your database lower_case_table_names=1, please add ${import_chalk.default.yellow("DB_UNDERSCORED=true")} to the .env file`
|
|
416
|
-
);
|
|
417
|
-
if (options == null ? void 0 : options.exit) {
|
|
418
|
-
process.exit();
|
|
419
|
-
}
|
|
420
|
-
return false;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
return true;
|
|
424
|
-
}
|
|
425
409
|
async isInstalled() {
|
|
426
410
|
return await this.db.collectionExistsInDb("applicationVersion") || await this.db.collectionExistsInDb("collections");
|
|
427
411
|
}
|
|
@@ -515,10 +499,10 @@ const _Application = class _Application extends import_koa.default {
|
|
|
515
499
|
this._resourcer = (0, import_helper.createResourcer)(options);
|
|
516
500
|
this._cli = this.createCli();
|
|
517
501
|
this._i18n = (0, import_helper.createI18n)(options);
|
|
518
|
-
this._cache = (0, import_cache.createCache)(options.cache);
|
|
519
502
|
this.context.db = this._db;
|
|
520
503
|
this.context.logger = this._logger;
|
|
521
504
|
this.context.resourcer = this._resourcer;
|
|
505
|
+
this.context.cacheManager = this._cacheManager;
|
|
522
506
|
this.context.cache = this._cache;
|
|
523
507
|
const plugins = this._pm ? this._pm.options.plugins : options.plugins;
|
|
524
508
|
this._pm = new import_plugin_manager.PluginManager({
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cache_exports = {};
|
|
20
|
+
__export(cache_exports, {
|
|
21
|
+
createCacheManager: () => createCacheManager
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(cache_exports);
|
|
24
|
+
var import_cache = require("@nocobase/cache");
|
|
25
|
+
const createCacheManager = /* @__PURE__ */ __name(async (app, options) => {
|
|
26
|
+
const cacheManager = new import_cache.CacheManager(options);
|
|
27
|
+
const defaultCache = await cacheManager.createCache({ name: app.name });
|
|
28
|
+
app.cache = defaultCache;
|
|
29
|
+
app.context.cache = defaultCache;
|
|
30
|
+
return cacheManager;
|
|
31
|
+
}, "createCacheManager");
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
createCacheManager
|
|
35
|
+
});
|
package/lib/locale/locale.js
CHANGED
|
@@ -21,7 +21,6 @@ __export(locale_exports, {
|
|
|
21
21
|
Locale: () => Locale
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(locale_exports);
|
|
24
|
-
var import_cache = require("@nocobase/cache");
|
|
25
24
|
var import_utils = require("@nocobase/utils");
|
|
26
25
|
var import_resource = require("./resource");
|
|
27
26
|
const _Locale = class _Locale {
|
|
@@ -31,7 +30,6 @@ const _Locale = class _Locale {
|
|
|
31
30
|
localeFn = /* @__PURE__ */ new Map();
|
|
32
31
|
constructor(app) {
|
|
33
32
|
this.app = app;
|
|
34
|
-
this.cache = (0, import_cache.createCache)();
|
|
35
33
|
this.app.on("afterLoad", async () => {
|
|
36
34
|
this.app.log.debug("load locale resource");
|
|
37
35
|
this.app.setMaintainingMessage("load locale resource");
|
|
@@ -41,6 +39,11 @@ const _Locale = class _Locale {
|
|
|
41
39
|
});
|
|
42
40
|
}
|
|
43
41
|
async load() {
|
|
42
|
+
this.cache = await this.app.cacheManager.createCache({
|
|
43
|
+
name: "locale",
|
|
44
|
+
prefix: "locale",
|
|
45
|
+
store: "memory"
|
|
46
|
+
});
|
|
44
47
|
await this.get(this.defaultLang);
|
|
45
48
|
}
|
|
46
49
|
setLocaleFn(name, fn) {
|
|
@@ -51,7 +54,7 @@ const _Locale = class _Locale {
|
|
|
51
54
|
resources: await this.getCacheResources(lang)
|
|
52
55
|
};
|
|
53
56
|
for (const [name, fn] of this.localeFn) {
|
|
54
|
-
const result = await this.wrapCache(
|
|
57
|
+
const result = await this.wrapCache(`${name}:${lang}`, async () => await fn(lang));
|
|
55
58
|
if (result) {
|
|
56
59
|
defaults[name] = result;
|
|
57
60
|
}
|
|
@@ -59,19 +62,12 @@ const _Locale = class _Locale {
|
|
|
59
62
|
return defaults;
|
|
60
63
|
}
|
|
61
64
|
async wrapCache(key, fn) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
const value = await fn();
|
|
67
|
-
if (import_utils.lodash.isEmpty(value)) {
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
70
|
-
await this.cache.set(key, value);
|
|
71
|
-
return value;
|
|
65
|
+
return await this.cache.wrapWithCondition(key, fn, {
|
|
66
|
+
isCacheable: (val) => !import_utils.lodash.isEmpty(val)
|
|
67
|
+
});
|
|
72
68
|
}
|
|
73
69
|
async getCacheResources(lang) {
|
|
74
|
-
return await this.wrapCache(`
|
|
70
|
+
return await this.wrapCache(`resources:${lang}`, () => this.getResources(lang));
|
|
75
71
|
}
|
|
76
72
|
getResources(lang) {
|
|
77
73
|
var _a;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0-alpha.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
"@koa/cors": "^3.1.0",
|
|
11
11
|
"@koa/multer": "^3.0.2",
|
|
12
12
|
"@koa/router": "^9.4.0",
|
|
13
|
-
"@nocobase/acl": "0.
|
|
14
|
-
"@nocobase/actions": "0.
|
|
15
|
-
"@nocobase/auth": "0.
|
|
16
|
-
"@nocobase/cache": "0.
|
|
17
|
-
"@nocobase/database": "0.
|
|
18
|
-
"@nocobase/evaluators": "0.
|
|
19
|
-
"@nocobase/logger": "0.
|
|
20
|
-
"@nocobase/resourcer": "0.
|
|
21
|
-
"@nocobase/sdk": "0.
|
|
22
|
-
"@nocobase/utils": "0.
|
|
13
|
+
"@nocobase/acl": "0.16.0-alpha.1",
|
|
14
|
+
"@nocobase/actions": "0.16.0-alpha.1",
|
|
15
|
+
"@nocobase/auth": "0.16.0-alpha.1",
|
|
16
|
+
"@nocobase/cache": "0.16.0-alpha.1",
|
|
17
|
+
"@nocobase/database": "0.16.0-alpha.1",
|
|
18
|
+
"@nocobase/evaluators": "0.16.0-alpha.1",
|
|
19
|
+
"@nocobase/logger": "0.16.0-alpha.1",
|
|
20
|
+
"@nocobase/resourcer": "0.16.0-alpha.1",
|
|
21
|
+
"@nocobase/sdk": "0.16.0-alpha.1",
|
|
22
|
+
"@nocobase/utils": "0.16.0-alpha.1",
|
|
23
23
|
"@types/decompress": "4.2.4",
|
|
24
24
|
"@types/ini": "^1.3.31",
|
|
25
25
|
"@types/koa-send": "^4.1.3",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"@types/serve-handler": "^6.1.1",
|
|
53
53
|
"@types/ws": "^8.5.5"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "e8aaf48d169448376a06d87f090786cd7649255e"
|
|
56
56
|
}
|