refactor(example): update example code to newest api
MODIFY
example/src/controllers/api.controller.ts
example/src/controllers/api.controller.ts
-import { Effect, HttpError, HttpStatus, combineRoutes, matchPath, matchType } from '@marblejs/core';
+import { EffectFactory, HttpError, HttpStatus, combineRoutes } from '@marblejs/core';
import { throwError } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { user$ } from './user.controller';
-const root$: Effect = request$ => request$
- .pipe(
- matchPath('/'),
- matchType('GET'),
+const root$ = EffectFactory
+ .matchPath('/')
+ .matchType('GET')
+ .use(req$ => req$.pipe(
map(req => ({
body: `API root @ ${req.url}`,
})),
);
-const notFound$: Effect = request$ => request$
- .pipe(
- matchPath('*'),
- matchType('*'),
+const notFound$ = EffectFactory
+ .matchPath('*')
+ .matchType('*')
+ .use(req$ => req$.pipe(
switchMap(() =>
throwError(new HttpError('Route not found', HttpStatus.NOT_FOUND))
)
- );
+ ));
export const api$ = combineRoutes(
'/api/v1',

MODIFY
example/src/controllers/user.controller.ts
example/src/controllers/user.controller.ts
-import { Effect, combineRoutes, matchPath, matchType, use } from '@marblejs/core';
+import { EffectFactory, combineRoutes, use } from '@marblejs/core';
import { map, switchMap } from 'rxjs/operators';
import { Dao } from '../fakes/dao.fake';
import { authorize$ } from '../middlewares/auth.middleware';
-const getUsers$: Effect = request$ =>
- request$.pipe(
- matchPath('/'),
- matchType('GET'),
+const getUsers$ = EffectFactory
+ .matchPath('/')
+ .matchType('GET')
+ .use(req$ => req$.pipe(
use(authorize$),
switchMap(Dao.getUsers),
map(users => ({ body: users })),
- );
+ ));
-const postUser$: Effect = request$ =>
- request$.pipe(
- matchPath('/'),
- matchType('POST'),
+const postUser$ = EffectFactory
+ .matchPath('/')
+ .matchType('POST')
+ .use(req$ => req$.pipe(
use(authorize$),
map(req => req.body),
switchMap(Dao.postUser),
map(response => ({ body: response })),
- );
+ ));
export const user$ = combineRoutes(
'/user',

MODIFY
packages/middleware-joi/README.md
packages/middleware-joi/README.md
@@ -9,17 +9,18 @@ Example of using this middleware on a GET route to validate params.
```javascript
import { validator$, Joi } from '@marblejs/middleware-joi';
-const foo$: Effect = request$ => request$
- .pipe(
- matchPath('/foo/:id'),
- matchType('GET'),
+
+const foo$ = EffectFactory
+ .matchPath('/foo/:id')
+ .matchType('GET')
+ .use(req$ => req$.pipe(
use(validator$({
params: Joi.object({
id: Joi.number().min(1).max(10),
})
}));
// ...
- );
+ ));
```
Example to validate all incoming requests.

refactor(example): update example code to newest api