@nocobase/server 0.7.7-alpha.1 → 0.8.0-alpha.5
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 +35 -28
- package/lib/application.js +214 -121
- package/lib/commands/index.js +3 -1
- package/lib/commands/pm.d.ts +3 -0
- package/lib/commands/pm.js +27 -0
- package/lib/helper.js +29 -22
- package/lib/middlewares/data-wrapping.js +40 -15
- package/lib/middlewares/{table2resource.d.ts → db2resource.d.ts} +3 -3
- package/lib/middlewares/{table2resource.js → db2resource.js} +3 -3
- package/lib/middlewares/i18n.d.ts +1 -0
- package/lib/middlewares/i18n.js +32 -0
- package/lib/middlewares/index.d.ts +1 -1
- package/lib/middlewares/index.js +8 -8
- package/lib/plugin-manager/PluginManager.d.ts +43 -0
- package/lib/plugin-manager/PluginManager.js +669 -0
- package/lib/plugin-manager/PluginManagerRepository.d.ts +10 -0
- package/lib/plugin-manager/PluginManagerRepository.js +121 -0
- package/lib/plugin-manager/index.d.ts +1 -0
- package/lib/plugin-manager/index.js +18 -0
- package/lib/plugin-manager/options/collection.d.ts +14 -0
- package/lib/plugin-manager/options/collection.js +31 -0
- package/lib/plugin-manager/options/resource.d.ts +11 -0
- package/lib/plugin-manager/options/resource.js +84 -0
- package/lib/plugin.d.ts +12 -7
- package/lib/plugin.js +25 -30
- package/package.json +9 -7
- package/lib/plugin-manager.d.ts +0 -26
- package/lib/plugin-manager.js +0 -130
package/lib/helper.js
CHANGED
|
@@ -60,7 +60,9 @@ function _koaBodyparser() {
|
|
|
60
60
|
|
|
61
61
|
var _dataWrapping = require("./middlewares/data-wrapping");
|
|
62
62
|
|
|
63
|
-
var
|
|
63
|
+
var _db2resource = require("./middlewares/db2resource");
|
|
64
|
+
|
|
65
|
+
var _i18n = require("./middlewares/i18n");
|
|
64
66
|
|
|
65
67
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
66
68
|
|
|
@@ -97,33 +99,25 @@ function createResourcer(options) {
|
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
function registerMiddlewares(app, options) {
|
|
102
|
+
app.use((0, _cors().default)(_objectSpread({
|
|
103
|
+
exposeHeaders: ['content-disposition']
|
|
104
|
+
}, options.cors)), {
|
|
105
|
+
tag: 'cors',
|
|
106
|
+
after: 'bodyParser'
|
|
107
|
+
});
|
|
108
|
+
|
|
100
109
|
if (options.bodyParser !== false) {
|
|
101
|
-
app.use((0, _koaBodyparser().default)(_objectSpread({}, options.bodyParser))
|
|
110
|
+
app.use((0, _koaBodyparser().default)(_objectSpread({}, options.bodyParser)), {
|
|
111
|
+
tag: 'bodyParser'
|
|
112
|
+
});
|
|
102
113
|
}
|
|
103
114
|
|
|
104
|
-
app.use((0, _cors().default)(_objectSpread({
|
|
105
|
-
exposeHeaders: ['content-disposition']
|
|
106
|
-
}, options.cors)));
|
|
107
115
|
app.use( /*#__PURE__*/function () {
|
|
108
116
|
var _ref = _asyncToGenerator(function* (ctx, next) {
|
|
109
117
|
ctx.getBearerToken = () => {
|
|
110
118
|
return ctx.get('Authorization').replace(/^Bearer\s+/gi, '');
|
|
111
119
|
};
|
|
112
120
|
|
|
113
|
-
ctx.db = app.db;
|
|
114
|
-
ctx.cache = app.cache;
|
|
115
|
-
ctx.resourcer = app.resourcer;
|
|
116
|
-
const i18n = app.i18n.cloneInstance({
|
|
117
|
-
initImmediate: false
|
|
118
|
-
});
|
|
119
|
-
ctx.i18n = i18n;
|
|
120
|
-
ctx.t = i18n.t.bind(i18n);
|
|
121
|
-
const lng = ctx.get('X-Locale') || ctx.request.query.locale || app.i18n.language || ctx.acceptsLanguages().shift() || 'en-US';
|
|
122
|
-
|
|
123
|
-
if (lng !== '*' && lng) {
|
|
124
|
-
i18n.changeLanguage(lng);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
121
|
yield next();
|
|
128
122
|
});
|
|
129
123
|
|
|
@@ -131,11 +125,24 @@ function registerMiddlewares(app, options) {
|
|
|
131
125
|
return _ref.apply(this, arguments);
|
|
132
126
|
};
|
|
133
127
|
}());
|
|
128
|
+
app.use(_i18n.i18n, {
|
|
129
|
+
tag: 'i18n',
|
|
130
|
+
after: 'cors'
|
|
131
|
+
});
|
|
134
132
|
|
|
135
133
|
if (options.dataWrapping !== false) {
|
|
136
|
-
app.use((0, _dataWrapping.dataWrapping)()
|
|
134
|
+
app.use((0, _dataWrapping.dataWrapping)(), {
|
|
135
|
+
tag: 'dataWrapping',
|
|
136
|
+
after: 'i18n'
|
|
137
|
+
});
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
app.use(
|
|
140
|
-
|
|
140
|
+
app.use(_db2resource.db2resource, {
|
|
141
|
+
tag: 'db2resource',
|
|
142
|
+
after: 'dataWrapping'
|
|
143
|
+
});
|
|
144
|
+
app.use(app.resourcer.restApiMiddleware(), {
|
|
145
|
+
tag: 'restApi',
|
|
146
|
+
after: 'db2resource'
|
|
147
|
+
});
|
|
141
148
|
}
|
|
@@ -5,8 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.dataWrapping = dataWrapping;
|
|
7
7
|
exports.default = void 0;
|
|
8
|
+
|
|
9
|
+
function _stream() {
|
|
10
|
+
const data = _interopRequireDefault(require("stream"));
|
|
11
|
+
|
|
12
|
+
_stream = function _stream() {
|
|
13
|
+
return data;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
|
|
8
19
|
const _excluded = ["rows"];
|
|
9
20
|
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
|
|
10
23
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
11
24
|
|
|
12
25
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
@@ -18,15 +31,16 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
18
31
|
function dataWrapping() {
|
|
19
32
|
return /*#__PURE__*/function () {
|
|
20
33
|
var _dataWrapping = _asyncToGenerator(function* (ctx, next) {
|
|
21
|
-
var _ctx$action;
|
|
22
|
-
|
|
23
34
|
yield next();
|
|
24
35
|
|
|
25
36
|
if (ctx.withoutDataWrapping) {
|
|
26
37
|
return;
|
|
27
|
-
}
|
|
38
|
+
} // if (!ctx?.action?.params) {
|
|
39
|
+
// return;
|
|
40
|
+
// }
|
|
41
|
+
|
|
28
42
|
|
|
29
|
-
if (
|
|
43
|
+
if (ctx.body instanceof _stream().default.Readable) {
|
|
30
44
|
return;
|
|
31
45
|
}
|
|
32
46
|
|
|
@@ -35,24 +49,35 @@ function dataWrapping() {
|
|
|
35
49
|
}
|
|
36
50
|
|
|
37
51
|
if (!ctx.body) {
|
|
38
|
-
|
|
52
|
+
var _ctx$action;
|
|
53
|
+
|
|
54
|
+
if (((_ctx$action = ctx.action) === null || _ctx$action === void 0 ? void 0 : _ctx$action.actionName) == 'get') {
|
|
39
55
|
ctx.status = 200;
|
|
40
56
|
}
|
|
41
57
|
}
|
|
42
58
|
|
|
43
|
-
|
|
44
|
-
rows = _ref.rows,
|
|
45
|
-
meta = _objectWithoutProperties(_ref, _excluded);
|
|
46
|
-
|
|
47
|
-
if (rows) {
|
|
48
|
-
ctx.body = {
|
|
49
|
-
data: rows,
|
|
50
|
-
meta
|
|
51
|
-
};
|
|
52
|
-
} else {
|
|
59
|
+
if (Array.isArray(ctx.body)) {
|
|
53
60
|
ctx.body = {
|
|
54
61
|
data: ctx.body
|
|
55
62
|
};
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (ctx.body) {
|
|
67
|
+
const _ctx$body = ctx.body,
|
|
68
|
+
rows = _ctx$body.rows,
|
|
69
|
+
meta = _objectWithoutProperties(_ctx$body, _excluded);
|
|
70
|
+
|
|
71
|
+
if (rows) {
|
|
72
|
+
ctx.body = {
|
|
73
|
+
data: rows,
|
|
74
|
+
meta
|
|
75
|
+
};
|
|
76
|
+
} else {
|
|
77
|
+
ctx.body = {
|
|
78
|
+
data: ctx.body
|
|
79
|
+
};
|
|
80
|
+
}
|
|
56
81
|
}
|
|
57
82
|
});
|
|
58
83
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ResourcerContext } from '@nocobase/resourcer';
|
|
2
1
|
import Database from '@nocobase/database';
|
|
3
|
-
|
|
2
|
+
import { ResourcerContext } from '@nocobase/resourcer';
|
|
3
|
+
export declare function db2resource(ctx: ResourcerContext & {
|
|
4
4
|
db: Database;
|
|
5
5
|
}, next: () => Promise<any>): Promise<any>;
|
|
6
|
-
export default
|
|
6
|
+
export default db2resource;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.db2resource = db2resource;
|
|
6
7
|
exports.default = void 0;
|
|
7
|
-
exports.table2resource = table2resource;
|
|
8
8
|
|
|
9
9
|
function _resourcer() {
|
|
10
10
|
const data = require("@nocobase/resourcer");
|
|
@@ -28,7 +28,7 @@ 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
|
|
31
|
+
function db2resource(ctx, next) {
|
|
32
32
|
const resourcer = ctx.resourcer;
|
|
33
33
|
const database = ctx.db;
|
|
34
34
|
let params = (0, _resourcer().parseRequest)({
|
|
@@ -74,5 +74,5 @@ function table2resource(ctx, next) {
|
|
|
74
74
|
return next();
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
var _default =
|
|
77
|
+
var _default = db2resource;
|
|
78
78
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function i18n(ctx: any, next: any): Promise<void>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.i18n = i18n;
|
|
7
|
+
|
|
8
|
+
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); } }
|
|
9
|
+
|
|
10
|
+
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); }); }; }
|
|
11
|
+
|
|
12
|
+
function i18n(_x, _x2) {
|
|
13
|
+
return _i18n.apply(this, arguments);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function _i18n() {
|
|
17
|
+
_i18n = _asyncToGenerator(function* (ctx, next) {
|
|
18
|
+
const i18n = ctx.app.i18n.cloneInstance({
|
|
19
|
+
initImmediate: false
|
|
20
|
+
});
|
|
21
|
+
ctx.i18n = i18n;
|
|
22
|
+
ctx.t = i18n.t.bind(i18n);
|
|
23
|
+
const lng = ctx.get('X-Locale') || ctx.request.query.locale || ctx.app.i18n.language || ctx.acceptsLanguages().shift() || 'en-US';
|
|
24
|
+
|
|
25
|
+
if (lng !== '*' && lng) {
|
|
26
|
+
i18n.changeLanguage(lng);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
yield next();
|
|
30
|
+
});
|
|
31
|
+
return _i18n.apply(this, arguments);
|
|
32
|
+
}
|
package/lib/middlewares/index.js
CHANGED
|
@@ -4,28 +4,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _dataWrapping = require("./data-wrapping");
|
|
8
8
|
|
|
9
|
-
Object.keys(
|
|
9
|
+
Object.keys(_dataWrapping).forEach(function (key) {
|
|
10
10
|
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (key in exports && exports[key] ===
|
|
11
|
+
if (key in exports && exports[key] === _dataWrapping[key]) return;
|
|
12
12
|
Object.defineProperty(exports, key, {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function get() {
|
|
15
|
-
return
|
|
15
|
+
return _dataWrapping[key];
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _db2resource = require("./db2resource");
|
|
21
21
|
|
|
22
|
-
Object.keys(
|
|
22
|
+
Object.keys(_db2resource).forEach(function (key) {
|
|
23
23
|
if (key === "default" || key === "__esModule") return;
|
|
24
|
-
if (key in exports && exports[key] ===
|
|
24
|
+
if (key in exports && exports[key] === _db2resource[key]) return;
|
|
25
25
|
Object.defineProperty(exports, key, {
|
|
26
26
|
enumerable: true,
|
|
27
27
|
get: function get() {
|
|
28
|
-
return
|
|
28
|
+
return _db2resource[key];
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { CleanOptions, Collection, SyncOptions } from '@nocobase/database';
|
|
3
|
+
import net from 'net';
|
|
4
|
+
import Application from '../application';
|
|
5
|
+
import { Plugin } from '../plugin';
|
|
6
|
+
import { PluginManagerRepository } from './PluginManagerRepository';
|
|
7
|
+
export interface PluginManagerOptions {
|
|
8
|
+
app: Application;
|
|
9
|
+
plugins?: any[];
|
|
10
|
+
}
|
|
11
|
+
export interface InstallOptions {
|
|
12
|
+
cliArgs?: any[];
|
|
13
|
+
clean?: CleanOptions | boolean;
|
|
14
|
+
sync?: SyncOptions;
|
|
15
|
+
}
|
|
16
|
+
export declare class PluginManager {
|
|
17
|
+
app: Application;
|
|
18
|
+
collection: Collection;
|
|
19
|
+
repository: PluginManagerRepository;
|
|
20
|
+
plugins: Map<string, Plugin<any>>;
|
|
21
|
+
server: net.Server;
|
|
22
|
+
pmSock: string;
|
|
23
|
+
_tmpPluginArgs: any[];
|
|
24
|
+
constructor(options: PluginManagerOptions);
|
|
25
|
+
addStaticMultiple(plugins: any): void;
|
|
26
|
+
getPlugins(): Map<string, Plugin<any>>;
|
|
27
|
+
get(name: string): Plugin<any>;
|
|
28
|
+
clientWrite(data: any): void;
|
|
29
|
+
listen(): Promise<net.Server>;
|
|
30
|
+
create(name: string | string[]): Promise<void>;
|
|
31
|
+
clone(): PluginManager;
|
|
32
|
+
addStatic(plugin?: any, options?: any): any;
|
|
33
|
+
add(plugin: any, options?: any): any;
|
|
34
|
+
load(options?: any): Promise<void>;
|
|
35
|
+
install(options?: InstallOptions): Promise<void>;
|
|
36
|
+
enable(name: string | string[]): Promise<void>;
|
|
37
|
+
disable(name: string | string[]): Promise<void>;
|
|
38
|
+
remove(name: string | string[]): Promise<void>;
|
|
39
|
+
static getPackageName(name: string): string;
|
|
40
|
+
static findPackage(name: string): Promise<string>;
|
|
41
|
+
static resolvePlugin(pluginName: string): any;
|
|
42
|
+
}
|
|
43
|
+
export default PluginManager;
|