@nocobase/server 0.5.0-alpha.38 → 0.7.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/LICENSE +201 -21
- package/esm/acl/available-action.d.ts +5 -0
- package/esm/acl/available-action.js +36 -0
- package/esm/acl/available-action.js.map +1 -0
- package/esm/acl/index.d.ts +2 -0
- package/esm/acl/index.js +19 -0
- package/esm/acl/index.js.map +1 -0
- package/esm/app-manager.d.ts +19 -0
- package/esm/app-manager.js +69 -0
- package/esm/app-manager.js.map +1 -0
- package/esm/application.d.ts +97 -0
- package/esm/application.js +156 -0
- package/esm/application.js.map +1 -0
- package/esm/commands/console.d.ts +4 -0
- package/esm/commands/console.js +25 -0
- package/esm/commands/console.js.map +1 -0
- package/esm/commands/create-plugin/create-plugin.d.ts +2 -0
- package/esm/commands/create-plugin/create-plugin.js +29 -0
- package/esm/commands/create-plugin/create-plugin.js.map +1 -0
- package/esm/commands/create-plugin/index.d.ts +5 -0
- package/esm/commands/create-plugin/index.js +6 -0
- package/esm/commands/create-plugin/index.js.map +1 -0
- package/esm/commands/create-plugin/resources/templates/package-json.d.ts +11 -0
- package/esm/commands/create-plugin/resources/templates/package-json.js +11 -0
- package/esm/commands/create-plugin/resources/templates/package-json.js.map +1 -0
- package/esm/commands/create-plugin/resources/templates/plugin.d.ts +4 -0
- package/esm/commands/create-plugin/resources/templates/plugin.js +12 -0
- package/esm/commands/create-plugin/resources/templates/plugin.js.map +1 -0
- package/esm/commands/db-sync.d.ts +5 -0
- package/esm/commands/db-sync.js +25 -0
- package/esm/commands/db-sync.js.map +1 -0
- package/esm/commands/index.d.ts +3 -0
- package/esm/commands/index.js +26 -0
- package/esm/commands/index.js.map +1 -0
- package/esm/commands/install.d.ts +5 -0
- package/esm/commands/install.js +23 -0
- package/esm/commands/install.js.map +1 -0
- package/esm/commands/start.d.ts +5 -0
- package/esm/commands/start.js +23 -0
- package/esm/commands/start.js.map +1 -0
- package/esm/helper.d.ts +7 -0
- package/esm/helper.js +59 -0
- package/esm/helper.js.map +1 -0
- package/esm/index.d.ts +7 -0
- package/esm/index.js +9 -0
- package/esm/index.js.map +1 -0
- package/esm/middlewares/data-wrapping.d.ts +3 -0
- package/esm/middlewares/data-wrapping.js +54 -0
- package/esm/middlewares/data-wrapping.js.map +1 -0
- package/esm/middlewares/index.d.ts +2 -0
- package/esm/middlewares/index.js +3 -0
- package/esm/middlewares/index.js.map +1 -0
- package/esm/middlewares/table2resource.d.ts +6 -0
- package/esm/middlewares/table2resource.js +51 -0
- package/esm/middlewares/table2resource.js.map +1 -0
- package/esm/plugin-manager.d.ts +23 -0
- package/esm/plugin-manager.js +57 -0
- package/esm/plugin-manager.js.map +1 -0
- package/esm/plugin.d.ts +32 -0
- package/esm/plugin.js +43 -0
- package/esm/plugin.js.map +1 -0
- package/esm/read-config.d.ts +8 -0
- package/esm/read-config.js +63 -0
- package/esm/read-config.js.map +1 -0
- package/lib/acl/available-action.d.ts +5 -0
- package/lib/acl/available-action.js +39 -0
- package/lib/acl/available-action.js.map +1 -0
- package/lib/acl/index.d.ts +2 -0
- package/lib/acl/index.js +23 -0
- package/lib/acl/index.js.map +1 -0
- package/lib/app-manager.d.ts +19 -0
- package/lib/app-manager.js +76 -0
- package/lib/app-manager.js.map +1 -0
- package/lib/application.d.ts +51 -12
- package/lib/application.js +147 -245
- package/lib/application.js.map +1 -1
- package/lib/commands/console.d.ts +4 -0
- package/lib/commands/console.js +27 -0
- package/lib/commands/console.js.map +1 -0
- package/lib/commands/create-plugin/create-plugin.d.ts +2 -0
- package/lib/commands/create-plugin/create-plugin.js +31 -0
- package/lib/commands/create-plugin/create-plugin.js.map +1 -0
- package/lib/commands/create-plugin/index.d.ts +5 -0
- package/lib/commands/create-plugin/index.js +8 -0
- package/lib/commands/create-plugin/index.js.map +1 -0
- package/lib/commands/create-plugin/resources/templates/package-json.d.ts +11 -0
- package/lib/commands/create-plugin/resources/templates/package-json.js +13 -0
- package/lib/commands/create-plugin/resources/templates/package-json.js.map +1 -0
- package/lib/commands/create-plugin/resources/templates/plugin.d.ts +4 -0
- package/lib/commands/create-plugin/resources/templates/plugin.js +33 -0
- package/lib/commands/create-plugin/resources/templates/plugin.js.map +1 -0
- package/lib/commands/db-sync.d.ts +5 -0
- package/lib/commands/db-sync.js +27 -0
- package/lib/commands/db-sync.js.map +1 -0
- package/lib/commands/index.d.ts +3 -0
- package/lib/commands/index.js +30 -0
- package/lib/commands/index.js.map +1 -0
- package/lib/commands/install.d.ts +5 -0
- package/lib/commands/install.js +25 -0
- package/lib/commands/install.js.map +1 -0
- package/lib/commands/start.d.ts +5 -0
- package/lib/commands/start.js +25 -0
- package/lib/commands/start.js.map +1 -0
- package/lib/helper.d.ts +1 -3
- package/lib/helper.js +50 -185
- package/lib/helper.js.map +1 -1
- package/lib/index.d.ts +4 -1
- package/lib/index.js +28 -63
- package/lib/index.js.map +1 -1
- package/lib/middlewares/data-wrapping.js +49 -97
- package/lib/middlewares/data-wrapping.js.map +1 -1
- package/lib/middlewares/index.js +11 -35
- package/lib/middlewares/index.js.map +1 -1
- package/lib/middlewares/table2resource.d.ts +4 -1
- package/lib/middlewares/table2resource.js +45 -129
- package/lib/middlewares/table2resource.js.map +1 -1
- package/lib/plugin-manager.d.ts +23 -0
- package/lib/plugin-manager.js +61 -0
- package/lib/plugin-manager.js.map +1 -0
- package/lib/plugin.d.ts +17 -16
- package/lib/plugin.js +42 -99
- package/lib/plugin.js.map +1 -1
- package/lib/read-config.d.ts +8 -0
- package/lib/read-config.js +72 -0
- package/lib/read-config.js.map +1 -0
- package/package.json +22 -9
- package/tsconfig.build.json +9 -0
- package/lib/application.d.ts.map +0 -1
- package/lib/helper.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/middlewares/data-wrapping.d.ts.map +0 -1
- package/lib/middlewares/index.d.ts.map +0 -1
- package/lib/middlewares/table2resource.d.ts.map +0 -1
- package/lib/plugin.d.ts.map +0 -1
|
@@ -1,106 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
16
|
-
function adopt(value) {
|
|
17
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
18
|
-
resolve(value);
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
9
|
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
-
function fulfilled(value) {
|
|
24
|
-
try {
|
|
25
|
-
step(generator.next(value));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
reject(e);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function rejected(value) {
|
|
32
|
-
try {
|
|
33
|
-
step(generator["throw"](value));
|
|
34
|
-
} catch (e) {
|
|
35
|
-
reject(e);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function step(result) {
|
|
40
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
44
|
-
});
|
|
45
10
|
};
|
|
46
|
-
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
56
21
|
};
|
|
57
|
-
|
|
58
|
-
Object.defineProperty(exports, "__esModule", {
|
|
59
|
-
value: true
|
|
60
|
-
});
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
23
|
exports.dataWrapping = void 0;
|
|
62
|
-
|
|
63
24
|
function dataWrapping() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
};
|
|
95
|
-
} else {
|
|
96
|
-
ctx.body = {
|
|
97
|
-
data: ctx.body
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
};
|
|
25
|
+
return function dataWrapping(ctx, next) {
|
|
26
|
+
var _a;
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
yield next();
|
|
29
|
+
if (ctx.withoutDataWrapping) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!((_a = ctx === null || ctx === void 0 ? void 0 : ctx.action) === null || _a === void 0 ? void 0 : _a.params)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (ctx.body instanceof Buffer) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!ctx.body) {
|
|
39
|
+
ctx.body = {};
|
|
40
|
+
}
|
|
41
|
+
const _b = ctx.body, { rows } = _b, meta = __rest(_b, ["rows"]);
|
|
42
|
+
if (rows) {
|
|
43
|
+
ctx.body = {
|
|
44
|
+
data: rows,
|
|
45
|
+
meta,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
ctx.body = {
|
|
50
|
+
data: ctx.body,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
102
55
|
}
|
|
103
|
-
|
|
104
56
|
exports.dataWrapping = dataWrapping;
|
|
105
57
|
exports.default = dataWrapping;
|
|
106
|
-
//# sourceMappingURL=data-wrapping.js.map
|
|
58
|
+
//# sourceMappingURL=data-wrapping.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/data-wrapping.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAgB,YAAY;IAC1B,OAAO,SAAe,YAAY,CAAC,GAAY,EAAE,IAAU;;;YACzD,MAAM,IAAI,EAAE,CAAC;YACb,IAAI,GAAG,CAAC,mBAAmB,EAAE;gBAC3B,OAAO;aACR;YACD,IAAI,CAAC,CAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,0CAAE,MAAM,CAAA,EAAE;gBACxB,OAAO;aACR;YACD,IAAI,GAAG,CAAC,IAAI,YAAY,MAAM,EAAE;gBAC9B,OAAO;aACR;YACD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;gBACb,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;aACf;YACD,MAAM,KAAoB,GAAG,CAAC,IAAI,EAA5B,EAAE,IAAI,OAAsB,EAAjB,IAAI,cAAf,QAAiB,CAAW,CAAC;YACnC,IAAI,IAAI,EAAE;gBACR,GAAG,CAAC,IAAI,GAAG;oBACT,IAAI,EAAE,IAAI;oBACV,IAAI;iBACL,CAAC;aACH;iBAAM;gBACL,GAAG,CAAC,IAAI,GAAG;oBACT,IAAI,EAAE,GAAG,CAAC,IAAI;iBACf,CAAC;aACH;;KACF,
|
|
1
|
+
{"version":3,"file":"data-wrapping.js","sourceRoot":"","sources":["../../src/middlewares/data-wrapping.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAgB,YAAY;IAC1B,OAAO,SAAe,YAAY,CAAC,GAAY,EAAE,IAAU;;;YACzD,MAAM,IAAI,EAAE,CAAC;YACb,IAAI,GAAG,CAAC,mBAAmB,EAAE;gBAC3B,OAAO;aACR;YACD,IAAI,CAAC,CAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,0CAAE,MAAM,CAAA,EAAE;gBACxB,OAAO;aACR;YACD,IAAI,GAAG,CAAC,IAAI,YAAY,MAAM,EAAE;gBAC9B,OAAO;aACR;YACD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE;gBACb,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC;aACf;YACD,MAAM,KAAoB,GAAG,CAAC,IAAI,EAA5B,EAAE,IAAI,OAAsB,EAAjB,IAAI,cAAf,QAAiB,CAAW,CAAC;YACnC,IAAI,IAAI,EAAE;gBACR,GAAG,CAAC,IAAI,GAAG;oBACT,IAAI,EAAE,IAAI;oBACV,IAAI;iBACL,CAAC;aACH;iBAAM;gBACL,GAAG,CAAC,IAAI,GAAG;oBACT,IAAI,EAAE,GAAG,CAAC,IAAI;iBACf,CAAC;aACH;;KACF,CAAC;AACJ,CAAC;AA3BD,oCA2BC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import { Context, Next } from '@nocobase/actions';\n\nexport function dataWrapping() {\n return async function dataWrapping(ctx: Context, next: Next) {\n await next();\n if (ctx.withoutDataWrapping) {\n return;\n }\n if (!ctx?.action?.params) {\n return;\n }\n if (ctx.body instanceof Buffer) {\n return;\n }\n if (!ctx.body) {\n ctx.body = {};\n }\n const { rows, ...meta } = ctx.body;\n if (rows) {\n ctx.body = {\n data: rows,\n meta,\n };\n } else {\n ctx.body = {\n data: ctx.body,\n };\n }\n };\n}\n\nexport default dataWrapping;\n"]}
|
package/lib/middlewares/index.js
CHANGED
|
@@ -1,39 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
Object.defineProperty(o, k2, {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function get() {
|
|
20
|
-
return m[k];
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
} : function (o, m, k, k2) {
|
|
24
|
-
if (k2 === undefined) k2 = k;
|
|
25
|
-
o[k2] = m[k];
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
29
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
30
11
|
};
|
|
31
|
-
|
|
32
|
-
Object.defineProperty(exports, "__esModule", {
|
|
33
|
-
value: true
|
|
34
|
-
});
|
|
35
|
-
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
13
|
__exportStar(require("./table2resource"), exports);
|
|
37
|
-
|
|
38
14
|
__exportStar(require("./data-wrapping"), exports);
|
|
39
|
-
//# sourceMappingURL=index.js.map
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAiC;AACjC,kDAAgC","
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middlewares/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAiC;AACjC,kDAAgC","sourcesContent":["export * from './table2resource';\nexport * from './data-wrapping';\n"]}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { ResourcerContext } from '@nocobase/resourcer';
|
|
2
|
-
|
|
2
|
+
import Database from '@nocobase/database';
|
|
3
|
+
export declare function table2resource(): (ctx: ResourcerContext & {
|
|
4
|
+
db: Database;
|
|
5
|
+
}, next: () => Promise<any>) => Promise<any>;
|
|
3
6
|
export default table2resource;
|
|
@@ -1,139 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return data;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
16
|
-
|
|
17
|
-
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."); }
|
|
18
|
-
|
|
19
|
-
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); }
|
|
20
|
-
|
|
21
|
-
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; }
|
|
22
|
-
|
|
23
|
-
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; }
|
|
24
|
-
|
|
25
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
26
|
-
|
|
27
|
-
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
|
|
28
|
-
function adopt(value) {
|
|
29
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
30
|
-
resolve(value);
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
31
9
|
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
35
|
-
function fulfilled(value) {
|
|
36
|
-
try {
|
|
37
|
-
step(generator.next(value));
|
|
38
|
-
} catch (e) {
|
|
39
|
-
reject(e);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function rejected(value) {
|
|
44
|
-
try {
|
|
45
|
-
step(generator["throw"](value));
|
|
46
|
-
} catch (e) {
|
|
47
|
-
reject(e);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function step(result) {
|
|
52
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
56
|
-
});
|
|
57
10
|
};
|
|
58
|
-
|
|
59
|
-
Object.defineProperty(exports, "__esModule", {
|
|
60
|
-
value: true
|
|
61
|
-
});
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
12
|
exports.table2resource = void 0;
|
|
63
|
-
|
|
64
13
|
const resourcer_1 = require("@nocobase/resourcer");
|
|
65
|
-
|
|
66
|
-
const database_1 = require("@nocobase/database");
|
|
67
|
-
|
|
68
14
|
function table2resource() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
let resourceType = 'single';
|
|
105
|
-
let actions = {};
|
|
106
|
-
|
|
107
|
-
if (field) {
|
|
108
|
-
if (field instanceof database_1.HASONE) {
|
|
109
|
-
resourceType = 'hasOne';
|
|
110
|
-
} else if (field instanceof database_1.HASMANY) {
|
|
111
|
-
resourceType = 'hasMany';
|
|
112
|
-
} else if (field instanceof database_1.BELONGSTO) {
|
|
113
|
-
resourceType = 'belongsTo';
|
|
114
|
-
} else if (field instanceof database_1.BELONGSTOMANY) {
|
|
115
|
-
resourceType = 'belongsToMany';
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (field.options.actions) {
|
|
119
|
-
actions = field.options.actions || {};
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
actions = table.getOptions('actions') || {};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
resourcer.define({
|
|
126
|
-
type: resourceType,
|
|
127
|
-
name: resourceName,
|
|
128
|
-
actions
|
|
15
|
+
return function table2resource(ctx, next) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const resourcer = ctx.resourcer;
|
|
18
|
+
const database = ctx.db;
|
|
19
|
+
let params = (0, resourcer_1.parseRequest)({
|
|
20
|
+
path: ctx.request.path,
|
|
21
|
+
method: ctx.request.method,
|
|
22
|
+
}, {
|
|
23
|
+
prefix: resourcer.options.prefix,
|
|
24
|
+
accessors: resourcer.options.accessors,
|
|
25
|
+
});
|
|
26
|
+
if (!params) {
|
|
27
|
+
return next();
|
|
28
|
+
}
|
|
29
|
+
const resourceName = (0, resourcer_1.getNameByParams)(params);
|
|
30
|
+
// 如果资源名称未被定义
|
|
31
|
+
if (resourcer.isDefined(resourceName)) {
|
|
32
|
+
return next();
|
|
33
|
+
}
|
|
34
|
+
const [collectionName, fieldName] = resourceName.split('.');
|
|
35
|
+
// 如果经过加载后是已经定义的表
|
|
36
|
+
if (!database.hasCollection(collectionName)) {
|
|
37
|
+
return next();
|
|
38
|
+
}
|
|
39
|
+
const collection = database.getCollection(collectionName);
|
|
40
|
+
let resourceType = 'single';
|
|
41
|
+
if (fieldName && collection.hasField(fieldName)) {
|
|
42
|
+
const field = collection.getField(fieldName);
|
|
43
|
+
resourceType = field.type;
|
|
44
|
+
}
|
|
45
|
+
resourcer.define({
|
|
46
|
+
type: resourceType,
|
|
47
|
+
name: resourceName,
|
|
48
|
+
});
|
|
49
|
+
return next();
|
|
129
50
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return next();
|
|
133
|
-
});
|
|
134
|
-
};
|
|
51
|
+
};
|
|
135
52
|
}
|
|
136
|
-
|
|
137
53
|
exports.table2resource = table2resource;
|
|
138
54
|
exports.default = table2resource;
|
|
139
|
-
//# sourceMappingURL=table2resource.js.map
|
|
55
|
+
//# sourceMappingURL=table2resource.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["middlewares/table2resource.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"table2resource.js","sourceRoot":"","sources":["../../src/middlewares/table2resource.ts"],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;gBACf,IAAI,EAAE,YAAY;gBAClB,IAAI,EAAE,YAAY;aACnB,CAAC,CAAC;YACH,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;KAAA,CAAC;AACJ,CAAC;AAvCD,wCAuCC;AAED,kBAAe,cAAc,CAAC","sourcesContent":["import { getNameByParams, parseRequest, ResourcerContext, ResourceType } from '@nocobase/resourcer';\nimport Database from '@nocobase/database';\n\nexport function table2resource() {\n return async function table2resource(ctx: ResourcerContext & { db: Database }, next: () => Promise<any>) {\n const resourcer = ctx.resourcer;\n const database = ctx.db;\n let params = parseRequest(\n {\n path: ctx.request.path,\n method: ctx.request.method,\n },\n {\n prefix: resourcer.options.prefix,\n accessors: resourcer.options.accessors,\n },\n );\n if (!params) {\n return next();\n }\n const resourceName = getNameByParams(params);\n // 如果资源名称未被定义\n if (resourcer.isDefined(resourceName)) {\n return next();\n }\n const [collectionName, fieldName] = resourceName.split('.');\n // 如果经过加载后是已经定义的表\n if (!database.hasCollection(collectionName)) {\n return next();\n }\n const collection = database.getCollection(collectionName);\n let resourceType: ResourceType = 'single';\n if (fieldName && collection.hasField(fieldName)) {\n const field = collection.getField(fieldName);\n resourceType = field.type;\n }\n resourcer.define({\n type: resourceType,\n name: resourceName,\n });\n return next();\n };\n}\n\nexport default table2resource;\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
export declare class PluginManager {
|
|
13
|
+
app: Application;
|
|
14
|
+
protected plugins: Map<string, Plugin<any>>;
|
|
15
|
+
constructor(options: PluginManagerOptions);
|
|
16
|
+
getPlugins(): Map<string, Plugin<any>>;
|
|
17
|
+
get(name: string): Plugin<any>;
|
|
18
|
+
add<P = Plugin, O = any>(pluginClass: any, options?: O): P;
|
|
19
|
+
load(): Promise<void>;
|
|
20
|
+
install(options?: InstallOptions): Promise<void>;
|
|
21
|
+
static resolvePlugin(pluginName: string): any;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PluginManager = void 0;
|
|
13
|
+
class PluginManager {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.plugins = new Map();
|
|
16
|
+
this.app = options.app;
|
|
17
|
+
}
|
|
18
|
+
getPlugins() {
|
|
19
|
+
return this.plugins;
|
|
20
|
+
}
|
|
21
|
+
get(name) {
|
|
22
|
+
return this.plugins.get(name);
|
|
23
|
+
}
|
|
24
|
+
add(pluginClass, options) {
|
|
25
|
+
const instance = new pluginClass(this.app, options);
|
|
26
|
+
const name = instance.getName();
|
|
27
|
+
if (this.plugins.has(name)) {
|
|
28
|
+
throw new Error(`plugin name [${name}] `);
|
|
29
|
+
}
|
|
30
|
+
this.plugins.set(name, instance);
|
|
31
|
+
return instance;
|
|
32
|
+
}
|
|
33
|
+
load() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
yield this.app.emitAsync('beforeLoadAll');
|
|
36
|
+
for (const [name, plugin] of this.plugins) {
|
|
37
|
+
yield plugin.beforeLoad();
|
|
38
|
+
}
|
|
39
|
+
for (const [name, plugin] of this.plugins) {
|
|
40
|
+
yield this.app.emitAsync('beforeLoadPlugin', plugin);
|
|
41
|
+
yield plugin.load();
|
|
42
|
+
yield this.app.emitAsync('afterLoadPlugin', plugin);
|
|
43
|
+
}
|
|
44
|
+
yield this.app.emitAsync('afterLoadAll');
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
install(options) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
for (const [name, plugin] of this.plugins) {
|
|
50
|
+
yield this.app.emitAsync('beforeInstallPlugin', plugin, options);
|
|
51
|
+
yield plugin.install(options);
|
|
52
|
+
yield this.app.emitAsync('afterInstallPlugin', plugin, options);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
static resolvePlugin(pluginName) {
|
|
57
|
+
return require(pluginName).default;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.PluginManager = PluginManager;
|
|
61
|
+
//# sourceMappingURL=plugin-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-manager.js","sourceRoot":"","sources":["../src/plugin-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAcA,MAAa,aAAa;IAIxB,YAAY,OAA6B;QAF/B,YAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAG5C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IACzB,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,GAAG,CAAsB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AO,CAAC,CAAC;gBAC9B,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,oBAAoB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;aACjE;QACH,CAAC;KAAA;IAED,MAAM,CAAC,aAAa,CAAC,UAAkB;QACrC,OAAO,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC;IACrC,CAAC;CACF;AAzDD,sCAyDC","sourcesContent":["import { CleanOptions, SyncOptions } from '@nocobase/database';\nimport Application from './application';\nimport { Plugin } from './plugin';\n\ninterface PluginManagerOptions {\n app: Application;\n}\n\nexport interface InstallOptions {\n cliArgs?: any[];\n clean?: CleanOptions | boolean;\n sync?: SyncOptions;\n}\n\nexport class PluginManager {\n app: Application;\n protected plugins = new Map<string, Plugin>();\n\n constructor(options: PluginManagerOptions) {\n this.app = options.app;\n }\n\n getPlugins() {\n return this.plugins;\n }\n\n get(name: string) {\n return this.plugins.get(name);\n }\n\n add<P = Plugin, O = any>(pluginClass: any, options?: O): P {\n const instance = new pluginClass(this.app, options);\n\n const name = instance.getName();\n\n if (this.plugins.has(name)) {\n throw new Error(`plugin name [${name}] `);\n }\n\n this.plugins.set(name, instance);\n\n return instance;\n }\n\n async load() {\n await this.app.emitAsync('beforeLoadAll');\n\n for (const [name, plugin] of this.plugins) {\n await plugin.beforeLoad();\n }\n\n for (const [name, plugin] of this.plugins) {\n await this.app.emitAsync('beforeLoadPlugin', plugin);\n await plugin.load();\n await this.app.emitAsync('afterLoadPlugin', plugin);\n }\n\n await this.app.emitAsync('afterLoadAll');\n }\n\n async install(options?: InstallOptions) {\n for (const [name, plugin] of this.plugins) {\n await this.app.emitAsync('beforeInstallPlugin', plugin, options);\n await plugin.install(options);\n await this.app.emitAsync('afterInstallPlugin', plugin, options);\n }\n }\n\n static resolvePlugin(pluginName: string) {\n return require(pluginName).default;\n }\n}\n"]}
|
package/lib/plugin.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { Database } from '@nocobase/database';
|
|
1
2
|
import { Application } from './application';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { InstallOptions } from './plugin-manager';
|
|
4
|
+
export interface PluginInterface {
|
|
5
|
+
beforeLoad?: () => void;
|
|
6
|
+
load(): any;
|
|
7
|
+
getName(): string;
|
|
5
8
|
}
|
|
6
9
|
export interface PluginOptions {
|
|
7
|
-
name?: string;
|
|
8
10
|
activate?: boolean;
|
|
9
11
|
displayName?: string;
|
|
10
12
|
description?: string;
|
|
@@ -14,18 +16,17 @@ export interface PluginOptions {
|
|
|
14
16
|
plugin?: typeof Plugin;
|
|
15
17
|
[key: string]: any;
|
|
16
18
|
}
|
|
17
|
-
export declare type
|
|
18
|
-
export declare
|
|
19
|
-
|
|
20
|
-
options: PluginOptions;
|
|
19
|
+
export declare type PluginType = typeof Plugin;
|
|
20
|
+
export declare abstract class Plugin<O = any> implements PluginInterface {
|
|
21
|
+
options: O;
|
|
21
22
|
app: Application;
|
|
22
|
-
|
|
23
|
-
constructor(options?:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
install(): Promise<void>;
|
|
29
|
-
call(name: string): Promise<void>;
|
|
23
|
+
db: Database;
|
|
24
|
+
constructor(app: Application, options?: O);
|
|
25
|
+
setOptions(options: O): void;
|
|
26
|
+
abstract getName(): string;
|
|
27
|
+
beforeLoad(): void;
|
|
28
|
+
install(options?: InstallOptions): Promise<void>;
|
|
30
29
|
load(): Promise<void>;
|
|
30
|
+
collectionPath(): any;
|
|
31
|
+
protected getPackageName(dirname: string): any;
|
|
31
32
|
}
|