@nocobase/server 0.8.1-alpha.4 → 0.9.0-alpha.2
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/acl/index.js +1 -1
- package/lib/middlewares/data-wrapping.js +4 -0
- package/lib/middlewares/i18n.js +7 -1
- package/lib/plugin-manager/PluginManager.d.ts +1 -0
- package/lib/plugin-manager/PluginManager.js +25 -17
- package/lib/plugin.d.ts +2 -0
- package/lib/plugin.js +16 -0
- package/package.json +8 -14
package/lib/acl/index.js
CHANGED
|
@@ -29,7 +29,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
29
29
|
|
|
30
30
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
31
31
|
|
|
32
|
-
const configureResources = ['roles', 'collections', 'roles.collections', 'roles.resources', 'rolesResourcesScopes', 'availableActions'];
|
|
32
|
+
const configureResources = ['roles', 'users', 'collections', 'fields', 'collections.fields', 'roles.collections', 'roles.resources', 'rolesResourcesScopes', 'availableActions'];
|
|
33
33
|
|
|
34
34
|
function createACL() {
|
|
35
35
|
const acl = new (_acl().ACL)();
|
package/lib/middlewares/i18n.js
CHANGED
|
@@ -20,7 +20,13 @@ function _i18n() {
|
|
|
20
20
|
});
|
|
21
21
|
ctx.i18n = i18n;
|
|
22
22
|
ctx.t = i18n.t.bind(i18n);
|
|
23
|
-
|
|
23
|
+
|
|
24
|
+
ctx.getCurrentLocale = () => {
|
|
25
|
+
const lng = ctx.get('X-Locale') || ctx.request.query.locale || ctx.app.i18n.language || ctx.acceptsLanguages().shift() || 'en-US';
|
|
26
|
+
return lng;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const lng = ctx.getCurrentLocale();
|
|
24
30
|
|
|
25
31
|
if (lng !== '*' && lng) {
|
|
26
32
|
i18n.changeLanguage(lng);
|
|
@@ -31,6 +31,7 @@ export declare class PluginManager {
|
|
|
31
31
|
create(name: string | string[]): Promise<void>;
|
|
32
32
|
clone(): PluginManager;
|
|
33
33
|
addStatic(plugin?: any, options?: any): any;
|
|
34
|
+
generateClientFile(plugin: string, packageName: string): Promise<void>;
|
|
34
35
|
add(plugin: any, options?: any, transaction?: any): any;
|
|
35
36
|
load(options?: any): Promise<void>;
|
|
36
37
|
install(options?: InstallOptions): Promise<void>;
|
|
@@ -124,8 +124,10 @@ class PluginManager {
|
|
|
124
124
|
this.repository = this.collection.repository;
|
|
125
125
|
this.repository.setPluginManager(this);
|
|
126
126
|
this.app.resourcer.define(_resource.default);
|
|
127
|
-
this.app.acl.
|
|
128
|
-
|
|
127
|
+
this.app.acl.registerSnippet({
|
|
128
|
+
name: 'pm',
|
|
129
|
+
actions: ['pm:*', 'applicationPlugins:list']
|
|
130
|
+
});
|
|
129
131
|
this.server = _net().default.createServer(socket => {
|
|
130
132
|
socket.on('data', /*#__PURE__*/function () {
|
|
131
133
|
var _ref = _asyncToGenerator(function* (data) {
|
|
@@ -342,6 +344,25 @@ class PluginManager {
|
|
|
342
344
|
return instance;
|
|
343
345
|
}
|
|
344
346
|
|
|
347
|
+
generateClientFile(plugin, packageName) {
|
|
348
|
+
return _asyncToGenerator(function* () {
|
|
349
|
+
const file = (0, _path().resolve)(process.cwd(), 'packages', process.env.APP_PACKAGE_ROOT || 'app', 'client/src/plugins', `${plugin}.ts`);
|
|
350
|
+
|
|
351
|
+
if (!_fs().default.existsSync(file)) {
|
|
352
|
+
try {
|
|
353
|
+
require.resolve(`${packageName}/client`);
|
|
354
|
+
|
|
355
|
+
yield _fs().default.promises.writeFile(file, `export { default } from '${packageName}/client';`);
|
|
356
|
+
|
|
357
|
+
const _require3 = require('@nocobase/cli/src/util'),
|
|
358
|
+
run = _require3.run;
|
|
359
|
+
|
|
360
|
+
yield run('yarn', ['nocobase', 'postinstall']);
|
|
361
|
+
} catch (error) {}
|
|
362
|
+
}
|
|
363
|
+
})();
|
|
364
|
+
}
|
|
365
|
+
|
|
345
366
|
add(plugin, options = {}, transaction) {
|
|
346
367
|
var _this4 = this;
|
|
347
368
|
|
|
@@ -363,6 +384,8 @@ class PluginManager {
|
|
|
363
384
|
|
|
364
385
|
const packageJson = require(`${packageName}/package.json`);
|
|
365
386
|
|
|
387
|
+
yield _this4.generateClientFile(plugin, packageName);
|
|
388
|
+
|
|
366
389
|
const instance = _this4.addStatic(plugin, _objectSpread(_objectSpread({}, options), {}, {
|
|
367
390
|
async: true
|
|
368
391
|
}));
|
|
@@ -393,21 +416,6 @@ class PluginManager {
|
|
|
393
416
|
});
|
|
394
417
|
}
|
|
395
418
|
|
|
396
|
-
const file = (0, _path().resolve)(process.cwd(), 'packages', process.env.APP_PACKAGE_ROOT || 'app', 'client/src/plugins', `${plugin}.ts`);
|
|
397
|
-
|
|
398
|
-
if (!_fs().default.existsSync(file)) {
|
|
399
|
-
try {
|
|
400
|
-
require.resolve(`${packageName}/client`);
|
|
401
|
-
|
|
402
|
-
yield _fs().default.promises.writeFile(file, `export { default } from '${packageName}/client';`);
|
|
403
|
-
|
|
404
|
-
const _require3 = require('@nocobase/cli/src/util'),
|
|
405
|
-
run = _require3.run;
|
|
406
|
-
|
|
407
|
-
yield run('yarn', ['nocobase', 'postinstall']);
|
|
408
|
-
} catch (error) {}
|
|
409
|
-
}
|
|
410
|
-
|
|
411
419
|
return instance;
|
|
412
420
|
})();
|
|
413
421
|
}
|
package/lib/plugin.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
|
|
|
21
21
|
options: any;
|
|
22
22
|
app: Application;
|
|
23
23
|
constructor(app: Application, options?: any);
|
|
24
|
+
get name(): string;
|
|
24
25
|
get db(): import("@nocobase/database").default;
|
|
25
26
|
get enabled(): any;
|
|
26
27
|
set enabled(value: any);
|
|
@@ -33,5 +34,6 @@ export declare abstract class Plugin<O = any> implements PluginInterface {
|
|
|
33
34
|
afterEnable(): Promise<void>;
|
|
34
35
|
afterDisable(): Promise<void>;
|
|
35
36
|
remove(): Promise<void>;
|
|
37
|
+
importCollections(collectionsPath: string): Promise<void>;
|
|
36
38
|
}
|
|
37
39
|
export default Plugin;
|
package/lib/plugin.js
CHANGED
|
@@ -13,11 +13,16 @@ class Plugin {
|
|
|
13
13
|
constructor(app, options) {
|
|
14
14
|
this.options = void 0;
|
|
15
15
|
this.app = void 0;
|
|
16
|
+
this.setOptions(options);
|
|
16
17
|
this.app = app;
|
|
17
18
|
this.setOptions(options);
|
|
18
19
|
this.afterAdd();
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
get name() {
|
|
23
|
+
return this.options.name;
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
get db() {
|
|
22
27
|
return this.app.db;
|
|
23
28
|
}
|
|
@@ -62,6 +67,17 @@ class Plugin {
|
|
|
62
67
|
return _asyncToGenerator(function* () {})();
|
|
63
68
|
}
|
|
64
69
|
|
|
70
|
+
importCollections(collectionsPath) {
|
|
71
|
+
var _this = this;
|
|
72
|
+
|
|
73
|
+
return _asyncToGenerator(function* () {
|
|
74
|
+
yield _this.db.import({
|
|
75
|
+
directory: collectionsPath,
|
|
76
|
+
from: _this.getName()
|
|
77
|
+
});
|
|
78
|
+
})();
|
|
79
|
+
}
|
|
80
|
+
|
|
65
81
|
}
|
|
66
82
|
|
|
67
83
|
exports.Plugin = Plugin;
|
package/package.json
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-alpha.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
|
-
"licenses": [
|
|
8
|
-
{
|
|
9
|
-
"type": "Apache-2.0",
|
|
10
|
-
"url": "http://www.apache.org/licenses/LICENSE-2.0"
|
|
11
|
-
}
|
|
12
|
-
],
|
|
13
7
|
"dependencies": {
|
|
14
8
|
"@hapi/topo": "^6.0.0",
|
|
15
9
|
"@koa/cors": "^3.1.0",
|
|
16
10
|
"@koa/router": "^9.4.0",
|
|
17
|
-
"@nocobase/acl": "0.
|
|
18
|
-
"@nocobase/actions": "0.
|
|
19
|
-
"@nocobase/database": "0.
|
|
20
|
-
"@nocobase/logger": "0.
|
|
21
|
-
"@nocobase/resourcer": "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",
|
|
22
16
|
"chalk": "^4.1.1",
|
|
23
17
|
"commander": "^9.2.0",
|
|
24
18
|
"find-package-json": "^1.2.0",
|
|
25
|
-
"i18next": "^
|
|
19
|
+
"i18next": "^22.4.9",
|
|
26
20
|
"koa": "^2.13.4",
|
|
27
21
|
"koa-bodyparser": "^4.3.0",
|
|
28
22
|
"koa-static": "^5.0.0",
|
|
@@ -33,5 +27,5 @@
|
|
|
33
27
|
"devDependencies": {
|
|
34
28
|
"@types/semver": "^7.3.9"
|
|
35
29
|
},
|
|
36
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "b8f76ad38e60e677c5bb4aab0a4cdb28d98a0f49"
|
|
37
31
|
}
|