Introduction#
While browsing the documentation, if you feel like an example is missing, feel free to check the
tests
folder to see the actual usage of the feature you
were reading about.
Motivation#
Basically this is a Node / Typescript route handler tightly coupled* with TypeORM entities.
I wanted to get rid of writing the same boring controllers again & again for each entities and I could not find a NodeJS project that would fit my needs : being simple enough not to require any configuration (or controllers), yet easily customizable when needed.
Main Features#
- Instant CRUD with a simple
@EntityRoute
decorator - Granular control over which properties are exposed (with
@Groups
) in which route scope Subresources
: Entity properties that have dedicated endpoints, can be nested- Independant service components (Database
Reader
,Persister
,RelationManager
etc...) - Built-in powerful
filters
for lists (Search
/Pagination
) that should fit well for 99% use cases - Custom filters if you find yourself in the 1%
Hooks
to alter a request handling at any point in the process- Built-in validation using class-validator/entity-validator decorators on your entities
- Inferred entity route mappings (with generated endpoints to get the summary of an entity exposed properties for each contexts)
- Computed properties: methods, possibly async, exposed as properties
@MaxDepth
decorator for entity/properties- Optimized SQL queries with only exposed properties selected
- Soft delete/restoration supported (also for Subresources)
- Standardized REST responses
Perks#
- 0 config required
- Type-safe API
- Almost complete code coverage (95%+)
- Out-of-the-box support for Koa/Express (therefore Next, Nuxt) integrations and compatible and any other middleware-based framework using adapters
- Everything (types included) is exported so you can use it your own way
Future#
entity-routes
is tightly coupled with TypeORM for now. In the long-term I'd like to make it an ORM-independant
library. Something like supporting ORM through different packages, like @entity-routes/typeorm
,
@entity-routes/mikro-orm
, etc.
Same could be done for routers (@entity-routes/koa
, @entity-routes/express
), rather than use the current
ContextAdapter
.
Inspiration#
Inspired by an internal project made at ACSEO with ApiPlatform (Symfony/PHP)