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

agradon

v1.0.0-alpha.6

Published

Express Middleware for automatic generation of the models, controllers, and routes with MongoDB.

Downloads

4

Readme

Agradon

Coverage Status

Extensible Express middleware for automatic generation of the models, controllers, and routes with MongoDB.

Getting started

How to install

Install the package

npm install agradon

Initialize Agradon

Create a mongoose connection import agradon in your app index.

const express = require('express');
const agradon = require('agradon');
const app = express();

async function build() {
  await agradon.init({ app });
  app.listen(process.env.PORT, () => console.log(`Server is listening on port ${process.env.PORT}`));
}

build();

Agradon also support plugins for increase functionality. We made plugins class based to extend their capabilities in the future. Plugin Example:

class CustomPlugin extends AgradonPlugin {
  load (router, mongoose, schemas) {
  // Code live here
  ...
  }
}


const config = {
  app,
  plugins: [new CustomPlugin()]
}

Entities

Agrandon entities are composed by three different files. Entities by default are located in entities folder, Example: entities/<entitity-name>/schema.yml You can also change this setting path in ENTITIES_PATH environment variable.

-schema.json (Required) -model.js (Optional) -controller.js (Optional)

schema.json *

Schemas now are json-schema based.

model.js

Model file used to set virtual, hooks, etc. You also can register middlewares to default routes or to be used in controller file.

module.exports.schema = schema => {
  // Code goes here
  return schema;
};

controller.js

Controller file is used to create custom endpoints or add middlewares to the default endpoints.

module.exports = (router, model) => {
  router.get('/', (req, res) => {
    return model.find({}).then(result => {
      res.send(result);
    });
  });
  return router;
};

Authentication Module

Agradon includes a configurable authentication plugin

How to setup

To enable authetication module follow the example bellow. This module is configurable, so you can pass your own strategies to interact with db.

agradon.init({
  app,
  rootPath: '/api',
  plugins: [
    new AuthPlugin()
  ]
});

By default we set /auth/local with a local strategy

Auth Guards

The guards are created to protect the crud routes. guards are set in schema.yml by http method/action in db.

...
_auth:
  get: true
  post: true
  put: true
  delete: true

Routing

Agradon creates the routes based in the entity name.

  • GET: /:collection
  • GET: /:collection/:id
  • POST: /:collection/
  • PUT: /:collection/:id
  • DELETE: /:collection/:id

You can set a prefix as /api in the config object Example:

agradon.init({
  app,
  rootPath: '/api'
});

Query System

Agradon includes a powerful query system for GET requests

  • Match
  • Compare
  • Pick
  • Omit
  • Pagination
  • Limit
  • Populate

Those Matchers are passed as query in get request, example /user?match=name:john

Match

Match filter the results matching key:value in documents. Use: match=key:value

Compare

Compare documents with. Use: compare=key:operator:value In case of multiple matching can be send it as array. Operators:

  • ==
  • >
  • <
  • >=
  • <=
  • !=

Pick

Select which fields you need from each document. Use: pick=field1,field2,field4.field4A or pick=field1&pick=field2&pick=field3 Can be a string separated by comma or an array.

Omit

Omit is the oposite of pick. Use: omit=field1,field2,field4.field4A or omit=field1&omit=field2 Can be a string separated by comma or an array.

Limit

You are able to limit the results. Use: limit=20

Pagination

We also included pagination Use: page=1&perPage=10

Hint: perPage is an alias for limit.

Populate

If you have some experience with MongoDB maybe you know about populate, if not read this. Use: populate=field1(subField1,subField1) Example: populate=user(name,lastname)