npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aom

v1.0.0-beta.46

Published

API Over Models: typescript-decorators meta-framework

Downloads

748

Readme

AOM: API Over Models

Travis (.com) npm Libraries.io dependency status for latest release GitHub

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.

Installation

npm i -s aom

or

yarn add aom

Getting started

To check out the documentation, visit aom.js.org (en and ru available)

Concept

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()
class Root {
  @Get()
  static Index() {
    return models.Settings.findOne({ enabled: true });
  }
}

// ...
@Controller()
class Auth {
  user: models.Users;
  login: models.UserLogins;
  token: models.AuthTokens;

  @Middleware()
  static async Required(
    @Headers("authorization") token,
    @This() _this: Auth,
    @Next() next,
    @Err() err
  ) {
    const authToken = await models.AuthTokens.checkToken(token);
    if (authData) {
      _this.token = authToken;
      _this.user = await models.Users.findById(authToken.userId);
      _this.login = await models.UserLogins.findById(authToken.loginId);
      return next();
    } else {
      return err("access denied", 403);
    }
  }

  @Post()
  static async Login(@Body() { login, password }, @Err() err) {
    const authLogin = await models.UserLogins.authLogin(login, password);
    if (checkLogin) {
      return models.AuthTokens.generateToken(authLogin);
    } else {
      return err("wrong login", 403);
    }
  }
}

// ...
@Controller()
class Shop {
  @Get()
  static Index(@Query() query) {
    return models.Products.find({ ...query });
  }

  @Get("/categories")
  static Categories(@Query() query) {
    return models.Categories.find({ ...query });
  }

  @Get("/brands")
  static Brands(@Query() query) {
    return models.Brands.find({ ...query });
  }

  @Post("/add_to_cart")
  @Use(Auth.Required)
  static AddToCart(@Body() { productId, quantity }, @StateMap(Auth) { user }: Auth) {
    const addUserCart = await user.addProductToCart(productId, quantity);
    return user.getProductsCart();
  }
}

// ...
@Controller()
@Use(Auth.Required)
class Account {
  @Get()
  static async Index(@StateMap(Auth) { user, login }: Auth) {
    const orders = await user.getOrders();
    return { user, login, orders };
  }

  @Post("/logout")
  static async Logout(@StateMap(Auth) { token }: Auth) {
    await token.remove();
    return { message: "success logout" };
  }
}

Issues

Use Github issues to ask your question or report about problem.

Contacts

License

AOM is MIT licensed.

Warning

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.