Export everything in packages/server
This commit is contained in:
parent
3bd4083999
commit
5881b64ecf
@ -1,4 +1,4 @@
|
||||
server := src/server/index.ts
|
||||
server := src/bootstrap.ts
|
||||
typeorm := ts-node ../../node_modules/.bin/typeorm
|
||||
|
||||
orm:
|
||||
|
||||
@ -54,7 +54,7 @@ export class Application implements IApplication {
|
||||
|
||||
router.use('/app', urlencoded({ extended: false }))
|
||||
|
||||
router.use(new middleware.Session({
|
||||
router.use(new middleware.SessionMiddleware({
|
||||
transactionManager,
|
||||
baseUrl: this.config.app.baseUrl,
|
||||
sessionName: this.config.app.session.name,
|
||||
|
||||
3
packages/server/src/entities/index.ts
Normal file
3
packages/server/src/entities/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './Session'
|
||||
export * from './User'
|
||||
export * from './UserEmail'
|
||||
9
packages/server/src/index.ts
Normal file
9
packages/server/src/index.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export * from './application'
|
||||
export * from './database'
|
||||
export * from './entities'
|
||||
export * from './logger'
|
||||
export * from './middleware'
|
||||
export * from './router'
|
||||
export * from './routes'
|
||||
export * from './services'
|
||||
export * from './session'
|
||||
@ -14,7 +14,7 @@ export interface ISessionOptions {
|
||||
sessionSecret: string | string[],
|
||||
}
|
||||
|
||||
export class Session implements IMiddleware {
|
||||
export class SessionMiddleware implements IMiddleware {
|
||||
readonly handle: IHandler
|
||||
|
||||
constructor(readonly params: ISessionOptions) {
|
||||
@ -49,4 +49,3 @@ export class Session implements IMiddleware {
|
||||
return this.params.transactionManager.getRepository(SessionEntity)
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,5 +9,5 @@ export * from './IHandler'
|
||||
export * from './IMiddleware'
|
||||
export * from './IPromiseHandler'
|
||||
export * from './RequestLogger'
|
||||
export * from './Session'
|
||||
export * from './SessionMiddleware'
|
||||
export * from './Transaction'
|
||||
|
||||
@ -1,15 +1,6 @@
|
||||
import {IRoutes, IRoute, IMethod} from '@rondo/common'
|
||||
import express, {NextFunction} from 'express'
|
||||
|
||||
export interface IRequest<T extends IRoute> extends express.Request {
|
||||
body: T['body']
|
||||
params: T['params']
|
||||
query: T['query']
|
||||
}
|
||||
|
||||
export type IHandler<R extends IRoutes, P extends keyof R, M extends IMethod> =
|
||||
(req: IRequest<R[P][M]>, res: express.Response, next: NextFunction) =>
|
||||
Promise<R[P][M]['response']>
|
||||
import express from 'express'
|
||||
import {IRoutes, IMethod} from '@rondo/common'
|
||||
import {ITypedHandler} from './ITypedHandler'
|
||||
|
||||
export class AsyncRouter<R extends IRoutes> {
|
||||
readonly router: express.Router
|
||||
@ -23,7 +14,7 @@ export class AsyncRouter<R extends IRoutes> {
|
||||
protected addRoute<M extends IMethod, P extends keyof R & string>(
|
||||
method: M,
|
||||
path: P,
|
||||
handler: IHandler<R, P, M>,
|
||||
handler: ITypedHandler<R, P, M>,
|
||||
) {
|
||||
const addRoute = this.router[method].bind(this.router)
|
||||
|
||||
@ -31,7 +22,7 @@ export class AsyncRouter<R extends IRoutes> {
|
||||
}
|
||||
|
||||
protected wrapHandler<M extends IMethod, P extends keyof R & string>(
|
||||
handler: IHandler<R, P, M>,
|
||||
handler: ITypedHandler<R, P, M>,
|
||||
): express.RequestHandler {
|
||||
return (req, res, next) => {
|
||||
handler(req, res, next)
|
||||
@ -42,34 +33,45 @@ export class AsyncRouter<R extends IRoutes> {
|
||||
}
|
||||
}
|
||||
|
||||
get<P extends keyof R & string>(path: P, handler: IHandler<R, P, 'get'>) {
|
||||
get<P extends keyof R & string>(
|
||||
path: P,
|
||||
handler: ITypedHandler<R, P, 'get'>,
|
||||
) {
|
||||
this.addRoute('get', path, handler)
|
||||
}
|
||||
|
||||
post<P extends keyof R & string>(path: P, handler: IHandler<R, P, 'post'>) {
|
||||
post<P extends keyof R & string>(
|
||||
path: P,
|
||||
handler: ITypedHandler<R, P, 'post'>,
|
||||
) {
|
||||
this.addRoute('post', path, handler)
|
||||
}
|
||||
|
||||
put<P extends keyof R & string>(path: P, handler: IHandler<R, P, 'put'>) {
|
||||
put<P extends keyof R & string>(
|
||||
path: P, handler: ITypedHandler<R, P, 'put'>,
|
||||
) {
|
||||
this.addRoute('put', path, handler)
|
||||
}
|
||||
|
||||
delete<P extends keyof R & string>(
|
||||
path: P, handler: IHandler<R, P, 'delete'>) {
|
||||
path: P, handler: ITypedHandler<R, P, 'delete'>) {
|
||||
this.addRoute('delete', path, handler)
|
||||
}
|
||||
|
||||
head<P extends keyof R & string>(path: P, handler: IHandler<R, P, 'head'>) {
|
||||
head<P extends keyof R & string>(
|
||||
path: P,
|
||||
handler: ITypedHandler<R, P, 'head'>,
|
||||
) {
|
||||
this.addRoute('head', path, handler)
|
||||
}
|
||||
|
||||
options<P extends keyof R & string>(
|
||||
path: P, handler: IHandler<R, P, 'options'>) {
|
||||
path: P, handler: ITypedHandler<R, P, 'options'>) {
|
||||
this.addRoute('options', path, handler)
|
||||
}
|
||||
|
||||
patch<P extends keyof R & string>(
|
||||
path: P, handler: IHandler<R, P, 'patch'>) {
|
||||
path: P, handler: ITypedHandler<R, P, 'patch'>) {
|
||||
this.addRoute('patch', path, handler)
|
||||
}
|
||||
|
||||
|
||||
13
packages/server/src/router/ITypedHandler.ts
Normal file
13
packages/server/src/router/ITypedHandler.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import express from 'express'
|
||||
import {IRoutes, IMethod} from '@rondo/common'
|
||||
import {ITypedRequest} from './ITypedRequest'
|
||||
|
||||
export type ITypedHandler<
|
||||
R extends IRoutes,
|
||||
P extends keyof R,
|
||||
M extends IMethod
|
||||
> = (
|
||||
req: ITypedRequest<R[P][M]>,
|
||||
res: express.Response,
|
||||
next: express.NextFunction,
|
||||
) => Promise<R[P][M]['response']>
|
||||
8
packages/server/src/router/ITypedRequest.ts
Normal file
8
packages/server/src/router/ITypedRequest.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import express from 'express'
|
||||
import {IRoute} from '@rondo/common'
|
||||
|
||||
export interface ITypedRequest<T extends IRoute> extends express.Request {
|
||||
body: T['body']
|
||||
params: T['params']
|
||||
query: T['query']
|
||||
}
|
||||
@ -1,7 +1,8 @@
|
||||
import express from 'express'
|
||||
import {AsyncRouter, IHandler} from './AsyncRouter'
|
||||
import {AsyncRouter} from './AsyncRouter'
|
||||
import {IRoutes, IMethod} from '@rondo/common'
|
||||
import {ITransactionManager} from '../database/ITransactionManager'
|
||||
import {ITypedHandler} from './ITypedHandler'
|
||||
|
||||
export class TransactionalRouter<R extends IRoutes> extends AsyncRouter<R> {
|
||||
constructor(readonly transactionManager: ITransactionManager) {
|
||||
@ -9,7 +10,7 @@ export class TransactionalRouter<R extends IRoutes> extends AsyncRouter<R> {
|
||||
}
|
||||
|
||||
protected wrapHandler<M extends IMethod, P extends keyof R & string>(
|
||||
handler: IHandler<R, P, M>,
|
||||
handler: ITypedHandler<R, P, M>,
|
||||
): express.RequestHandler {
|
||||
return async (req, res, next) => {
|
||||
await this.transactionManager
|
||||
|
||||
@ -1,2 +1,4 @@
|
||||
export * from './AsyncRouter'
|
||||
export * from './ITypedHandler'
|
||||
export * from './ITypedRequest'
|
||||
export * from './TransactionalRouter'
|
||||
|
||||
2
packages/server/src/session/index.ts
Normal file
2
packages/server/src/session/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './ISession'
|
||||
export * from './SessionStore'
|
||||
Loading…
x
Reference in New Issue
Block a user