Skip to content

You may want to check this out (parse-server-addon-cloud-class) #5088

Closed

Description

@jcguarinpenaranda

Hello!

First of all excuse me as I didn't find another way to share this, but I consider it may be useful for your parse-server applications.

I created an addon called parse-server-addon-cloud-class, available now on npm, which helps you organize and extend your parse-server's Cloud Code. Please check the repo here: https://github.com/owsas/parse-cloud-class

With this module you can easily:

  • Define minimum values for keys on your classes
  • Define maximum values
  • Define default values
  • Define required keys
  • Define immutable keys (only editable with the master key)
  • 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

Classes

It helps you organize your code for each of your Parse classes, like so:

// GamePoint.js
class GamePoint extends ParseCloudClass {
  requiredKeys = ['player']; // All points must have a player
  minimumValues = {
    credits: 10, // minimum ammount of 10 credits can be earned
  }
  maximumValues = {
    credits: 100, // limit the ammount to maximum a 100 credits 
  }
  defaultValues = {
    credits: 20, // by default, give 20 credits
  }
  
  async afterSave(request) {
    const obj = await super.afterSave(request);
    
    // log something to Google Analytics ...

    return obj;
  }
}

module.exports = GamePoint;

Using

After writing your classes that extend ParseCloudClass, you can import and use them in your Cloud Code's main.js file, like this:

const { ParseCloudClass } = require('parse-server-addon-cloud-class');
const GamePoint = require('./GamePoint');

const gamePoint = new GamePoint();

ParseCloudClass.configureClass(Parse, 'GamePoint', gamePoint);

This way, every GamePoint element will run your custom code using ParseCloudClass.

Addons

You can create your own addons or use community created ones to extend the functionality for your classes. This may open your parse-server for new integrations. For example, using Google Analytics on afterSave, logging errors to an error tracking service, replicating your data to any database or running your custom business logic.

// main.js

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

// import a community created addon
import { SomeAddon } from 'some-addon-module';

// Create the instance
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);

If you like it, give parse-server-addon-cloud-class a star 😄

Activity

  1. flovilmart commented on Sep 27, 2018

    @flovilmart
    Contributor

    Closing as it is not an issue.

  2. jcguarinpenaranda commented on Sep 27, 2018

    @jcguarinpenaranda
    ContributorAuthor

    @flovilmart Which would be the best way to share things with the community?

  3. flovilmart commented on Sep 27, 2018

    @flovilmart
    Contributor

    I don’t know but not this one. We use github issues for tracking issues, as mentioned in all issues templates.

    There is a gitter where some users discuss, as exposed in the README, then blog, articles, SEO are other ways to reach ou to people. But this is not one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions