This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 📄 postOfferFile.effect.ts | |
| const postOffersFile$ = r.pipe( | |
| r.matchPath('/offers/:id/file'), | |
| r.matchType('POST'), | |
| r.useEffect((req$, ctx) => { | |
| const eventBusClient = useContext(EventBusClientToken)(ctx.ask); | |
| return req$.pipe( | |
| validateRequest, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface Effect<I, O, Client> { | |
| (input$: Observable<I>, ctx: EffectContext<Client>): Observable<O>; | |
| } | |
| interface HttpEffect< | |
| I = HttpRequest, | |
| O = HttpEffectResponse, | |
| > extends Effect<I, O, HttpServer> {} | |
| interface WsEffect< |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // HTTP server logger output | |
| λ - 47700 - 2020-01-27 22:04:21 - http [Context] - Registered: "HttpRequestBusToken" | |
| λ - 47700 - 2020-01-27 22:04:21 - http [Context] - Registered: "HttpServerClientToken" | |
| λ - 47700 - 2020-01-27 22:04:21 - http [Context] - Registered: "HttpServerEventStreamToken" | |
| λ - 47700 - 2020-01-27 22:04:21 - http [Context] - Registered: "LoggerToken" | |
| λ - 47700 - 2020-01-27 22:04:21 - http [Router] - Effect mapped: /api/:version GET | |
| λ - 47700 - 2020-01-27 22:04:21 - http [Router] - Effect mapped: /api/:version/user GET | |
| λ - 47700 - 2020-01-27 22:04:21 - http [Router] - Effect mapped: /api/:version/user POST | |
| λ - 47700 - 2020-01-27 22:04:21 - http [Router] - Effect mapped: /api/:version/user/:id GET |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| bindEagerlyTo(Token)(async () => 'bar'); | |
| const foo = useContext(Token)(ask); // foo === 'bar' | |
| // but... | |
| bindTo(Token)(async () => 'bar'); | |
| const foo = useContext(Token)(ask); // foo === Promise<'bar'> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const foo$ = r.pipe( | |
| r.applyMeta({ continuous: true }), | |
| r.matchPath('/'), | |
| r.matchType('GET'), | |
| r.useEffect((req$, ctx) => { | |
| const reqBus$ = useContext(HttpRequestBusToken)(ctx.ask); | |
| const terminate$ = reqBus$.pipe(filter(req => req.url === '/flush')); | |
| return req$.pipe( | |
| bufferWhen(() => terminate$), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 📄 publisher - fib.effect.ts | |
| const fib$ = r.pipe( | |
| r.matchPath('/fib/:number'), | |
| r.matchType('GET'), | |
| r.useEffect((req$, ctx) => { | |
| const client = useContext(ClientToken)(ctx.ask); | |
| return req$.pipe( | |
| validateRequest, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { createServer, combineRoutes, httpListener, r } from '@marblejs/core'; | |
| import { logger$ } from '@marblejs/middleware-logger'; | |
| import { bodyParser$ } from '@marblejs/middleware-body'; | |
| import { map, mapTo } from 'rxjs/operators'; | |
| // USERS API definition | |
| const getUserList$ = r.pipe( | |
| r.matchPath('/'), | |
| r.matchType('GET'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const httpsOptions: https.ServerOptions = { | |
| key: fs.readFileSync('key.pem'), | |
| cert: fs.readFileSync('cert.pem'), | |
| }; | |
| const listening$: HttpServerEffect = event$ => | |
| event$.pipe( | |
| matchEvent(ServerEvent.listening), | |
| map(event => event.payload), | |
| tap(({ port, host }) => console.log(`Running @ http://${host}:${port}/`)), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { bodyParser$, jsonParser } from '@marblejs/middleware-body'; | |
| bodyParser$({ | |
| parser: jsonParser, | |
| type: ['*/json', 'application/vnd.api+json'], | |
| }) | |
| // or | |
| import { bodyParser$, urlEncodedParser } from '@marblejs/middleware-body'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const userSchema: t.type({ | |
| id: t.string, | |
| name: t.string, | |
| age: t.number, | |
| roles: t.array(t.union([ | |
| t.literal('ADMIN'), | |
| t.literal('GUEST'), | |
| ])), | |
| }); |
NewerOlder