@nocobase/server 0.7.6-alpha.2 → 0.8.0-alpha.10
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 +36 -28
- package/lib/application.js +221 -127
- package/lib/commands/db-sync.js +0 -1
- package/lib/commands/index.js +3 -1
- package/lib/commands/install.js +2 -0
- package/lib/commands/pm.d.ts +3 -0
- package/lib/commands/pm.js +35 -0
- package/lib/commands/start.js +2 -1
- 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 +44 -0
- package/lib/plugin-manager/PluginManager.js +673 -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
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PluginManagerRepository = void 0;
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
|
|
22
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
+
|
|
24
|
+
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; } } }; }
|
|
25
|
+
|
|
26
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
27
|
+
|
|
28
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
29
|
+
|
|
30
|
+
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); } }
|
|
31
|
+
|
|
32
|
+
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); }); }; }
|
|
33
|
+
|
|
34
|
+
class PluginManagerRepository extends _database().Repository {
|
|
35
|
+
constructor(...args) {
|
|
36
|
+
super(...args);
|
|
37
|
+
this.pm = void 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
setPluginManager(pm) {
|
|
41
|
+
this.pm = pm;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
remove(name) {
|
|
45
|
+
var _this = this;
|
|
46
|
+
|
|
47
|
+
return _asyncToGenerator(function* () {
|
|
48
|
+
yield _this.destroy({
|
|
49
|
+
filter: {
|
|
50
|
+
name
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
})();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
enable(name) {
|
|
57
|
+
var _this2 = this;
|
|
58
|
+
|
|
59
|
+
return _asyncToGenerator(function* () {
|
|
60
|
+
const pluginNames = typeof name === 'string' ? [name] : name;
|
|
61
|
+
yield _this2.update({
|
|
62
|
+
filter: {
|
|
63
|
+
name
|
|
64
|
+
},
|
|
65
|
+
values: {
|
|
66
|
+
enabled: true,
|
|
67
|
+
installed: true
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return pluginNames;
|
|
71
|
+
})();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
disable(name) {
|
|
75
|
+
var _this3 = this;
|
|
76
|
+
|
|
77
|
+
return _asyncToGenerator(function* () {
|
|
78
|
+
const pluginNames = typeof name === 'string' ? [name] : name;
|
|
79
|
+
yield _this3.update({
|
|
80
|
+
filter: {
|
|
81
|
+
name
|
|
82
|
+
},
|
|
83
|
+
values: {
|
|
84
|
+
enabled: false,
|
|
85
|
+
installed: false
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return pluginNames;
|
|
89
|
+
})();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
load() {
|
|
93
|
+
var _this4 = this;
|
|
94
|
+
|
|
95
|
+
return _asyncToGenerator(function* () {
|
|
96
|
+
const items = yield _this4.find();
|
|
97
|
+
|
|
98
|
+
var _iterator = _createForOfIteratorHelper(items),
|
|
99
|
+
_step;
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
103
|
+
const item = _step.value;
|
|
104
|
+
yield _this4.pm.addStatic(item.get('name'), _objectSpread(_objectSpread({}, item.get('options')), {}, {
|
|
105
|
+
name: item.get('name'),
|
|
106
|
+
version: item.get('version'),
|
|
107
|
+
enabled: item.get('enabled'),
|
|
108
|
+
async: true
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
} catch (err) {
|
|
112
|
+
_iterator.e(err);
|
|
113
|
+
} finally {
|
|
114
|
+
_iterator.f();
|
|
115
|
+
}
|
|
116
|
+
})();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
exports.PluginManagerRepository = PluginManagerRepository;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PluginManager';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _PluginManager = require("./PluginManager");
|
|
8
|
+
|
|
9
|
+
Object.keys(_PluginManager).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _PluginManager[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _PluginManager[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = {
|
|
8
|
+
name: 'applicationPlugins',
|
|
9
|
+
repository: 'PluginManagerRepository',
|
|
10
|
+
fields: [{
|
|
11
|
+
type: 'string',
|
|
12
|
+
name: 'name',
|
|
13
|
+
unique: true
|
|
14
|
+
}, {
|
|
15
|
+
type: 'string',
|
|
16
|
+
name: 'version'
|
|
17
|
+
}, {
|
|
18
|
+
type: 'boolean',
|
|
19
|
+
name: 'enabled'
|
|
20
|
+
}, {
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
name: 'installed'
|
|
23
|
+
}, {
|
|
24
|
+
type: 'boolean',
|
|
25
|
+
name: 'builtIn'
|
|
26
|
+
}, {
|
|
27
|
+
type: 'json',
|
|
28
|
+
name: 'options'
|
|
29
|
+
}]
|
|
30
|
+
};
|
|
31
|
+
exports.default = _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
name: string;
|
|
3
|
+
actions: {
|
|
4
|
+
add(ctx: any, next: any): Promise<void>;
|
|
5
|
+
enable(ctx: any, next: any): Promise<void>;
|
|
6
|
+
disable(ctx: any, next: any): Promise<void>;
|
|
7
|
+
upgrade(ctx: any, next: any): Promise<void>;
|
|
8
|
+
remove(ctx: any, next: any): Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
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
|
+
var _default = {
|
|
13
|
+
name: 'pm',
|
|
14
|
+
actions: {
|
|
15
|
+
add(ctx, next) {
|
|
16
|
+
return _asyncToGenerator(function* () {
|
|
17
|
+
const pm = ctx.app.pm;
|
|
18
|
+
const filterByTk = ctx.action.params.filterByTk;
|
|
19
|
+
|
|
20
|
+
if (!filterByTk) {
|
|
21
|
+
ctx.throw(400, 'plugin name invalid');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
yield pm.add(filterByTk);
|
|
25
|
+
ctx.body = filterByTk;
|
|
26
|
+
yield next();
|
|
27
|
+
})();
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
enable(ctx, next) {
|
|
31
|
+
return _asyncToGenerator(function* () {
|
|
32
|
+
const pm = ctx.app.pm;
|
|
33
|
+
const filterByTk = ctx.action.params.filterByTk;
|
|
34
|
+
|
|
35
|
+
if (!filterByTk) {
|
|
36
|
+
ctx.throw(400, 'plugin name invalid');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
yield pm.enable(filterByTk);
|
|
40
|
+
ctx.body = filterByTk;
|
|
41
|
+
yield next();
|
|
42
|
+
})();
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
disable(ctx, next) {
|
|
46
|
+
return _asyncToGenerator(function* () {
|
|
47
|
+
const pm = ctx.app.pm;
|
|
48
|
+
const filterByTk = ctx.action.params.filterByTk;
|
|
49
|
+
|
|
50
|
+
if (!filterByTk) {
|
|
51
|
+
ctx.throw(400, 'plugin name invalid');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
yield pm.disable(filterByTk);
|
|
55
|
+
ctx.body = filterByTk;
|
|
56
|
+
yield next();
|
|
57
|
+
})();
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
upgrade(ctx, next) {
|
|
61
|
+
return _asyncToGenerator(function* () {
|
|
62
|
+
ctx.body = 'ok';
|
|
63
|
+
yield next();
|
|
64
|
+
})();
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
remove(ctx, next) {
|
|
68
|
+
return _asyncToGenerator(function* () {
|
|
69
|
+
const pm = ctx.app.pm;
|
|
70
|
+
const filterByTk = ctx.action.params.filterByTk;
|
|
71
|
+
|
|
72
|
+
if (!filterByTk) {
|
|
73
|
+
ctx.throw(400, 'plugin name invalid');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
yield pm.remove(filterByTk);
|
|
77
|
+
ctx.body = filterByTk;
|
|
78
|
+
yield next();
|
|
79
|
+
})();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
exports.default = _default;
|
package/lib/plugin.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export interface PluginOptions {
|
|
|
11
11
|
displayName?: string;
|
|
12
12
|
description?: string;
|
|
13
13
|
version?: string;
|
|
14
|
+
enabled?: boolean;
|
|
14
15
|
install?: (this: Plugin) => void;
|
|
15
16
|
load?: (this: Plugin) => void;
|
|
16
17
|
plugin?: typeof Plugin;
|
|
@@ -18,16 +19,20 @@ export interface PluginOptions {
|
|
|
18
19
|
}
|
|
19
20
|
export declare type PluginType = typeof Plugin;
|
|
20
21
|
export declare abstract class Plugin<O = any> implements PluginInterface {
|
|
21
|
-
options:
|
|
22
|
+
options: any;
|
|
22
23
|
app: Application;
|
|
23
24
|
db: Database;
|
|
24
|
-
constructor(app: Application, options?:
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
constructor(app: Application, options?: any);
|
|
26
|
+
get enabled(): any;
|
|
27
|
+
set enabled(value: any);
|
|
28
|
+
setOptions(options: any): void;
|
|
29
|
+
getName(): any;
|
|
30
|
+
afterAdd(): void;
|
|
27
31
|
beforeLoad(): void;
|
|
28
|
-
install(options?: InstallOptions): Promise<void>;
|
|
29
32
|
load(): Promise<void>;
|
|
30
|
-
|
|
31
|
-
|
|
33
|
+
install(options?: InstallOptions): Promise<void>;
|
|
34
|
+
afterEnable(): Promise<void>;
|
|
35
|
+
afterDisable(): Promise<void>;
|
|
36
|
+
remove(): Promise<void>;
|
|
32
37
|
}
|
|
33
38
|
export default Plugin;
|
package/lib/plugin.js
CHANGED
|
@@ -5,18 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.Plugin = void 0;
|
|
7
7
|
|
|
8
|
-
function _findPackageJson() {
|
|
9
|
-
const data = _interopRequireDefault(require("find-package-json"));
|
|
10
|
-
|
|
11
|
-
_findPackageJson = function _findPackageJson() {
|
|
12
|
-
return data;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return data;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
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); } }
|
|
21
9
|
|
|
22
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); }); }; }
|
|
@@ -29,40 +17,47 @@ class Plugin {
|
|
|
29
17
|
this.app = app;
|
|
30
18
|
this.db = app.db;
|
|
31
19
|
this.setOptions(options);
|
|
20
|
+
this.afterAdd();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
get enabled() {
|
|
24
|
+
return this.options.enabled;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
set enabled(value) {
|
|
28
|
+
this.options.enabled = value;
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
setOptions(options) {
|
|
35
32
|
this.options = options || {};
|
|
36
33
|
}
|
|
37
34
|
|
|
35
|
+
getName() {
|
|
36
|
+
return this.options.name;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
afterAdd() {}
|
|
40
|
+
|
|
38
41
|
beforeLoad() {}
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
load() {
|
|
41
44
|
return _asyncToGenerator(function* () {})();
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return _asyncToGenerator(function* () {
|
|
48
|
-
const collectionPath = _this.collectionPath();
|
|
47
|
+
install(options) {
|
|
48
|
+
return _asyncToGenerator(function* () {})();
|
|
49
|
+
}
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
directory: collectionPath
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
})();
|
|
51
|
+
afterEnable() {
|
|
52
|
+
return _asyncToGenerator(function* () {})();
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
return
|
|
55
|
+
afterDisable() {
|
|
56
|
+
return _asyncToGenerator(function* () {})();
|
|
60
57
|
}
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const packageObj = f.next().value;
|
|
65
|
-
return packageObj['name'];
|
|
59
|
+
remove() {
|
|
60
|
+
return _asyncToGenerator(function* () {})();
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0-alpha.10",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
}
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"@hapi/topo": "^6.0.0",
|
|
14
15
|
"@koa/cors": "^3.1.0",
|
|
15
16
|
"@koa/router": "^9.4.0",
|
|
16
|
-
"@nocobase/acl": "0.
|
|
17
|
-
"@nocobase/actions": "0.
|
|
18
|
-
"@nocobase/database": "0.
|
|
19
|
-
"@nocobase/resourcer": "0.
|
|
17
|
+
"@nocobase/acl": "0.8.0-alpha.10",
|
|
18
|
+
"@nocobase/actions": "0.8.0-alpha.10",
|
|
19
|
+
"@nocobase/database": "0.8.0-alpha.10",
|
|
20
|
+
"@nocobase/resourcer": "0.8.0-alpha.10",
|
|
20
21
|
"chalk": "^4.1.1",
|
|
21
22
|
"commander": "^9.2.0",
|
|
22
23
|
"find-package-json": "^1.2.0",
|
|
@@ -25,10 +26,11 @@
|
|
|
25
26
|
"koa-bodyparser": "^4.3.0",
|
|
26
27
|
"koa-static": "^5.0.0",
|
|
27
28
|
"lodash": "^4.17.21",
|
|
28
|
-
"semver": "^7.3.7"
|
|
29
|
+
"semver": "^7.3.7",
|
|
30
|
+
"xpipe": "^1.0.5"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
31
33
|
"@types/semver": "^7.3.9"
|
|
32
34
|
},
|
|
33
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "a9723cdeadc764eba634b5815685177679025c83"
|
|
34
36
|
}
|
package/lib/plugin-manager.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { CleanOptions, SyncOptions } from '@nocobase/database';
|
|
2
|
-
import Application from './application';
|
|
3
|
-
import { Plugin } from './plugin';
|
|
4
|
-
interface PluginManagerOptions {
|
|
5
|
-
app: Application;
|
|
6
|
-
}
|
|
7
|
-
export interface InstallOptions {
|
|
8
|
-
cliArgs?: any[];
|
|
9
|
-
clean?: CleanOptions | boolean;
|
|
10
|
-
sync?: SyncOptions;
|
|
11
|
-
}
|
|
12
|
-
declare type PluginConstructor<P, O = any> = {
|
|
13
|
-
new (app: Application, options: O): P;
|
|
14
|
-
};
|
|
15
|
-
export declare class PluginManager {
|
|
16
|
-
app: Application;
|
|
17
|
-
protected plugins: Map<string, Plugin<any>>;
|
|
18
|
-
constructor(options: PluginManagerOptions);
|
|
19
|
-
getPlugins(): Map<string, Plugin<any>>;
|
|
20
|
-
get(name: string): Plugin<any>;
|
|
21
|
-
add<P extends Plugin = Plugin, O = any>(pluginClass: PluginConstructor<P, O>, options?: O): P;
|
|
22
|
-
load(): Promise<void>;
|
|
23
|
-
install(options?: InstallOptions): Promise<void>;
|
|
24
|
-
static resolvePlugin(pluginName: string): any;
|
|
25
|
-
}
|
|
26
|
-
export {};
|
package/lib/plugin-manager.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PluginManager = void 0;
|
|
7
|
-
|
|
8
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
-
|
|
10
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
-
|
|
12
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
13
|
-
|
|
14
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
|
-
|
|
16
|
-
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(_e2) { throw _e2; }, 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(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
17
|
-
|
|
18
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
19
|
-
|
|
20
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
21
|
-
|
|
22
|
-
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); } }
|
|
23
|
-
|
|
24
|
-
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); }); }; }
|
|
25
|
-
|
|
26
|
-
class PluginManager {
|
|
27
|
-
constructor(options) {
|
|
28
|
-
this.app = void 0;
|
|
29
|
-
this.plugins = new Map();
|
|
30
|
-
this.app = options.app;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
getPlugins() {
|
|
34
|
-
return this.plugins;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get(name) {
|
|
38
|
-
return this.plugins.get(name);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
add(pluginClass, options) {
|
|
42
|
-
const instance = new pluginClass(this.app, options);
|
|
43
|
-
const name = instance.getName();
|
|
44
|
-
|
|
45
|
-
if (this.plugins.has(name)) {
|
|
46
|
-
throw new Error(`plugin name [${name}] `);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.plugins.set(name, instance);
|
|
50
|
-
return instance;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
load() {
|
|
54
|
-
var _this = this;
|
|
55
|
-
|
|
56
|
-
return _asyncToGenerator(function* () {
|
|
57
|
-
yield _this.app.emitAsync('beforeLoadAll');
|
|
58
|
-
|
|
59
|
-
var _iterator = _createForOfIteratorHelper(_this.plugins),
|
|
60
|
-
_step;
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
64
|
-
const _step$value = _slicedToArray(_step.value, 2),
|
|
65
|
-
name = _step$value[0],
|
|
66
|
-
plugin = _step$value[1];
|
|
67
|
-
|
|
68
|
-
yield plugin.beforeLoad();
|
|
69
|
-
}
|
|
70
|
-
} catch (err) {
|
|
71
|
-
_iterator.e(err);
|
|
72
|
-
} finally {
|
|
73
|
-
_iterator.f();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
var _iterator2 = _createForOfIteratorHelper(_this.plugins),
|
|
77
|
-
_step2;
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
81
|
-
const _step2$value = _slicedToArray(_step2.value, 2),
|
|
82
|
-
name = _step2$value[0],
|
|
83
|
-
plugin = _step2$value[1];
|
|
84
|
-
|
|
85
|
-
yield _this.app.emitAsync('beforeLoadPlugin', plugin);
|
|
86
|
-
yield plugin.load();
|
|
87
|
-
yield _this.app.emitAsync('afterLoadPlugin', plugin);
|
|
88
|
-
}
|
|
89
|
-
} catch (err) {
|
|
90
|
-
_iterator2.e(err);
|
|
91
|
-
} finally {
|
|
92
|
-
_iterator2.f();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
yield _this.app.emitAsync('afterLoadAll');
|
|
96
|
-
})();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
install(options = {}) {
|
|
100
|
-
var _this2 = this;
|
|
101
|
-
|
|
102
|
-
return _asyncToGenerator(function* () {
|
|
103
|
-
var _iterator3 = _createForOfIteratorHelper(_this2.plugins),
|
|
104
|
-
_step3;
|
|
105
|
-
|
|
106
|
-
try {
|
|
107
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
108
|
-
const _step3$value = _slicedToArray(_step3.value, 2),
|
|
109
|
-
name = _step3$value[0],
|
|
110
|
-
plugin = _step3$value[1];
|
|
111
|
-
|
|
112
|
-
yield _this2.app.emitAsync('beforeInstallPlugin', plugin, options);
|
|
113
|
-
yield plugin.install(options);
|
|
114
|
-
yield _this2.app.emitAsync('afterInstallPlugin', plugin, options);
|
|
115
|
-
}
|
|
116
|
-
} catch (err) {
|
|
117
|
-
_iterator3.e(err);
|
|
118
|
-
} finally {
|
|
119
|
-
_iterator3.f();
|
|
120
|
-
}
|
|
121
|
-
})();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
static resolvePlugin(pluginName) {
|
|
125
|
-
return require(pluginName).default;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
exports.PluginManager = PluginManager;
|