@sepo27/servicio 0.6.4 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## <small>0.6.5 (2026-12-05)</small>
2
+
3
+ * test: Integration test extended usage ([6052367](https://github.com/sepo27/servicio/commit/6052367))
4
+
1
5
  ## <small>0.6.4 (2026-12-05)</small>
2
6
 
3
7
  * docs: Update README ([6c77c63](https://github.com/sepo27/servicio/commit/6c77c63))
package/README.md CHANGED
@@ -27,6 +27,8 @@ import { svc, HttpStatus, SuccessResponse } from '@sepo27/servicio';
27
27
 
28
28
  const app: svc.App = svc.app();
29
29
 
30
+ app.use(...); // Use whatever used with express app itself
31
+
30
32
  app.useRoute('GET /foo', () => {
31
33
  return new SuccessResponse({
32
34
  status: HttpStatus.OK,
@@ -72,6 +74,8 @@ router.useRoute('GET /', () => new SuccessResponse({
72
74
  },
73
75
  }))
74
76
 
77
+ router.use(...) // Use whaever used with express Router
78
+
75
79
  app.useRouter(router)
76
80
  ```
77
81
 
@@ -82,7 +86,10 @@ import { svc, SuccessResponse, HttpStatus } from '@sepo27/servicio';
82
86
 
83
87
  const app: svc.App = svc.app()
84
88
 
89
+ // Parent Router
90
+
85
91
  const router: svc.Router = svc.router('/foo')
92
+
86
93
  router.useRoute('GET /', () => new SuccessResponse({
87
94
  status: HttpStatus.OK,
88
95
  body: {
@@ -90,7 +97,12 @@ router.useRoute('GET /', () => new SuccessResponse({
90
97
  },
91
98
  }))
92
99
 
100
+ router.use(...) // Use whaever used with express Router
101
+
102
+ // Child Router
103
+
93
104
  const fooItemsRouter: svc.Router = svc.router('/:id/items', { mergeParams: true })
105
+
94
106
  fooItemsRouter.useRoute('GET /', () => new SuccessResponse({
95
107
  status: HttpStatus.OK,
96
108
  body: {
@@ -98,6 +110,8 @@ fooItemsRouter.useRoute('GET /', () => new SuccessResponse({
98
110
  },
99
111
  }))
100
112
 
113
+ fooItemsRouter.use(...) // Use whaever used with express Router
114
+
101
115
  router.useRouter(fooItemsRouter)
102
116
 
103
117
  app.useRouter(router)
@@ -61,6 +61,27 @@ describe('servicio', () => {
61
61
  expect(res.body).toEqual(response.body);
62
62
  });
63
63
  }));
64
+ it('handles simple route and middleware', () => __awaiter(void 0, void 0, void 0, function* () {
65
+ const middleware = (req, _, next) => {
66
+ // @ts-ignore: TODO
67
+ req.testValue = 'test';
68
+ next();
69
+ };
70
+ app.use(middleware);
71
+ app.useRoute('GET /test', (req) => {
72
+ return new SuccessResponse({
73
+ status: HttpStatus.OK,
74
+ // @ts-ignore: TODO
75
+ body: { value: req.testValue },
76
+ });
77
+ });
78
+ yield agent
79
+ .get('/test')
80
+ .expect(HttpStatus.OK)
81
+ .expect(res => {
82
+ expect(res.body).toEqual({ value: 'test' });
83
+ });
84
+ }));
64
85
  it('handles router', () => __awaiter(void 0, void 0, void 0, function* () {
65
86
  const router = svc.router('/foo');
66
87
  router.useRoute('GET /:id', () => new SuccessResponse());
@@ -69,6 +90,28 @@ describe('servicio', () => {
69
90
  .get('/foo/123')
70
91
  .expect(HttpStatus.OK);
71
92
  }));
93
+ it('handles router and middleware', () => __awaiter(void 0, void 0, void 0, function* () {
94
+ const middleware = (req, _, next) => {
95
+ // @ts-ignore: TODO
96
+ req.testValue = 'test';
97
+ next();
98
+ }, router = svc.router('/foo');
99
+ router.use(middleware);
100
+ router.useRoute('GET /:id', (req) => {
101
+ return new SuccessResponse({
102
+ status: HttpStatus.OK,
103
+ // @ts-ignore: TODO
104
+ body: { value: req.testValue },
105
+ });
106
+ });
107
+ app.useRouter(router);
108
+ yield agent
109
+ .get('/foo/123')
110
+ .expect(HttpStatus.OK)
111
+ .expect(res => {
112
+ expect(res.body).toEqual({ value: 'test' });
113
+ });
114
+ }));
72
115
  it('handles nested router', () => __awaiter(void 0, void 0, void 0, function* () {
73
116
  const router = svc.router('/bar');
74
117
  router.useRoute('GET /:id', () => new SuccessResponse());
@@ -86,6 +129,57 @@ describe('servicio', () => {
86
129
  expect(res.body).toEqual(itemsResponse.body);
87
130
  });
88
131
  }));
132
+ it('handles nested router with parent middleware', () => __awaiter(void 0, void 0, void 0, function* () {
133
+ const middleware = (req, _, next) => {
134
+ // @ts-ignore: TODO
135
+ req.parentValue = 'parent';
136
+ next();
137
+ }, router = svc.router('/bar'), nestedRouter = svc.router('/:id/items');
138
+ router.use(middleware);
139
+ nestedRouter.useRoute('GET /', (req) => {
140
+ return new SuccessResponse({
141
+ status: HttpStatus.OK,
142
+ // @ts-ignore: TODO
143
+ body: { parentValue: req.parentValue },
144
+ });
145
+ });
146
+ router.useRouter(nestedRouter);
147
+ app.useRouter(router);
148
+ yield agent
149
+ .get('/bar/123/items')
150
+ .expect(HttpStatus.OK)
151
+ .expect(res => {
152
+ expect(res.body).toEqual({ parentValue: 'parent' });
153
+ });
154
+ }));
155
+ it('handles nested router with parent and child middlewares', () => __awaiter(void 0, void 0, void 0, function* () {
156
+ const parentMiddleware = (req, _, next) => {
157
+ // @ts-ignore: TODO
158
+ req.parentValue = 'parent';
159
+ next();
160
+ }, childMiddleware = (req, _, next) => {
161
+ // @ts-ignore: TODO
162
+ req.childValue = 'child';
163
+ next();
164
+ }, router = svc.router('/bar'), nestedRouter = svc.router('/:id/items');
165
+ router.use(parentMiddleware);
166
+ nestedRouter.use(childMiddleware);
167
+ nestedRouter.useRoute('GET /', (req) => {
168
+ return new SuccessResponse({
169
+ status: HttpStatus.OK,
170
+ // @ts-ignore: TODO
171
+ body: { parentValue: req.parentValue, childValue: req.childValue },
172
+ });
173
+ });
174
+ router.useRouter(nestedRouter);
175
+ app.useRouter(router);
176
+ yield agent
177
+ .get('/bar/123/items')
178
+ .expect(HttpStatus.OK)
179
+ .expect(res => {
180
+ expect(res.body).toEqual({ parentValue: 'parent', childValue: 'child' });
181
+ });
182
+ }));
89
183
  it('handles http error with status by default (w/ express default handler)', () => __awaiter(void 0, void 0, void 0, function* () {
90
184
  const error = new BadRequestError();
91
185
  app.useRoute('GET /xyz', () => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sepo27/servicio",
3
3
  "description": "Backend Service Frame",
4
- "version": "0.6.4",
4
+ "version": "0.6.5",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",
7
7
  "types": "./dist/src/index.d.ts",