Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

kaleabmelkie/meseret-utils

Repository files navigation

meseret-utils

A collection of handy utility functions and middleware compatible with meseret.

meseret-utils npm downloads npm code style: prettier

Getting Started

To install, inside a meseret project:

yarn add meseret-utils

# or, using npm:
# npm i meseret-utils --save

Then, we'll need to run the configuration/setup function (called configureMeseretUtils) at our app's entry like:

// maybe, your index.ts

import { ServerApp } from 'meseret'
import { configureMeseretUtils } from 'meseret-utils'

import { serverAppConfig } from './path/to/your/server-app-config'

export const serverApp = new ServerApp(serverAppConfig)

configureMeseretUtils({
  serverApp
})

serverApp.start().catch(console.error)

Utils

Helper Functions
  • C.R.U.D.: a collection of functions (add, get, list, search, edit and remove) that perform read and write operations on MongoDB collections (as modelled by mongoose); these functions include extensive error handling, and highly customizable querying and action plugging.

  • email: an easy way to send an email.

  • Grid: a nice abstraction of GridFS, the large-file-size-capable storage system inside MongoDB.

  • KoaController: a controller super-class that works hand-in-hand with our handle middleware.

  • KoaError: an extension of Error (with support for error code and HTTP status) that is compatible with koa and our handle middleware.

  • password: a pair of functions that assist in an account's password reset process.

  • PhotoGrid: coming soon, in the next few feature releases.

  • transact: an abstraction to quickly support MongoDB's session-based multi-document ACID-compatible transactions; this requires MongoDB 4+.

Koa Middleware
  • handle: a koa middleware that implicitly calls our transact function on our koa-controller methods and nicely handles our koa-error throws.

  • sslRedirect: a koa middleware that redirects all HTTP requests to HTTPS in "production" environments (unless other environments are passed to it).

Mongoose Models
  • KeyModel: a mongoose data model used in our password reset functions to store unique keys (tokens).
Types
  • ObjectId: a shortcut for the type mongoose.Schema.Types.ObjectId | string.

License

Proudly, made with ♥ in Addis Ababa.

MIT License © 2019 Kaleab S. Melkie

About

A collection of handy utility functions and middleware compatible with meseret.

Resources

License

Stars

Watchers

Forks

Packages

No packages published