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

@clocklimited/crud-service

v2.0.0

Published

Create a crud service by combining schemata and save

Downloads

25

Readme

crud-service

CircleCI

NPM

Simple crud service for object definition, validation, basic persistence and collection.

Installation

npm install @clocklimited/crud-service

Usage

const createCrudService = require('@clocklimited/crud-service')
const save = require('save')
const schema = require('./schema')
const service = createCrudService('things', save('thing'), schema())

// service now has some slightly inflated CRUD functionality:
// .create() .read() .update() .partialUpdate()
// .delete() .deleteMany() .find() .count()

API

var service = new CrudService(String: propertyName, Save: collection, Schemata: schema, Object, options)

Create a new crud service that stores entites in the provided collection. This should be a save instance with your preferred engine. A schemata schema is required for validation

service has the following CRUD-y methods:

service.create(Object: obj, Object: options, Function: cb)

service.read(String: objId, Function: cb)

service.update(Object: obj, Object: options, Function: cb)

service.partialUpdate(Object: obj, Object: options, Function: cb)

service.delete(String: objId, Function: cb)

service.deleteMany(Object: query, Function: cb)

service.find(Object: query, Object: options, Function: cb)

All options arguments are optional.

Omitting cb when calling service.find() will return a stream.

service also has the following method:

service.pre(String: hook, Function: processor)

This facilitates a pipeline for object manipulation before certain operations. pre() can be called multiple times for the same hook and the processor functions will be queued up. A processor function has the signature function (entity, cb) {}, and should callback with cb(err, entity).

A simple example is to maintain a lastUpdated property on service objects:

const setUpdateTime = (entity, cb) => {
  entity.lastUpdated = new Date()
  cb(null, entity)
}

service.pre('update', setUpdateTime)
service.pre('partialUpdate', setUpdateTime)

The available pre hooks are:

  • create - after validation, just before persistence
  • createValidate - before validation
  • update - after validation, just before persistence
  • updateValidate - before validation
  • partialUpdate - after validation, just before persistence
  • partialValidate - before validation
  • delete - before deletion

Credits

Paul Serby follow me on twitter @serby

Clock Limited follow us on twitter @clock

License

Licensed under the ISC