@sepo27/servicio 0.6.4 → 0.6.6
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 +8 -0
- package/README.md +16 -1
- package/dist/src/main/app/servicio.spec.js +94 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## <small>0.6.6 (2026-12-05)</small>
|
|
2
|
+
|
|
3
|
+
* docs: Update README ([9668021](https://github.com/sepo27/servicio/commit/9668021))
|
|
4
|
+
|
|
5
|
+
## <small>0.6.5 (2026-12-05)</small>
|
|
6
|
+
|
|
7
|
+
* test: Integration test extended usage ([6052367](https://github.com/sepo27/servicio/commit/6052367))
|
|
8
|
+
|
|
1
9
|
## <small>0.6.4 (2026-12-05)</small>
|
|
2
10
|
|
|
3
11
|
* docs: Update README ([6c77c63](https://github.com/sepo27/servicio/commit/6c77c63))
|
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Status
|
|
2
2
|
|
|
3
|
-
**:warning: ACTIVE DEVELOPMENT :warning:**
|
|
3
|
+
**:warning: ACTIVE DEVELOPMENT :warning:**
|
|
4
|
+
*(MINOR version bumps may be actually MAJOR)*
|
|
4
5
|
|
|
5
6
|
# What
|
|
6
7
|
|
|
@@ -27,6 +28,8 @@ import { svc, HttpStatus, SuccessResponse } from '@sepo27/servicio';
|
|
|
27
28
|
|
|
28
29
|
const app: svc.App = svc.app();
|
|
29
30
|
|
|
31
|
+
app.use(...); // Use whatever used with express app itself
|
|
32
|
+
|
|
30
33
|
app.useRoute('GET /foo', () => {
|
|
31
34
|
return new SuccessResponse({
|
|
32
35
|
status: HttpStatus.OK,
|
|
@@ -72,6 +75,8 @@ router.useRoute('GET /', () => new SuccessResponse({
|
|
|
72
75
|
},
|
|
73
76
|
}))
|
|
74
77
|
|
|
78
|
+
router.use(...) // Use whaever used with express Router
|
|
79
|
+
|
|
75
80
|
app.useRouter(router)
|
|
76
81
|
```
|
|
77
82
|
|
|
@@ -82,7 +87,10 @@ import { svc, SuccessResponse, HttpStatus } from '@sepo27/servicio';
|
|
|
82
87
|
|
|
83
88
|
const app: svc.App = svc.app()
|
|
84
89
|
|
|
90
|
+
// Parent Router
|
|
91
|
+
|
|
85
92
|
const router: svc.Router = svc.router('/foo')
|
|
93
|
+
|
|
86
94
|
router.useRoute('GET /', () => new SuccessResponse({
|
|
87
95
|
status: HttpStatus.OK,
|
|
88
96
|
body: {
|
|
@@ -90,7 +98,12 @@ router.useRoute('GET /', () => new SuccessResponse({
|
|
|
90
98
|
},
|
|
91
99
|
}))
|
|
92
100
|
|
|
101
|
+
router.use(...) // Use whaever used with express Router
|
|
102
|
+
|
|
103
|
+
// Child Router
|
|
104
|
+
|
|
93
105
|
const fooItemsRouter: svc.Router = svc.router('/:id/items', { mergeParams: true })
|
|
106
|
+
|
|
94
107
|
fooItemsRouter.useRoute('GET /', () => new SuccessResponse({
|
|
95
108
|
status: HttpStatus.OK,
|
|
96
109
|
body: {
|
|
@@ -98,6 +111,8 @@ fooItemsRouter.useRoute('GET /', () => new SuccessResponse({
|
|
|
98
111
|
},
|
|
99
112
|
}))
|
|
100
113
|
|
|
114
|
+
fooItemsRouter.use(...) // Use whaever used with express Router
|
|
115
|
+
|
|
101
116
|
router.useRouter(fooItemsRouter)
|
|
102
117
|
|
|
103
118
|
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', () => {
|