@sepo27/servicio 0.5.0 → 0.6.0
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## 0.6.0 (2026-12-05)
|
|
2
|
+
|
|
3
|
+
* feat: Extend makeRouter() to support options ([b9aa465](https://github.com/sepo27/servicio/commit/b9aa465))
|
|
4
|
+
|
|
1
5
|
## 0.5.0 (2026-12-05)
|
|
2
6
|
|
|
3
7
|
* refaactor: Refactor complete approach to use namespace solution ([4006cd3](https://github.com/sepo27/servicio/commit/4006cd3))
|
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ router.useRoute('GET /', () => new SuccessResponse({
|
|
|
90
90
|
},
|
|
91
91
|
}))
|
|
92
92
|
|
|
93
|
-
const fooItemsRouter: svc.Router = svc.router('/:id/items')
|
|
93
|
+
const fooItemsRouter: svc.Router = svc.router('/:id/items', { mergeParams: true })
|
|
94
94
|
fooItemsRouter.useRoute('GET /', () => new SuccessResponse({
|
|
95
95
|
status: HttpStatus.OK,
|
|
96
96
|
body: {
|
|
@@ -103,8 +103,9 @@ router.useRouter(fooItemsRouter)
|
|
|
103
103
|
app.useRouter(router)
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
*:information_source: Mind `mergeParams` option to handle params in sub-routers (see [here](https://expressjs.com/en/5x/guide/routing/#expressrouter))*
|
|
107
|
+
|
|
108
|
+
:information_source: Servicio does not currently support chainable methods (due to mixin proxy complexity)
|
|
108
109
|
|
|
109
110
|
## Express JS wrapper
|
|
110
111
|
|
package/dist/src/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare namespace svc {
|
|
|
5
5
|
const app: () => AppType;
|
|
6
6
|
const route: (endpoint: import("./main/types.js").RouteEndpointParam, action: import("./main/types.js").RouteAction) => RouteClass;
|
|
7
7
|
const Route: typeof RouteClass;
|
|
8
|
-
const router: (path: string) => RouterType;
|
|
8
|
+
const router: (path: string, options?: import("express").RouterOptions) => RouterType;
|
|
9
9
|
type App = AppType;
|
|
10
10
|
type Route = RouteClass;
|
|
11
11
|
type Router = RouterType;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import express from 'express';
|
|
2
2
|
import { RouterX } from '../routing/RouterX.js';
|
|
3
3
|
import { mixinProxy } from './mixinProxy.js';
|
|
4
|
-
export const makeRouter = (path) => {
|
|
5
|
-
const irouter = express.Router();
|
|
4
|
+
export const makeRouter = (path, options) => {
|
|
5
|
+
const irouter = express.Router(options);
|
|
6
6
|
return mixinProxy(new RouterX(path, irouter), irouter);
|
|
7
7
|
};
|
|
@@ -14,11 +14,19 @@ describe('makeRouter()', () => {
|
|
|
14
14
|
});
|
|
15
15
|
it('creates a router by combining RouterX with Express and returns the proxy', () => {
|
|
16
16
|
const path = '/foo', irouter = bench.mock.express.getRoutable(), router = {};
|
|
17
|
-
const
|
|
17
|
+
const expressRouterFactoryMock = jest.spyOn(express, 'Router').mockReturnValue(irouter), mixinProxyMock = jest.spyOn(mixinProxyModule, 'mixinProxy').mockReturnValue(router);
|
|
18
18
|
expect(makeRouter(path)).toBe(router);
|
|
19
|
-
expect(
|
|
19
|
+
expect(expressRouterFactoryMock).toHaveBeenCalledTimes(1);
|
|
20
20
|
expect(mixinProxyMock).toHaveBeenCalledTimes(1);
|
|
21
21
|
expect(mixinProxyMock).toHaveBeenCalledWith(expect.any(RouterX), irouter);
|
|
22
22
|
expect(mixinProxyMock).toHaveBeenCalledWith(expect.objectContaining({ path }), irouter);
|
|
23
23
|
});
|
|
24
|
+
it('creates a router without options', () => {
|
|
25
|
+
const opts = { mergeParams: true };
|
|
26
|
+
const expressRouterFactoryMock = jest.spyOn(express, 'Router');
|
|
27
|
+
jest.spyOn(mixinProxyModule, 'mixinProxy');
|
|
28
|
+
makeRouter('/foo', opts);
|
|
29
|
+
expect(expressRouterFactoryMock).toHaveBeenCalledTimes(1);
|
|
30
|
+
expect(expressRouterFactoryMock).toHaveBeenCalledWith(opts);
|
|
31
|
+
});
|
|
24
32
|
});
|