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-model-factory

v1.2.4

Published

A Model Factory for Parse-server

Downloads

11

Readme

Parse Model Factory

NPM version Build Status Downloads

Intro

Parse Model Factory is an addon to parse-server. It provides a lot of basic queries so you can centralize all of your queries in one place. This addon is amazing when you don't want query.find() all over your project. You can have clean models with just a few lines of code:

const ModelFactory = require('parse-model-factory');
const MyModel = ModelFactory.generate('MyModel');
MyModel.theQueryYouHave1000times = function() {
    const query = this._query();
    // all of your logic
    return this._find(query, ['include1', 'include2'], 200);
}
module.exports = MyModel;

As you can see, we get the query from the model factory and we call _find with our complex query, an array of includes and the limit.

No more query.include().include().include() :heart:

Getting Started

Running model factory

Locally

$ npm install parse-model-factory

Creating your first model

The only thing you should do is requiring the module and call the generate function

const ModelFactory = require('parse-model-factory');

const modelProperties = {
    defaultIncludes: ['prop1', 'prop2']
};

const objectProperties = {
    toStringCustom: function() {
 	     const prop = this.get('prop');
 	     return `Your prop is ${prop}`;
    }
};

const MyModel = ModelFactory.generate('MyModel', modelProperties, objectProperties);

Now you should be able to do:

const query = MyModel._query();
query.doesNotExist('property');

MyModel._find(query, MyModel.defaultIncludes, 10)
    .then(result => result.map(obj => console.log(obj.toStringCustom())))
    .catch(error => console.log(error));

Object Methods index

  • object.customFetch() -> Will fetch the object with the master key
  • object.saveMasterKey() -> Will save the object with the master key
  • object.destroyMasterKey() -> Will destroy the object with the master key
  • object.setAcl(force = false, func, ...args)
    • force : if false will set the acl only when the object is new

    • func : method you want to set public | private | read | write | user

const object = new TestObject();
object.setAcl(false, 'public', true, false);
// == setPublicReadAccess(true) && setPublicWriteAccess(false)

object.setAcl(false, 'private', [user], [user]);
// == setReadAccess(user) && setWriteAccess(user)

object.setAcl(false, 'read', user1, user2, ...);
// == setReadAccess(user1) && setReadAccess(user2) && setPublicWriteAccess(false)

object.setAcl(false, 'write', user1, user2, ...);
// == setWriteAccess(user1) && setWriteAccess(user2) && setPublicReadAccess(true)

object.setAcl(false, 'user', user);
// == setReadAccess(user) && setWriteAccess(user)

Queries Methods index

  • Model._query()

Methods with master key

  • Model._find(query, includes = [], limit = 5000, skip = 0)
  • Model._get(query, objectId, includes = [])
  • Model._each(query, includes = [], callback)
  • Model._count(query)
  • Model._first(query, includes = [])
  • Model.save(object, params = null)
  • Model.saveAll(objects)
  • Model.destroy(object)
  • Model.destroyAll(objects)

Methods without master key

  • Model._findRegular(query, includes = [], limit = 5000, skip = 0, option = {})
  • Model._getRegular(query, objectId, includes = [], option = {})
  • Model._countRegular(query, option = {})
  • Model._firstRegular(query, includes = [], option = {})
const query = MyModel._query();
query.doesNotExist('property');

const session = { sessionToken: req.user.getSessionToken() };

const result = await MyModel._findRegular(query, MyModel.defaultIncludes, 10, 10, session);