parsimonious (master) doxdox documentation

Utilities for Parse Server cloud code and JS SDK

# setParse(parse)

Set the instance of the Parse JS SDK to be used by all methods:

Parameters

Name Types Description
parse object instance of the Parse JS SDK

# _toArray(thing, type)

Return thing if array, string[] if string, otherwise array with thing as only item, even if undefined.

Parameters

Name Types Description
thing *
type string= If set, only include values of this type in resulting array.

# constrainQuery(query, constraints)

Calls one or more query constraint methods on a query with arbitrary number of arguments for each method. This method is useful when, for example, building a complex query configuration to pass to another function that may modify the configuration further and then generate the actual query. Mutates the 'query' parameter because it calls constraint methods on it. Returns the query, so you can chain this call.

Parameters

Name Types Description
query Parse.Query The query on which to call the constraint methods
constraints object Plain object containing query constraint methods as keys and arguments as values

# copyPFObjectAttributes(from, to, attributeNames)

Copy a set of attributes from one instance of Parse.Object to another. Mutates target Parse.Object.

Parameters

Name Types Description
from Parse.Object
to Parse.Object Is mutated.
attributeNames (string string[])

# fetchIfNeeded(thing, opts)

Given a value thing, return a promise that resolves to - thing if thing is a clean Parse.Object, - fetched Parse.Object if thing is a dirty Parse.Object, - fetched Parse.Object if thing is a pointer; - thing if otherwise

Parameters

Name Types Description
thing *
opts object= A Backbone-style options object for Parse subclass methods that read/write to database. (See Parse.Query.find).

Returns

Parse.Promise

# getId(thing)

Attempt to return the ID of thing if it's a Parse.Object or pointer. If thing is a string, just return it. Otherwise, return undefined.

Parameters

Name Types Description
thing *

# getJoinTableName(from, to)

Return the name of a table used to join two Parse.Object classes in a many-to-many relationship.

Parameters

Name Types Description
from string First class name
to string Second class name

# getUserById(id, opts)

Return Parse.User instance from user id

Parameters

Name Types Description
id string
opts object= A Backbone-style options object for Parse subclass methods that read/write to database. (See Parse.Query.find).

# getUserRoles(user, opts)

Return array of names of user's direct roles, or empty array. Requires that the Roles class has appropriate read permissions.

Parameters

Name Types Description
user Parse.User
opts object= A Backbone-style options object for Parse subclass methods that read/write to database. (See Parse.Query.find).

Returns

Parse.Promise

# isUser(thing)

Return true if thing is an instance of Parse.User.

Parameters

Name Types Description
thing *

# joinWithTable(object1, object2, metadata, opts)

Join two parse objects in a many-to-many relationship by adding a document to a third join table. Like Parse.Relation.add except that it allows you to add metadata to describe the relationship. Creates join tables which are named with the class names separated with the numeral 2; e.g.: Student2Course. (For backwards-compatibility with v4.1.0, this method may still be called with the 3 parameters 'classes', 'metadata', and 'opts', where 'classes' is a plain object whose two keys are the classes to join, and whose values are the Parse.Object instances.)

Parameters

Name Types Description
object1 Parse.Object Parse object or pointer
object2 Parse.Object Parse object or pointer
metadata object= - optional key/value pairs to set on the new document to describe relationship.
opts object= A Backbone-style options object for Parse subclass methods that read/write to database. (See Parse.Query.find).

# keysAreDirty(parseObj, keys)

Return true if any of the passed keys are dirty in parseObj

Parameters

Name Types Description
parseObj Parse.Object
keys (string string[])

# objGetDeep(parseObj, path)

Get the value of a key from a Parse object and return the value of a nested key within it.

Parameters

Name Types Description
parseObj Parse.Object
path string Dot-notation path whose first segment is the column name.

# objPick(parseObj, keys)

Get some columns from a Parse object and return them in a plain object. If keys is not an array or comma-separated string, return undefined.

Parameters

Name Types Description
parseObj Parse.Object
keys (string string[])

# objSetMulti(parseObj, dataObj, doMerge)

Set some columns on a Parse object. Mutates the Parse object.

Parameters

Name Types Description
parseObj Parse.Object
dataObj object
doMerge boolean= If true, each column value is shallow-merged with existing value

# pfObjectMatch(thing1, thing2)

Return true if values both represent the same Parse.Object instance (same class and id) even if one is a pointer and the other is a Parse.Object instance.

Parameters

Name Types Description
thing1 Parse.Object object
thing2 Parse.Object object

# Role(user, roles, opts)

Check if a user has a role, or any or all of multiple roles, return a promise resolving to true or false.

Parameters

Name Types Description
user Parse.User
roles string object
opts object= A Backbone-style options object for Parse subclass methods that read/write to database. (See Parse.Query.find).

Returns

Parse.Promise

# s(className)

Short-hand for Parse.Object.extend(className) or a special class like Parse.User

Parameters

Name Types Description
className string

# s(aClass, constraints)

Returns a new Parse.Query instance from a Parse Object class name.

Parameters

Name Types Description
aClass (Parse.Object string)
constraints object= Plain object whose keys may be any Parse.Query constraint methods and whose values are arrays of arguments for those methods.

# s(aClass, id, opts)

Return a Parse.Object instance from className and id.

Parameters

Name Types Description
aClass string object
id string
opts object= A Backbone-style options object for Parse subclass methods that read/write to database. (See Parse.Query.find).

# s(thing, ofClass)

Return true if thing is a Parse.Object, or sub-class of Parse.Object (like Parse.User or Parse.MyCustomClass)

Parameters

Name Types Description
thing *
ofClass string= Optionally check if it's of a specific ParseObjectSubclass

# s(thing, ofClass)

Return true if thing is array of Parse.Object

Parameters

Name Types Description
thing *
ofClass string= Optionally check if it's of a specific ParseObjectSubclass

# s(thing, ofClass)

Return true of thing is a valid pointer to a Parse.Object, regardless of whether the Parse.Object exists.

Parameters

Name Types Description
thing *
ofClass string= Optionally check if it's of a specific ParseObjectSubclass

# s(thing)

Returns the corresponding special Parse class (like 'User') if passed the name of one; otherwise, returns the value unchanged.

Parameters

Name Types Description
thing string

# ses(classes, constraints)

Return a query on a many-to-many join table created by Parsimonious.joinWithTable.

Parameters

Name Types Description
classes object Must contain two keys corresponding to existing classes. At least one key's value must be a valid parse object. If the other key's value is not a valid parse object, the query retrieves all objects of the 2nd key's class that are joined to the object of the 1st class. Same for vice-versa. If both values are valid parse objects, then the query should return zero or one row from the join table.
constraints object= (Options for Parsimonious.newQuery})

# setParse(parse)

Set the instance of the Parse JS SDK to be used by all methods:

Parameters

Name Types Description
parse object instance of the Parse JS SDK

# sInst(className, attributes, options)

Return instance of Parse.Object class.

Parameters

Name Types Description
className string Parse.Object subclass name.
attributes object= Properties to set on new object.
options object= Options to use when creating object.

# sName(className, objectId)

Return a pointer to a Parse.Object.

Parameters

Name Types Description
className string
objectId string

# sName(thing, ofClass)

Return true if thing is a Parse.Object or pointer

Parameters

Name Types Description
thing *
ofClass string= Optionally check if it's of a specific ParseObjectSubclass

# sName(thing, className, opts)

Resolves thing to a Parse.Object, or attempts to retrieve from db if a pointer. Resolves as undefined otherwise.

Parameters

Name Types Description
thing (Parse.Object object
className string= If set, and first param is a Parse.Object, resolves to the Parse.Object only if it is of this class.
opts object= A Backbone-style options object for Parse subclass methods that read/write to database. (See Parse.Query.find).

# sName(thing)

Returns valid class name when passed either a subclass of Parse.Object or any string. Removes the underscore if it is one of the special classes with a leading underscore. Returns undefined if anything else.

Parameters

Name Types Description
thing object string

Returns

string

# sName(className)

If className represents one of the special classes like 'User,' return prefixed with an underscore.

Parameters

Name Types Description
className

# sortPFObjectsByKey(objs, key)

Sort an array of Parse objects by key (column name) Mutates array.

Parameters

Name Types Description
objs object[]
key string

# sVars()

Converts a variable number of arguments into 4 variables used by the joinWithTable, unJoinWithTable, getJoinQuery methods.

# toJsn(thing, deep)

Return a json representation of a Parse.Object, or of plain object that may contain Parse.Object instances, optionally recursively.

Parameters

Name Types Description
thing * Value to create json from.
deep boolean= If true, recursively converts all Parse.Objects and sub-classes of Parse.Objects contained in any plain objects found or created during recursion.

# unJoinWithTable(object1, object2, opts)

Unjoin two parse objects previously joined by Parsimonious.joinWithTable If can't unjoin objects, returned promise resolves to undefined. (For backwards-compatibility with v4.1.0, this method may still be called with the 2 parameters 'classes' and 'opts', where 'classes' is a plain object whose two keys are the classes to join, and whose values are the Parse.Object instances.)

Parameters

Name Types Description
object1 Parse.Object Parse object or pointer
object2 Parse.Object Parse object or pointer
opts object= A Backbone-style options object for Parse subclass methods that read/write to database. (See Parse.Query.find).