aom - it is meta-framework made of typescript-decorators, which allows to fast and comfortable
create safe api-services, using the principle of accumulation data layers, enriched with abstractions.
npm i -s aom
or
yarn add aom
To check out the documentation, visit aom.js.org (en and ru available)
The main idea sounds like: "don't duplicate the code, link the code". aom allows to use data
proccessing, made to cover most cases you need. At the same time aom do not limit the developer
in frames of the only framework, but gives the ability to use third-party libraries and packages.
aom is not a "thing in itself "- a framework that operates exclusively on its own codebase and only
works in its own environment. Its important feature is the ability to combine with the "classic" code
on koa, which makes it useful when migrating functionality already existing projects.
aom does not run code in an isolated environment, but generates structures that are compatible with
popular libraries: koa-router, koa-session and others, which allows, if necessary,
keep the existing code-stack, and comfortably extend it in the aom +typescript methodology.
Code sample
@Bridge("/auth",Auth)
@Bridge("/shop",Shop)
@Bridge("/account",Account)
@Controller()classRoot{
@Get()staticIndex(){returnmodels.Settings.findOne({enabled: true});}}// ...
@Controller()classAuth{user: models.Users;login: models.UserLogins;token: models.AuthTokens;
@Middleware()staticasyncRequired(
@Headers("authorization")token,
@This()_this: Auth,
@Next()next,
@Err()err){constauthToken=awaitmodels.AuthTokens.checkToken(token);if(authData){_this.token=authToken;_this.user=awaitmodels.Users.findById(authToken.userId);_this.login=awaitmodels.UserLogins.findById(authToken.loginId);returnnext();}else{returnerr("access denied",403);}}
@Post()staticasyncLogin(@Body(){ login, password }, @Err()err){constauthLogin=awaitmodels.UserLogins.authLogin(login,password);if(checkLogin){returnmodels.AuthTokens.generateToken(authLogin);}else{returnerr("wrong login",403);}}}// ...
@Controller()classShop{
@Get()staticIndex(@Query()query){returnmodels.Products.find({ ...query});}
@Get("/categories")staticCategories(@Query()query){returnmodels.Categories.find({ ...query});}
@Get("/brands")staticBrands(@Query()query){returnmodels.Brands.find({ ...query});}
@Post("/add_to_cart")
@Use(Auth.Required)staticAddToCart(@Body(){ productId, quantity }, @StateMap(Auth){ user }: Auth){constaddUserCart=awaituser.addProductToCart(productId,quantity);returnuser.getProductsCart();}}// ...
@Controller()
@Use(Auth.Required)classAccount{
@Get()staticasyncIndex(@StateMap(Auth){ user, login }: Auth){constorders=awaituser.getOrders();return{ user, login, orders };}
@Post("/logout")staticasyncLogout(@StateMap(Auth){ token }: Auth){awaittoken.remove();return{message: "success logout"};}}Use Github issues to ask your question or report about problem.
- Author: Grigory Kholstinnikov
- Email: mail@scarych.ru
AOM is MIT licensed.
aom is in open beta and will be expanded with new features. Errors are not excluded, as well
as replacement and renaming of a number of functions and decorators.