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

parse-cloud-class

v1.0.0

Published

A new way to define Parse.Cloud events for your classes

Downloads

4

Readme

Parse Cloud Class

A new way to define Parse.Cloud events for your classes (DB tables). With this module you can easily:

  • Define minimum values for keys on your classes
  • Define default values
  • Define required keys
  • Use addons to easily extend the funcionality of your app
  • Create new addons and share them with the community
  • Customize the default behaviour to your own needs

This module is meant to be used with Parse and Parse Server

Installation

> npm install parse-cloud-class

Typescript: This module comes bundled with Intellisense :)

Basic Usage

/*
* This is the main cloud file for Parse
* cloud/main.js
*/

// with normal ES5
const ParseCloudClass = require('parse-cloud-class').ParseCloudClass;

// with typescript or ES6
import { ParseCloudClass } from 'parse-cloud-class';

const myConfig = new ParseCloudClass({
  // new items will not be created if they have no 'name' set
  requiredKeys: ['name']
  defaultValues: {
    // all new items will have active: true
    active: true,
    // by default, timesShared will be 0
    timesShared: 0,
  },
  minimumValues: {
    // timesShared cannot go below 0
    timesShared: 0,
  }
});

// Configure your class to use the configuration
ParseCloudClass.configureClass(Parse, 'MyClass', myConfig);

When you configure your classes to work with ParseCloudClass, they will be attached the following events

  • beforeFind
  • beforeSave
  • beforeDelete
  • afterSave
  • afterDelete

By default, the only event that is going to do something is the beforeSave, that is going to check the minimumValues, defaultValues and requiredKeys

Extending ParseCloudClass

You can easily extend ParseCloudClass in order to define your custom behaviours. In this case, you must have into account the following two extra methods of a ParseCloudClass:

  • processBeforeSave: Here you would define your custom behaviour for beforeSave
  • processBeforeDelete: Here you would define your custom behaviour for beforeDelete
// myCustomFile.js
import { ParseCloudClass } from 'parse-cloud-class';

export class MyCustomClass extends ParseCloudClass {
  /*
  * Here you can define your custom minimumValues, 
  * defaultValues and requiredKeys
  */
  requiredKeys = ['title']

  /**
  * @param req {Parse.Cloud.BeforeSaveRequest}
  */
  async processBeforeSave(req) {
    // Trigger the addons to determine if the object can be saved
    for (const addon of this.addons) {
      req.object = await addon.processBeforeSave(req);          
    }

    // write your own code here
    ....

    // make sure to return req.object
    return req.object;
  }
}

You can change the implementation of any method to your needs, but please, trigger the addon functions if you expect to have addon functionalities.

Using addons

To use an addon, you would first import it, and then configure your class to use that addon. Example:

// with typescript or ES6
import { ParseCloudClass } from 'parse-cloud-class';
import { SomeAddon } from 'some-addon-module';

const myConfig = new ParseCloudClass();

// use the addon
myConfig.useAddon(SomeAddon);

// you can use any number of addons
myConfig.useAddon(SomeOtherAddon);

// Configure your class to use the configuration
ParseCloudClass.configureClass(Parse, 'MyClass', myConfig);

Take into account that addons are executed in the order in which they were added.

Creating addons

Addons can be created by extending ParseCloudClass and defining new behaviours on:

  • beforeFind
  • beforeSave
  • beforeDelete
  • afterSave
  • afterDelete
  • processBeforeSave
  • processBeforeDelete

Credits

Developed by Juan Camilo Guarín Peñaranda,
Otherwise SAS, Colombia
2017

License

MIT.