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

@smart-api/mongoose

v1.0.12

Published

"# mongoose-smart-api: with auth/log/fixtures/postman"

Downloads

206

Readme

mongoose-smart-api

Description

main features

  • No code: is a library that allows you to create a RESTful API without any coding.
  • Simple Configuration: you can create a RESTful API with a simple configuration in one yaml file.
  • Security: you can secure your ressources with a simple configuration.
  • For each ressource, you have the next operations available:
    • creating:
      • create: create a new one document
      • createMany: create many documents with one request
      • import: create many documents from a file
    • reading:
      • getById: find a document by id
      • getByIds: find many documents by ids
      • getByQuery: find many documents by query
      • getAll: find all documents
      • export: for getByIds, getByQuery and getAll, you can export the result to a file
    • updating:
      • updateById: update a document by id
      • updateByIds: update many documents by ids
      • updateByQuery: update many documents by query
      • updateAll: update all documents
    • deleting:
      • deleteById: delete a document by id
      • deleteByIds: delete many documents by ids
      • deleteByQuery: delete many documents by query
      • deleteAll: delete all documents

Usage

Installation

npm install @smart-api/mongoose

use in index.js

const getSmartApi = require('@smart-api/mongoose');
const express = require('express');

const myApi = getSmartApi({
    configPath: 'path/to/configDir',
    apiName: 'my-api',
})

myApi.listen(3000, () => {
    console.log('Server is running on port 3000');
});

Configuration: configDir/smart-api.yaml

  • in the configDir, you should create a smart-api.yaml file with the next structure:

    • ressourceX: main key is the name of the ressource, and should have the schema and the permissions.
      • the schema contains the next keys:
        • timestamps: if true, the library will add createdAt and updatedAt fields and manage them.
        • fields: the fields of the ressource can have simple mongoose configuration.
      • the permissions follow the next structure:
        • default: the default permissions for all actions and for all users roles.
        • actionX: the permissions for the actionX;
          • default: the default permissions for the actionX and for all users roles.
          • roleX: the permissions for the actionX and for the roleX. override the default permissions for the actionX and for the ressourceX
  • the permissions controles are:

    • enabled: if false the action is disabled.
    • userFilter: it's used on the current user to check if the user can access the action.
    • queryFilter: it's used while fetching data. help as pre-filtering the data.
    • fieldsPopulate: it's used while fetching data. help as pre-populating the fields. for related ressources.
    • ressourceFilter: it's used on the fetched documents to check if the user can access them.
    • fieldsFilter: it's used on the fetched documents to filter the fields that the user can update/read.
  • Example:

users:
    schema:
        timestamps: true
        fields:
            fullname:
                type: String
            username:
                type: String
                required: true
            role:
                type: String
                required: true
                enum: "'user', 'admin'"
                default: 'user'
            password:
                type: String
                required: true
    permissions:
        default:
            enabled: true

comments:
    schema:
        timestamps: true
        fields:
            content:
                type: String
                required: true
            author:
                type: objectid
                required: true
                ref: users
            post:
                type: objectid
                required: true
                ref: posts
    permissions:
        default:
            enabled: true
            fieldsPopulate:
                - path: author
                  select: fullname
                - path: post
                  select: title

posts:
    schema:
        timestamps: true
        fields:
            title:
                type: String
                required: true
            content:
                type: String
                required: true
            author:
                type: objectid
                required: true
                ref: users
                fromUser: _id
    permissions:
        default:
            enabled: true
            userFilter:
                - field: isActive
                  value: true
                - field: role
                  value: us
                  operator: regex
            fieldsPopulate:
                - path: author
                  select: fullname
            ressourceFilter:
                - field: author.fullname
                  value: smapiuser@fullname
                  operator: regex
            fieldsFilter:
                denied:
                    - author
        updateById:
            default:
                fieldsFilter:
                    denied:
                        - title