smartive / giuseppe Goto Github PK
View Code? Open in Web Editor NEWA controller routing system for expressJS with TypeScript decorators and annotations
Home Page: http://giuseppe.smartive.ch
A controller routing system for expressJS with TypeScript decorators and annotations
Home Page: http://giuseppe.smartive.ch
Add a guide or even yeoman "integration" to get an example app running quickly.
chain multiple param validators
add a possibility to add a custom logging framework (via an interface) to enable logging for giuseppe
(maybe graylog or such a thing)
related to #80
Error
https://github.com/smartive/giuseppe/blob/master/controllers/ControllerDecorator.ts#L372
This prevents the whole application startup if any error occurs.
Maybe we should just log the error and continue?
The problem is, that the transpiled javascript is coverage tested and not the real source.
There could be a solution to remap the coverage results back to the typescript files.
Cannot find type definition file for 'chai'.
Error on compiling.
-> ParamDecorator.d.ts
/// <reference types="chai" />
import 'reflect-metadata';
import { BodyParamOptions, CookieParamOptions, ParamOptions, QueryParamOptions } from './ParamOptions';
/**
* Reflect metadata key for parameter list.
* @type {string}
*/
export declare const PARAMS_KEY: string;
Upgrade all stuff that is contained in giuseppe. This will cause havoc, but is necessary.
introduce some integrationtests (possibly through postman / newman) to ensure that giuseppe works with the given express JS version
(or even multiple versions?)
Controller that are only registered to certain routers.
This would add the possibility to create multiple sections of a site like:
registerControllers('user', userRouter);
registerControllers('admin', adminRouter);
Please add a newline before each @returns
in KSDoc.
related to #80
We may need a plugin system to enhance the way, giuseppe is handling everything.
This could support the following example
Since express has the possibility to add default routes (routes with *
in it) we need to provide any way of ordering the registrations.
If we don't, the (random) order of the decorators would define the wildcard routes.
One usecase:
/api/....
/*
with a catch all that is not registered to send the index.html
since controllers are instantiated, it would be cool to have some sort of a dependency injection (constructor injection?) to provide certain things via DI.
an example could be an instance of an elasticsearch client, or some other injected things
Add possibility to validate array items
array.every( -> validator )
It is not possible to call this.method() within an error handler method.
this
is undefined inside a route method.
Instantiate the controller and use it as this controller? But needs to be scoped for all route methods.
Should we add an error or a warning when @Body()
is used and no body-parser package is installed?
A similar problem exists with the future of @Cookie
param decorator. If there is no cookie-parser package, those two will always deliver undefined.
Maybe it's in the responsibility of the user since there could exist more than just body-parser
or other default expressJS packages.
Add default parameter null
for routePrefix
to allow @Post(passport.authenticate())
rather than @Post('', passport.authenticate())
.
The following usages must work:
@Post()
@Post('path')
@Post('path', middleware)
@Post('path', mw1, mw2)
@Post(mw1, mw2)
https://github.com/smartive/giuseppe/blob/master/controllers/ControllerDecorator.ts
Hi,
I really like your idea and the controller registration using decorators. When trying to make it work on my side I spend about an hour of debugging to find out why the routing does not work and I'm getting 402 No Content.
In ControllerDecorator
class on line 198 you're reading the return type of the route method. However, for this to work correctly the metadata must be emitted by the tsc
compiler and that requires compiler option emitDecoratorMetadata
to be set to true
. This is not emphasized in the documentation. Can you please add this note to readme document?
Thanks,
Karel
possibility to pass a constructor function for a parameter type
e.g.:
public foobar(@Query('bla', {constructor: Demo.create }) bla: Demo ){}
Or even a factory function:
public foobar(@Query('bla', {constructor: raw => Demo.create(raw) }) bla: Demo ){}
/*...*/
@Head(':id')
public exists(@UrlParam('id') id: number): boolean {
return true;
}
/*...*/
If head route is used and return value is Boolean
use the correct and corresponding status codes to implement an "exists" route.
true
-> res.status(httpStatus.SUCCESS);
false
-> res.status(httpStatus.NOT_FOUND);
possible solution: change regex to ^((?!spec).)*[.]js
to exclude spec files from loading
Some example apps and controller to provide additional documentation
/*param options*/
validator<T>?: (value: T) => boolean
can still be any
but can also be typed
It should be possible to add multiple route decorators for a route.
example:
@Post()
@Put()
public create(/* ... */): MyObject {
/* ... */
}
const -> UPPER_SNAKE_CASE
validator functions -> camelCase
Should we enable giuseppe to support websocket (socket.io?) connections as well?
We could implement it like a SocketRoute
(with the corresponding helpers SocketGet
etc)
Definitely needs more investigating into the topic, but would be a cool feature.
Add a console.warn
that notifies the user when the @Body
param decorator is used but no body-parser
package is found. In the future maybe this warning should be configurable, since body parsing can be made on it's own.
Or maybe add own body parser to giuseppe.
Same procedure applies when @Cookie
#23 is implemented
It would be nice if we could introduce some kind of versioning for same routes e.g. @Get(':id', { version: '1.4.2' })
and @Get(':id', { version: '2.0.0' })
via header.
If a promise is returned to the response function and no value is provided (i.e. Promise<void>
) we should return a 204.
https://github.com/smartive/giuseppe/blob/master/core/DefaultRouteHandler.ts#L113
since it's > node 4.0, es6 is supported.
async await notation would create a cleaner code base in the controllers
add possibility to ignore the previous route segments (i.e. from base url or controller base url)
possible on:
with special character ~
Hey, great library.
I was wondering if its possible to pass in custom middleware on a route or is it planned ?
or even better, protecting routes using security decorators ?
to deliver cookies into a route function
In order to find the repository in the documentation it would be nice to add a For me on Github ribbon.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.