@nocobase/server 1.2.7-alpha → 1.2.9-alpha

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.
@@ -7,7 +7,13 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
  import { Cache } from '@nocobase/cache';
10
+ import { Registry } from '@nocobase/utils';
10
11
  import Application from '../application';
12
+ export interface ResourceStorer {
13
+ getResources(lang: string): Promise<{
14
+ [ns: string]: Record<string, string>;
15
+ }>;
16
+ }
11
17
  export declare class Locale {
12
18
  app: Application;
13
19
  cache: Cache;
@@ -15,15 +21,18 @@ export declare class Locale {
15
21
  localeFn: Map<any, any>;
16
22
  resourceCached: Map<any, any>;
17
23
  i18nInstances: Map<any, any>;
24
+ resourceStorers: Registry<ResourceStorer>;
18
25
  constructor(app: Application);
19
26
  load(): Promise<void>;
27
+ reload(): Promise<void>;
20
28
  setLocaleFn(name: string, fn: (lang: string) => Promise<any>): void;
29
+ registerResourceStorer(name: string, storer: ResourceStorer): void;
21
30
  get(lang: string): Promise<{
22
31
  resources: any;
23
32
  }>;
24
33
  wrapCache(key: string, fn: () => any): Promise<any>;
25
34
  loadResourcesByLang(lang: string): Promise<void>;
26
35
  getCacheResources(lang: string): Promise<any>;
27
- getResources(lang: string): {};
36
+ getResources(lang: string): Promise<{}>;
28
37
  getI18nInstance(lang: string): Promise<any>;
29
38
  }
@@ -7,9 +7,11 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
+ var __create = Object.create;
10
11
  var __defProp = Object.defineProperty;
11
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
13
  var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
13
15
  var __hasOwnProp = Object.prototype.hasOwnProperty;
14
16
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
17
  var __export = (target, all) => {
@@ -24,6 +26,14 @@ var __copyProps = (to, from, except, desc) => {
24
26
  }
25
27
  return to;
26
28
  };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
27
37
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
38
  var locale_exports = {};
29
39
  __export(locale_exports, {
@@ -33,6 +43,7 @@ module.exports = __toCommonJS(locale_exports);
33
43
  var import_utils = require("@nocobase/utils");
34
44
  var import_resource = require("./resource");
35
45
  var import__ = require("..");
46
+ var import_deepmerge = __toESM(require("deepmerge"));
36
47
  const _Locale = class _Locale {
37
48
  app;
38
49
  cache;
@@ -40,6 +51,7 @@ const _Locale = class _Locale {
40
51
  localeFn = /* @__PURE__ */ new Map();
41
52
  resourceCached = /* @__PURE__ */ new Map();
42
53
  i18nInstances = /* @__PURE__ */ new Map();
54
+ resourceStorers = new import_utils.Registry();
43
55
  constructor(app) {
44
56
  this.app = app;
45
57
  this.app.on("afterLoad", async () => {
@@ -58,9 +70,15 @@ const _Locale = class _Locale {
58
70
  });
59
71
  await this.get(this.defaultLang);
60
72
  }
73
+ async reload() {
74
+ await this.cache.reset();
75
+ }
61
76
  setLocaleFn(name, fn) {
62
77
  this.localeFn.set(name, fn);
63
78
  }
79
+ registerResourceStorer(name, storer) {
80
+ this.resourceStorers.register(name, storer);
81
+ }
64
82
  async get(lang) {
65
83
  const defaults = {
66
84
  resources: await this.getCacheResources(lang)
@@ -89,11 +107,11 @@ const _Locale = class _Locale {
89
107
  async getCacheResources(lang) {
90
108
  this.resourceCached.set(lang, true);
91
109
  if (process.env.APP_ENV !== "production") {
92
- await this.cache.reset();
110
+ await this.reload();
93
111
  }
94
112
  return await this.wrapCache(`resources:${lang}`, () => this.getResources(lang));
95
113
  }
96
- getResources(lang) {
114
+ async getResources(lang) {
97
115
  var _a;
98
116
  const resources = {};
99
117
  const names = this.app.pm.getPlugins().keys();
@@ -117,6 +135,20 @@ const _Locale = class _Locale {
117
135
  } catch (err) {
118
136
  }
119
137
  }
138
+ const storers = this.resourceStorers.getValues();
139
+ for (const storer of storers) {
140
+ const custom = await storer.getResources(lang);
141
+ Object.keys(custom).forEach((key) => {
142
+ const module2 = key.replace("resources.", "");
143
+ const resource = resources[module2];
144
+ const customResource = custom[key];
145
+ resources[module2] = resource ? (0, import_deepmerge.default)(resource, customResource) : customResource;
146
+ const pkgName = `${import__.OFFICIAL_PLUGIN_PREFIX}${module2}`;
147
+ if (resources[pkgName]) {
148
+ resources[pkgName] = { ...resources[module2] };
149
+ }
150
+ });
151
+ }
120
152
  Object.keys(resources).forEach((name) => {
121
153
  this.app.i18n.addResources(lang, name, resources[name]);
122
154
  });
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
2
  "name": "@nocobase/server",
3
- "version": "1.2.7-alpha",
3
+ "version": "1.2.9-alpha",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "AGPL-3.0",
7
7
  "dependencies": {
8
- "@formily/json-schema": "2.2.27",
8
+ "@formily/json-schema": "2.x",
9
9
  "@hapi/topo": "^6.0.0",
10
10
  "@koa/cors": "^3.1.0",
11
11
  "@koa/multer": "^3.0.2",
12
12
  "@koa/router": "^9.4.0",
13
- "@nocobase/acl": "1.2.7-alpha",
14
- "@nocobase/actions": "1.2.7-alpha",
15
- "@nocobase/auth": "1.2.7-alpha",
16
- "@nocobase/cache": "1.2.7-alpha",
17
- "@nocobase/data-source-manager": "1.2.7-alpha",
18
- "@nocobase/database": "1.2.7-alpha",
19
- "@nocobase/evaluators": "1.2.7-alpha",
20
- "@nocobase/logger": "1.2.7-alpha",
21
- "@nocobase/resourcer": "1.2.7-alpha",
22
- "@nocobase/sdk": "1.2.7-alpha",
23
- "@nocobase/telemetry": "1.2.7-alpha",
24
- "@nocobase/utils": "1.2.7-alpha",
13
+ "@nocobase/acl": "1.2.9-alpha",
14
+ "@nocobase/actions": "1.2.9-alpha",
15
+ "@nocobase/auth": "1.2.9-alpha",
16
+ "@nocobase/cache": "1.2.9-alpha",
17
+ "@nocobase/data-source-manager": "1.2.9-alpha",
18
+ "@nocobase/database": "1.2.9-alpha",
19
+ "@nocobase/evaluators": "1.2.9-alpha",
20
+ "@nocobase/logger": "1.2.9-alpha",
21
+ "@nocobase/resourcer": "1.2.9-alpha",
22
+ "@nocobase/sdk": "1.2.9-alpha",
23
+ "@nocobase/telemetry": "1.2.9-alpha",
24
+ "@nocobase/utils": "1.2.9-alpha",
25
25
  "@types/decompress": "4.2.4",
26
26
  "@types/ini": "^1.3.31",
27
27
  "@types/koa-send": "^4.1.3",
@@ -54,5 +54,5 @@
54
54
  "@types/serve-handler": "^6.1.1",
55
55
  "@types/ws": "^8.5.5"
56
56
  },
57
- "gitHead": "393313a2a7d183ac72311484e452a2143a90fd02"
57
+ "gitHead": "b80e4678e8098d60755195ec63f865122aba021a"
58
58
  }