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

foxify-restify-odin

v1.8.1

Published

Easily restify odin databases

Downloads

7

Readme

foxify-restify-odin

Easily restify odin databases

Npm Version Node Version TypeScript Version Package Quality Npm Total Downloads Npm Monthly Downloads Open Issues Closed Issues Known Vulnerabilities Dependencies Status Pull Requests License Build Status Coverage Status Github Stars Github Forks

Table on Contents

Getting Started

Prerequisites

Installation

npm i -s foxify-restify-odin

Usage

const Foxify = require('foxify');
const restify = require('foxify-restify-odin');
const User = require('./models/User');

let app = new Foxify();

app.get('/users', restify(User), async (req, res) => {
  res.json({
    users: await req.fro.query.get(),
    total_users: await req.fro.counter.count(),
  });
});

app.start();

Documentation

type Operator = "lt" | "lte" | "eq" | "ne" | "gte" | "gt" |
  "exists" | "in" | "nin" | "bet" | "nbe" | "like" | "nlike";

interface FilterObject {
  field: string;
  operator: Operator;
  value: string | number | boolean | any[] | object | Date;
}

interface Filter {
  and?: Array<FilterObject | Filter>;
  or?: Array<FilterObject | Filter>;
  has?: string | { relation: string, filter: Filter | FilterObject };
}

interface Query {
  filter?: Filter | FilterObject;
  include?: string[];
  sort?: string[];
  skip?: number;
  limit?: number;
}

interface RouteOptions {
  pre?: Foxify.Handler | Foxify.Handler[];
  post?: Foxify.Handler | Foxify.Handler[];
}

interface RoutesOptions {
  index: RouteOptions & { lean?: boolean; } | false;
  count: RouteOptions | false;
  store: RouteOptions | false;
  show: RouteOptions | false;
  update: RouteOptions | false;
  delete: RouteOptions | false;
}

interface Options {
  name: string;
  prefix: string;
  qs: QSParseOptions;
  defaults: Query;
  pre: Foxify.Handler | Foxify.Handler[];
  routes: Partial<RoutesOptions>;
}

restify(model: typeof Odin, options: Partial<restify.Options> = {}): Router;

This module's middleware parses url query string and executes a query on the given model accordingly and passes the query to you (since you might need to do some modifications on the query, too)

It also passes a counter which is exactly like query but without applying skip, limit, sort just because you might want to send a total count in your response as well

Lastly it passes the a decoded key in req.fro which is the parsed query string that is used in the middleware

Stringify all query params using qs default options

All the possible query modifiers are explained as a single modification but they all can be used together

/users?sort%5B0%5D=age

Filters

qs.stringify({
  filter: {
    field: "username",
    operator: "eq",
    value: "ardalanamini",
  }
})
qs.stringify({
  filter: {
    or: [
      {
        field: "username",
        operator: "eq",
        value: "ardalanamini",
      },
      {
        and: [
          {
            field: "age",
            operator: "gte",
            value: 18,
          },
          {
            field: "email",
            operator: "exists",
            value: true,
          },
        ],
      },
    ],
  },
})

filter can be a single filter object or and/or of Array<filter object>

possible operators:

lt | lte | eq | ne | gte | gt | exists | in | nin | bet | nbe | like | nlike

include

qs.stringify({
  include: [
    "relation1",
    "relation2.subRelation1.subRelation2",
  ]
})

sort

qs.stringify({
  sort: [
    "field1", // same as "+field1"
    "-field2",
    "+field3",
  ]
})

skip

qs.stringify({
  skip: 100,
})

limit

qs.stringify({
  limit: 10,
})

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details

Support

If my work helps you, please consider

Become A Patron

Buy Me A Coffee