How to use the @marblejs/core.EffectFactory.matchPath function in @marblejs/core

To help you get started, we’ve selected a few @marblejs/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marblejs / example / src / api / api.controller.ts View on Github external
import { EffectFactory, HttpError, HttpStatus, combineRoutes } from '@marblejs/core';
import { throwError } from 'rxjs';
import { mapTo, switchMap } from 'rxjs/operators';
import { auth$ } from './auth/auth.controller';
import { user$ } from './user/user.controller';

const root$ = EffectFactory
  .matchPath('/')
  .matchType('GET')
  .use(req$ => req$.pipe(
    mapTo({ body: `API version: v1` }),
  ));

const notFound$ = EffectFactory
  .matchPath('*')
  .matchType('*')
  .use(req$ => req$.pipe(
    switchMap(() =>
      throwError(new HttpError('Route not found', HttpStatus.NOT_FOUND))
    )
  ));

export const api$ = combineRoutes(
github edbzn / reactive-blog / packages / server / src / api / user / index.ts View on Github external
import { combineRoutes, EffectFactory } from '@marblejs/core';
import { authorize$ } from '../authentication/middlewares/auth.middleware';
import { getMeEffect$ } from './effects/get-me.effect';
import { getUsersEffect$ } from './effects/get-users.effect';

export const getUsers$ = EffectFactory.matchPath('/')
  .matchType('GET')
  .use(getUsersEffect$);

export const getMe$ = EffectFactory.matchPath('/me')
  .matchType('GET')
  .use(getMeEffect$);

export const user$ = combineRoutes('/user', {
  effects: [getUsers$, getMe$],
  middlewares: [authorize$],
});
github marblejs / example / src / api / root / effects / not-found.effect.ts View on Github external
import { EffectFactory, HttpError, HttpStatus } from '@marblejs/core';
import { switchMap } from 'rxjs/operators';
import { throwError } from 'rxjs';

export const notFound$ = EffectFactory
  .matchPath('*')
  .matchType('*')
  .use(req$ => req$.pipe(
    switchMap(() =>
      throwError(new HttpError('Route not found', HttpStatus.NOT_FOUND))
    )
  ));
github marblejs / marble / packages / @integration / src / api.integration.spec.ts View on Github external
const STATIC_PATH = path.resolve(__dirname, '../../../assets');

const authorize$: Effect = request$ =>
  request$.pipe(
    filter(req => req.headers.authorization === 'Bearer test'),
  );

const root$ = EffectFactory
  .matchPath('/')
  .matchType('GET')
  .use(req$ => req$
    .pipe(
      mapTo({ status: 200, body: 'root' }),
    ));

const getUserList$ = EffectFactory
  .matchPath('/')
  .matchType('GET')
  .use(req$ => req$
    .pipe(
      switchMap(() => of(MOCKED_USER_LIST)),
      map(users => ({ body: users }))
    ));

const getUserSingle$ = EffectFactory
  .matchPath('/:id')
  .matchType('GET')
  .use(req$ => req$
    .pipe(
      map(({ params, query }) => ({ body: { params, query } }))
    ));
github marblejs / example / src / api / index.ts View on Github external
import { combineRoutes, EffectFactory } from '@marblejs/core';
import { versionEffect$, preflightEffect$, getFileEffect$, notFoundEffect$ } from './common/effects';
import { auth$ } from './auth';
import { users$ } from './users';
import { actors$ } from './actors';
import { movies$ } from './movies';

const root$ = EffectFactory
  .matchPath('/')
  .matchType('GET')
  .use(versionEffect$);

const preflight$ = EffectFactory
  .matchPath('*')
  .matchType('OPTIONS')
  .use(preflightEffect$);

const getFile$ = EffectFactory
  .matchPath('/assets/:dir*')
  .matchType('GET')
  .use(getFileEffect$);

const notFound$ = EffectFactory
  .matchPath('*')
github marblejs / example / src / api / index.ts View on Github external
import { auth$ } from './auth';
import { users$ } from './users';
import { actors$ } from './actors';
import { movies$ } from './movies';

const root$ = EffectFactory
  .matchPath('/')
  .matchType('GET')
  .use(versionEffect$);

const preflight$ = EffectFactory
  .matchPath('*')
  .matchType('OPTIONS')
  .use(preflightEffect$);

const getFile$ = EffectFactory
  .matchPath('/assets/:dir*')
  .matchType('GET')
  .use(getFileEffect$);

const notFound$ = EffectFactory
  .matchPath('*')
  .matchType('*')
  .use(notFoundEffect$);

export const api$ = combineRoutes('/api/v1', [
  root$,
  auth$,
  users$,
  actors$,
  movies$,
  getFile$,
github edbzn / reactive-blog / packages / server / src / api / article / index.ts View on Github external
.matchType('GET')
  .use(getArticleByIdEffect$);

const getArticleBySlug$ = EffectFactory.matchPath('/slug/:slug')
  .matchType('GET')
  .use(getArticleBySlugEffect$);

const removeArticle$ = EffectFactory.matchPath('/:id')
  .matchType('DELETE')
  .use(removeArticleEffect$);

const updateArticle$ = EffectFactory.matchPath('/:id')
  .matchType('PUT')
  .use(updateArticleEffect$);

const updateArticleReaction$ = EffectFactory.matchPath('/:id/reaction')
  .matchType('POST')
  .use(updateArticleReactionEffect$);

const postArticle$ = EffectFactory.matchPath('/')
  .matchType('POST')
  .use(postArticleEffect$);

export const article$ = combineRoutes('/article', {
  effects: [getArticleList$, getArticleById$, getArticleBySlug$, updateArticleReaction$],
});

export const authorizedArticle$ = combineRoutes('/article', {
  effects: [postArticle$, removeArticle$, updateArticle$],
  middlewares: [authorize$],
});
github marblejs / marble / packages / @integration / src / api.integration.spec.ts View on Github external
.matchType('GET')
  .use(req$ => req$
    .pipe(
      mapTo({ status: 200, body: 'root' }),
    ));

const getUserList$ = EffectFactory
  .matchPath('/')
  .matchType('GET')
  .use(req$ => req$
    .pipe(
      switchMap(() => of(MOCKED_USER_LIST)),
      map(users => ({ body: users }))
    ));

const getUserSingle$ = EffectFactory
  .matchPath('/:id')
  .matchType('GET')
  .use(req$ => req$
    .pipe(
      map(({ params, query }) => ({ body: { params, query } }))
    ));

const postUser$ = EffectFactory
  .matchPath('/')
  .matchType('POST')
  .use(req$ => req$
    .pipe(
      use(authorize$),
      map(req => req.body),
      map(response => ({ body: response }))
    ));
github edbzn / reactive-blog / packages / server / src / api / article / index.ts View on Github external
.matchType('GET')
  .use(getArticleBySlugEffect$);

const removeArticle$ = EffectFactory.matchPath('/:id')
  .matchType('DELETE')
  .use(removeArticleEffect$);

const updateArticle$ = EffectFactory.matchPath('/:id')
  .matchType('PUT')
  .use(updateArticleEffect$);

const updateArticleReaction$ = EffectFactory.matchPath('/:id/reaction')
  .matchType('POST')
  .use(updateArticleReactionEffect$);

const postArticle$ = EffectFactory.matchPath('/')
  .matchType('POST')
  .use(postArticleEffect$);

export const article$ = combineRoutes('/article', {
  effects: [getArticleList$, getArticleById$, getArticleBySlug$, updateArticleReaction$],
});

export const authorizedArticle$ = combineRoutes('/article', {
  effects: [postArticle$, removeArticle$, updateArticle$],
  middlewares: [authorize$],
});

export const authorizedDraft$ = combineRoutes('/draft', {
  effects: [getDraftList$],
  middlewares: [authorize$],
});
github marblejs / marble / packages / @integration / src / api.integration.spec.ts View on Github external
.pipe(
      use(authorize$),
      map(req => req.body),
      map(response => ({ body: response }))
    ));

const error$ = EffectFactory
  .matchPath('/error')
  .matchType('GET')
  .use(req$ => req$
    .pipe(
      switchMap(() => throwError(new HttpError('test', HttpStatus.METHOD_NOT_ALLOWED, { test: 'test' }))),
    )
  );

const file$ = EffectFactory
  .matchPath('/static/:dir')
  .matchType('GET')
  .use(req$ => req$
    .pipe(
      map(req => req.params!.dir as string),
      switchMap(readFile(STATIC_PATH)),
      map(body => ({ body }))
    ));

const user$ = combineRoutes('/user', [getUserList$, getUserSingle$, postUser$]);

const api$ = combineRoutes('/api/:version', [root$, file$, error$, user$]);

const app = httpListener({
  middlewares: [bodyParser$],
  effects: [api$],