Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { HttpEffect, HttpError, HttpStatus, use } from '@marblejs/core';
import { requestValidator$, t } from '@marblejs/middleware-io';
import { of, throwError } from 'rxjs';
import { catchError, map, mapTo, mergeMap } from 'rxjs/operators';
import { InstanceType } from 'typegoose';
import { neverNullable } from '../../../utils/never-nullable';
import { ReactionType } from '../model/article-reactions';
import { ArticleDao } from '../model/article.dao';
import { Article } from '../model/article.model';
export const articleReactionSchema = t.type({
reaction: t.union([t.literal('unicorn'), t.literal('mark'), t.literal('heart')]),
});
const validator$ = requestValidator$({
params: t.type({
id: t.string,
}),
body: articleReactionSchema,
});
const applyReaction = (reaction: ReactionType) => (article: InstanceType<article>) => {
const count = ++article.reactions.types[reaction].count;
article.reactions.types[reaction].count = count;
return article;
};
</article>export const createQuery = (opts: CollectionQueryValidatorOpts) =>
t.partial({
sortBy: t.union(opts.sortBy.map(s => t.literal(s)) as any),
sortDir: t.union([
t.refinement(t.union([t.string, t.number]), n => Number(n) === SortDir.ASC, 'SortDir.ASC'),
t.refinement(t.union([t.string, t.number]), n => Number(n) === SortDir.DESC, 'SortDir.DESC'),
]),
limit: t.refinement(t.union([t.string, t.number]), n => Number(n) >= 0, 'number.0+'),
page: t.refinement(t.union([t.string, t.number]), n => Number(n) >= 1, 'number.1+'),
});html: t.string,
tags: t.array(t.string),
slug: t.string,
published: t.boolean,
publishedAt: t.union([t.string, t.null]),
posterUrl: t.union([t.string, t.null]),
metaTitle: t.union([t.string, t.null]),
metaDescription: t.union([t.string, t.null]),
reactions: t.type({
types: t.type({
unicorn: t.type({ count: Positive }),
heart: t.type({ count: Positive }),
mark: t.type({ count: Positive }),
}),
}),
lang: t.union([t.literal(ArticleLanguage.FR), t.literal(ArticleLanguage.EN)]),
});
export type ArticlePayload = t.TypeOf;
export const articleValidator$ = requestValidator$({ body: articleSchema });import { r, HttpError, HttpStatus, combineRoutes, use, switchToProtocol } from '@marblejs/core';
import { requestValidator$, t } from '@marblejs/middleware-io';
import { throwError } from 'rxjs';
import { map, mergeMap, tap } from 'rxjs/operators';
import { user$ } from './user.effects';
import { static$ } from './static.effects';
import { WsServerToken } from '../tokens';
const rootValiadtor$ = requestValidator$({
params: t.type({
version: t.union([
t.literal('v1'),
t.literal('v2'),
]),
}),
});
const root$ = r.pipe(
r.matchPath('/'),
r.matchType('GET'),
r.useEffect((req$, _, { ask }) => req$.pipe(
use(rootValiadtor$),
map(req => req.params.version),
map(version => `API version: ${version}`),
tap(message => ask(WsServerToken).map(server =>
server.sendBroadcastResponse({ type: 'ROOT', payload: message })),
),
map(message => ({ body: message })),import { r, HttpError, HttpStatus, combineRoutes, use, switchToProtocol } from '@marblejs/core';
import { requestValidator$, t } from '@marblejs/middleware-io';
import { throwError } from 'rxjs';
import { map, mergeMap, tap } from 'rxjs/operators';
import { user$ } from './user.effects';
import { static$ } from './static.effects';
import { WsServerToken } from '../tokens';
const rootValiadtor$ = requestValidator$({
params: t.type({
version: t.union([
t.literal('v1'),
t.literal('v2'),
]),
}),
});
const root$ = r.pipe(
r.matchPath('/'),
r.matchType('GET'),
r.useEffect((req$, _, { ask }) => req$.pipe(
use(rootValiadtor$),
map(req => req.params.version),
map(version => `API version: ${version}`),
tap(message => ask(WsServerToken).map(server =>
server.sendBroadcastResponse({ type: 'ROOT', payload: message })),
),
map(message => ({ body: message })),
)));