@fy-tools/rpc-server-expressjs 0.0.119-alpha.10390 → 0.0.119-alpha.10391
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/dist/lib/app.d.ts.map +1 -1
- package/dist/lib/app.js +1 -3
- package/dist/lib/controller.d.ts.map +1 -1
- package/dist/lib/controller.js +5 -6
- package/dist/lib/route.d.ts +1 -2
- package/dist/lib/route.d.ts.map +1 -1
- package/dist/lib/route.js +8 -19
- package/dist/lib/types.d.ts +2 -1
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/lib/app.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/lib/app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,GAAG,CAAC,UAAU,SAAS,WAAW,GAAG,WAAW,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM;IAYxE,IAAI,EAAE,UAAU;IAAS,OAAO,EAAE,MAAM;IAX3D;;;SAGK;IACE,CAAC,EAAS,GACd,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CACrE,UAAU,EACV,oBAAoB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAC1D,GACF,CAAC;gBAEiB,IAAI,EAAE,UAAU,EAAS,OAAO,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/lib/app.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,MAAM,EACN,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,GAAG,CAAC,UAAU,SAAS,WAAW,GAAG,WAAW,EAAE,MAAM,SAAS,MAAM,GAAG,MAAM;IAYxE,IAAI,EAAE,UAAU;IAAS,OAAO,EAAE,MAAM;IAX3D;;;SAGK;IACE,CAAC,EAAS,GACd,GAAG,IAAI,kBAAkB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CACrE,UAAU,EACV,oBAAoB,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,CAC1D,GACF,CAAC;gBAEiB,IAAI,EAAE,UAAU,EAAS,OAAO,EAAE,MAAM;IAS3D,KAAK,CAAC,CAAC,SAAS,WAAW,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,CAAC;CAGxD"}
|
package/dist/lib/app.js
CHANGED
|
@@ -14,9 +14,7 @@ class App {
|
|
|
14
14
|
this._app = _app;
|
|
15
15
|
this._schema = _schema;
|
|
16
16
|
for (const i in _schema._controllers_map) {
|
|
17
|
-
|
|
18
|
-
this._app = controller._app;
|
|
19
|
-
this.C[i] = controller;
|
|
17
|
+
this.C[i] = new controller_1.Controller(this._app, _schema._controllers[_schema._controllers_map[i]]);
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
build(fn) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/lib/controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,aAAa,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,UAAU,CACrB,GAAG,SAAS,WAAW,GAAG,WAAW,EACrC,MAAM,SAAS,aAAa,GAAG,aAAa;IAQzB,IAAI,EAAE,GAAG;IAAS,OAAO,EAAE,MAAM;IANpD;;;SAGK;IACE,CAAC,
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/lib/controller.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,aAAa,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,UAAU,CACrB,GAAG,SAAS,WAAW,GAAG,WAAW,EACrC,MAAM,SAAS,aAAa,GAAG,aAAa;IAQzB,IAAI,EAAE,GAAG;IAAS,OAAO,EAAE,MAAM;IANpD;;;SAGK;IACE,CAAC,KAkBD,GAAG,iHAlBD;gBAEU,IAAI,EAAE,GAAG,EAAS,OAAO,EAAE,MAAM;IA6BpD,KAAK,CAAC,CAAC,SAAS,WAAW,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;CAGjD"}
|
package/dist/lib/controller.js
CHANGED
|
@@ -17,14 +17,13 @@ class Controller {
|
|
|
17
17
|
this._schema = _schema;
|
|
18
18
|
const router = express_1.default.Router();
|
|
19
19
|
const routes = {};
|
|
20
|
-
let currentRouter = router;
|
|
21
20
|
for (const i in _schema._routes_map) {
|
|
22
|
-
|
|
23
|
-
currentRouter = route._app;
|
|
24
|
-
routes[i] = route;
|
|
21
|
+
routes[i] = new route_1.Route(router, _schema._routes[_schema._routes_map[i]]);
|
|
25
22
|
}
|
|
26
|
-
const basePath = this._schema._basePath
|
|
27
|
-
|
|
23
|
+
const basePath = this._schema._basePath
|
|
24
|
+
? `/${this._schema._basePath}`
|
|
25
|
+
: '/';
|
|
26
|
+
this._app.use(basePath, router);
|
|
28
27
|
this.R = new Proxy(routes, {
|
|
29
28
|
get(target, p) {
|
|
30
29
|
return routes[p];
|
package/dist/lib/route.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { AnyRoute, Response } from '@fy-tools/rpc-server';
|
|
2
2
|
import type { Router } from 'express';
|
|
3
|
-
import
|
|
3
|
+
import { RouteToContext } from './types';
|
|
4
4
|
export declare class Route<App extends Router = Router, Schema extends AnyRoute = AnyRoute> {
|
|
5
5
|
_app: App;
|
|
6
6
|
_schema: Schema;
|
|
7
|
-
private readonly _handlerRef;
|
|
8
7
|
constructor(_app: App, _schema: Schema);
|
|
9
8
|
build<T extends Router>(fn: (app: App) => T): Route<T, Schema>;
|
|
10
9
|
handler(fn: (ctx: RouteToContext<Schema>) => Promise<Response<Schema>>): void;
|
package/dist/lib/route.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/lib/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC3E,OAAO,KAAK,EAIV,MAAM,EACP,MAAM,SAAS,CAAC;AAEjB,OAAO,
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/lib/route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC3E,OAAO,KAAK,EAIV,MAAM,EACP,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,qBAAa,KAAK,CAChB,GAAG,SAAS,MAAM,GAAG,MAAM,EAC3B,MAAM,SAAS,QAAQ,GAAG,QAAQ;IAEf,IAAI,EAAE,GAAG;IAAS,OAAO,EAAE,MAAM;gBAAjC,IAAI,EAAE,GAAG,EAAS,OAAO,EAAE,MAAM;IAEpD,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAI3C,OAAO,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,cAAc,CAAC,MAAM,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;CAuDvE"}
|
package/dist/lib/route.js
CHANGED
|
@@ -5,21 +5,17 @@ const rpc_server_1 = require("@fy-tools/rpc-server");
|
|
|
5
5
|
class Route {
|
|
6
6
|
_app;
|
|
7
7
|
_schema;
|
|
8
|
-
_handlerRef;
|
|
9
8
|
constructor(_app, _schema) {
|
|
10
9
|
this._app = _app;
|
|
11
10
|
this._schema = _schema;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// Capture ref object — closure reads handlerRef.fn, not this._handlerFn,
|
|
18
|
-
// so reassignment in handler() is always visible even if this-binding diverges.
|
|
19
|
-
const handlerRef = this._handlerRef;
|
|
11
|
+
}
|
|
12
|
+
build(fn) {
|
|
13
|
+
return new Route(fn(this._app), this._schema);
|
|
14
|
+
}
|
|
15
|
+
handler(fn) {
|
|
20
16
|
const path = this._schema._path ? `/${this._schema._path}` : '/';
|
|
21
17
|
const method = this._schema._method;
|
|
22
|
-
this._app
|
|
18
|
+
this._app[method](path, async (req, res, next) => {
|
|
23
19
|
try {
|
|
24
20
|
let body = req.body;
|
|
25
21
|
let params = req.params;
|
|
@@ -42,13 +38,13 @@ class Route {
|
|
|
42
38
|
return next(new rpc_server_1.ValidationError(result.issues));
|
|
43
39
|
query = result.value;
|
|
44
40
|
}
|
|
45
|
-
|
|
46
|
-
const response = await handlerRef.fn({
|
|
41
|
+
const response = await fn({
|
|
47
42
|
body,
|
|
48
43
|
params,
|
|
49
44
|
query,
|
|
50
45
|
req,
|
|
51
46
|
res,
|
|
47
|
+
next,
|
|
52
48
|
});
|
|
53
49
|
if (!res.headersSent)
|
|
54
50
|
res.json(response);
|
|
@@ -58,12 +54,5 @@ class Route {
|
|
|
58
54
|
}
|
|
59
55
|
});
|
|
60
56
|
}
|
|
61
|
-
build(fn) {
|
|
62
|
-
return new Route(fn(this._app), this._schema);
|
|
63
|
-
}
|
|
64
|
-
handler(fn) {
|
|
65
|
-
console.log('handler set ', fn);
|
|
66
|
-
this._handlerRef.fn = fn;
|
|
67
|
-
}
|
|
68
57
|
}
|
|
69
58
|
exports.Route = Route;
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { AnyRoute, Body, Params, Query } from '@fy-tools/rpc-server';
|
|
2
|
-
import type { Request, Response } from 'express';
|
|
2
|
+
import type { NextFunction, Request, Response } from 'express';
|
|
3
3
|
export type RouteToContext<Schema extends AnyRoute> = {
|
|
4
4
|
body: Body<Schema>;
|
|
5
5
|
params: Params<Schema>;
|
|
6
6
|
query: Query<Schema>;
|
|
7
7
|
req: Request;
|
|
8
8
|
res: Response;
|
|
9
|
+
next: NextFunction;
|
|
9
10
|
};
|
|
10
11
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,QAAQ,IAAI;IACpD,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACvB,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACrB,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fy-tools/rpc-server-expressjs",
|
|
3
|
-
"version": "0.0.119-alpha.
|
|
3
|
+
"version": "0.0.119-alpha.10391",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/festusyuma/fy-tools.git",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"!**/*.tsbuildinfo"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@fy-tools/rpc-server": "0.0.119-alpha.
|
|
25
|
+
"@fy-tools/rpc-server": "0.0.119-alpha.10391",
|
|
26
26
|
"express": "^4.21.2",
|
|
27
27
|
"tslib": "^2.3.0"
|
|
28
28
|
},
|