Saga Documentation 0.9.434-4

Javascript API

This structure explains the exposed and most frequently used JavaScript methods used in runnables and scripts.

Properties

UserProperties

/*
 * Library of static methods to add, find, and count User Properties. Each property has:
 * 
 * {string} name - the name
 * {ObjectId} parent - the parent
 * {object} value - the actual value
 * {date} created_at - creation date 
 * {number} sortable_id - an integer for sorting, each new sortable_id is +1 the latest sortable_id
 * 
 * The ones below are set behind the scenes and most are only relevant for internals such as error propagation and analytics.
 * 
 * {object} source_creator - an object describing who created the project
 * {object} runnable_call - data describing  how long it to took to create object, if an error occurred in a script during the creation, or if a log entry was added
 */ 

const UserProperty = {
 
     /**
    * Adds a new property with the given name, value and user with the given parent_id. 
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the value of the property
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or or global) and no script is triggered.
      * @return {Promise<object>} - the property
    */    
   add = function(name, value, parent_id, options={} ){  }
  
    /**
    * Increments the value of a numeric property. If property doesn't exist it will create it with the given value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the increment amount 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric. 
    */    
   incr = function(name, value, parent_id, options={} ){ } 
   
    /**
    * Multiplies the value of a numeric property. If property doesn't exist it will be set to 0.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  multiplication factor
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric. 
    */    
   mul = function(name, value, parent_id, options={} ){   }    

    /**
    * Adds a value to an array property unless the value is already present, in which case it does nothing to that array. If the property
    * wasn't defined yet it will create the array property with the specified value as its element.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the value to add to the array property 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param` {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   sadd = function(name, value, parent_id, options={} ){ }    


    /**
    * Removes from an existing array property all instances of the given value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the value to remove
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   rem = function(name, value, parent_id, options={} ){  }     

    /**
    * Left push to an array property. If property doesn't exist it will be set to [value]
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array. 
    
    */    
   lpush = function(name, value, parent_id, options={} ){   } 
   

    /**
    * Right push to an array property. If property doesn't exist it will be set to [value]
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   rpush = function(name, value, parent_id, options={} ){  } 

    /**
    * Left pop from array property. If property doesn't exist it will be set to undefined.
    * Returns the new value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {ObjectId} parent_id - the id of the parent    
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array. 

    */    
   lpop = function(name, parent_id, options={} ){  }
   
    /**
    * Left pop from array property. If property doesn't exist it will be set to undefined.
    * Returns the new value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array. 
    */    
    rpop = function(name, parent_id, options={} ){  }   
   
    /**
    * Adds a value to an array property that is treated as a set. If the same value  already exists it won't created a duplicate value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to add 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   sadd = async function (name, value, parent, options={} ) {   }
    /**
    * Removes all entries from the  array property that match the value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to remove 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
    
    rem = async function (name, value, parent, options={} ) {    }    

    /**
    * Set the key value pair in the given property. If property or key doesn't exist it will be set to [value]
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to set 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    set = async function (name, key, value, parent, options ) {  	}	
    /**
    * Unset the key value pair in the given property. 
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object to unset 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */ 
    unset = async function (name, key,  parent, options ) {   }    
    /**
    * Increase the key value pair in the given property. If property or key doesn't exist it will be set to [value]
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to increase by 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric.   
    */     
    hincr = async function (name, key, value, parent, options ) {    }	
    /**
    * Multiply the key value pair in the given property. If property or key doesn't exist it will be set to 0
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  multiplication factor 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric.   
    */  
   hmul = async function (name, key, value, parent, options ) {  }  
    /**
    * Left push to a property array entry. If property or key doesn't exist it will be set to [value]
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */   
    hlpush = async function (name, key, value, parent, options ) {  }
    /**
    * Left push to a property array entry. If property or key doesn't exist it will be set to [value]
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */   
   hrpush = async function (name, key, value, parent, options ) {   }    
    /**
    * Left pop from property array entry. If property doesn't exist it will be set to undefined.
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hlpop = async function (name, key, value, parent, options ) {  }   
    /**
    * Left pop from property array entry. If property doesn't exist it will be set to undefined.
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hrpop = async function (name, key, parent, options ) {  }  
    /**
    * Removes all entries from the  property array entry that match the value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to remove
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hrem = async function (name, key, value, parent, options ) { } 
    /**
    * Adds a value to a property array entry that is treated as a set. If the same value  already exists it won't created a duplicate value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to add 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hsadd = async function (name, key, value, parent, options ) { }     

   

    /**
    * Returns an array of properties that match the given conditions. You can query by name, value, created_at, and parent_id. 
    * @see https://mongoosejs.com/docs/api.html#model_Model.find
    * @async
    * @return {Promise<number>} - the number of properties matching the condition.
    */    
    find = async function(conditions,projection,options){}

    /**
    * Counts number of documents matching filter in a database collection. 
    * https://mongoosejs.com/docs/api.html#model_Model.find
    * @async
    * @return {Promise<array>} - an array of properties
    */ 
    countDocuments = async function(filter){}  
}

Examples

// add a property named "message" with the value "hi user" to the user with the given id
await UserProperty.add("message", "hi user" , id);    

// increments the property 'counter' by 1
await UserProperty.incr("counter", 1 , id);

// left pushes a new entry to the property 'member'
await UserProperty.lpush("member", "id_132313" , id);

// right pops an entry from the property "member"
await UserProperty.rpop("member", id);

// treat array property as set
await  UserProperty.add("name1", [{x:1,y:1},{x:1,y:2},{x:1,y:3}] , id ) ;             
await  UserProperty.sadd("name1", {x:1,y:2}, id ) ; 
//{x:1,y:1},{x:1,y:2},{x:1,y:3}

await  UserProperty.sadd("name1", {x:2,y:2}, id ) ;
//[{x:1,y:1},{x:1,y:2},{x:1,y:3},{x:2,y:2}]

//get the last 25 giphys of all users
const list = await UserProperty.find({name:"giphy"},{},{sort: '-createdAt', limit: 25});

//count all properties of the user with the given id
const count = await UserProperty.countDocuments({parent:id});

BotProperties

/*
 * Library of static methods to add, find, and count Bot Properties. Each property has:
 * 
 * {string} name - the name
 * {ObjectId} parent - the parent
 * {object} value - the actual value
 * {date} created_at - creation date 
 * {number} sortable_id - an integer for sorting, each new sortable_id is +1 the latest sortable_id
 * 
 * The ones below are set behind the scenes and most are only relevant for internals such as error propagation and analytics.
 * 
 * {object} source_creator - an object describing who created the project
 * {object} runnable_call - data describing how long it to took to create an object, if an error occurred in a script during the creation, or if a log entry was added
 */ 

const BotProperty= {

     /**
    * Adds a new property with the given name, value and user with the given parent_id. 
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the value of the property
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    */    
   add = function(name, value, parent_id, options={} ){  }
  
    /**
    * Increments the value of a numeric property. If property doesn't exist it will create it with the given value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the increment amount 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric. 
    */    
   incr = function(name, value, parent_id, options={} ){ } 
   
    /**
    * Multiplies the value of a numeric property. If property doesn't exist it will be set to 0.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  multiplication factor
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric. 
    */    
   mul = function(name, value, parent_id, options={} ){   }    

    /**
    * Adds a value to an array property unless the value is already present, in which case it does nothing to that array. If the property
    * wasn't defined yet it will create the array property with the specified value as its element.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the value to add to the array property 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   sadd = function(name, value, parent_id, options={} ){ }    


    /**
    * Removes from an existing array property all instances of the given value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the value to remove
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   rem = function(name, value, parent_id, options={} ){  }     

    /**
    * Left push to an array property. If property doesn't exist it will be set to [value]
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array. 
    
    */    
   lpush = function(name, value, parent_id, options={} ){   } 
   

    /**
    * Right push to an array property. If property doesn't exist it will be set to [value]
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   rpush = function(name, value, parent_id, options={} ){  } 

    /**
    * Left pop from array property. If property doesn't exist it will be set to undefined.
    * Returns the new value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {ObjectId} parent_id - the id of the parent    
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array. 

    */    
   lpop = function(name, parent_id, options={} ){  }
   
    /**
    * Left pop from array property. If property doesn't exist it will be set to undefined.
    * Returns the new value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array. 
    */    
    rpop = function(name, parent_id, options={} ){  }   
   
    /**
    * Adds a value to an array property that is treated as a set. If the same value  already exists it won't created a duplicate value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to add 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   sadd = async function (name, value, parent, options={} ) {   }
    /**
    * Removes all entries from the  array property that match the value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to remove 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
    
    rem = async function (name, value, parent, options={} ) {    }    

    /**
    * Set the key value pair in the given property. If property or key doesn't exist it will be set to [value]
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to set 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    set = async function (name, key, value, parent, options ) {  	}	
    /**
    * Unset the key value pair in the given property. 
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object to unset 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */ 
    unset = async function (name, key,  parent, options ) {   }    
    /**
    * Increase the key value pair in the given property. If property or key doesn't exist it will be set to [value]
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to increase by 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric.   
    */     
    hincr = async function (name, key, value, parent, options ) {    }	
    /**
    * Multiply the key value pair in the given property. If property or key doesn't exist it will be set to 0
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  multiplication factor 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric.   
    */  
   hmul = async function (name, key, value, parent, options ) {  }  
    /**
    * Left push to a property array entry. If property or key doesn't exist it will be set to [value]
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */   
    hlpush = async function (name, key, value, parent, options ) {  }
    /**
    * Left push to a property array entry. If property or key doesn't exist it will be set to [value]
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */   
   hrpush = async function (name, key, value, parent, options ) {   }    
    /**
    * Left pop from property array entry. If property doesn't exist it will be set to undefined.
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hlpop = async function (name, key, value, parent, options ) {  }   
    /**
    * Left pop from property array entry. If property doesn't exist it will be set to undefined.
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hrpop = async function (name, key, parent, options ) {  }  
    /**
    * Removes all entries from the  property array entry that match the value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to remove
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hrem = async function (name, key, value, parent, options ) { } 
    /**
    * Adds a value to a property array entry that is treated as a set. If the same value  already exists it won't created a duplicate value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to add 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hsadd = async function (name, key, value, parent, options ) { }     
  
    /**
    * Returns an array of properties that match the given conditions. You can query by name, value, created_at and parent_id. 
    * @see https://mongoosejs.com/docs/api.html#model_Model.find
    * @async
    * @return {Promise<number>} - the number of properties matching the condition.
    */    
    find = async function(conditions,projection,options){}

    /**
    * Counts number of documents matching filter in a database collection. 
    * https://mongoosejs.com/docs/api.html#model_Model.find
    * @async
    * @return {Promise<array>} - an array of properties
    */ 
    countDocuments = async function(filter){}

}

Examples

// add a property named "message" with the value "hi bot" to the bot with the given id
await BotProperty.add("message", "hi bot" , id);    

// increments the property 'counter' by 1
await BotProperty.incr("counter", 1 , id);    


//get the last 25 dances of all bots
const list = await BotProperty.find({name:"dance"},{},{sort: '-createdAt', limit: 25});

//count all properties of the bot with the given id
const count = await BotProperty.countDocuments({parent:id});

GlobalProperties

/*
 * Library of static methods to add, find, and count Global Properties. Each property has:
 * 
 * {string} name - the name
 * {ObjectId} parent - always null for Global Properties
 * {object} value - the actual value
 * {date} created_at - creation date 
 * {number} sortable_id - an integer for sorting, each new sortable_id is +1 the latest sortable_id
 * 
 * The ones below are set behind the scenes and most are only relevant for internals such as error propagation and analytics.
 * 
 * {object} source_creator - an object describing who created the project
 * {object} runnable_call - data describing  how long it to took to create an object, if an error occurred in a script during the creation, or if a log entry was added
 */ 

const GlobalProperty = {

     /**
    * Adds a new property with the given name, value and user with the given parent_id. 
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the value of the property
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    */    
   add = function(name, value, parent_id, options={} ){  }
  
    /**
    * Increments the value of a numeric property. If property doesn't exist it will create it with the given value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the increment amount 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric. 
    */    
   incr = function(name, value, parent_id, options={} ){ } 
   
    /**
    * Multiplies the value of a numeric property. If property doesn't exist it will be set to 0.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  multiplication factor
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric. 
    */    
   mul = function(name, value, parent_id, options={} ){   }    

    /**
    * Adds a value to an array property unless the value is already present, in which case it does nothing to that array. If the property
    * wasn't defined yet it will create the array property with the specified value as its element.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the value to add to the array property 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   sadd = function(name, value, parent_id, options={} ){ }    


    /**
    * Removes from an existing array property all instances of the given value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the value to remove
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   rem = function(name, value, parent_id, options={} ){  }     

    /**
    * Left push to an array property. If property doesn't exist it will be set to [value]
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array. 
    
    */    
   lpush = function(name, value, parent_id, options={} ){   } 
   

    /**
    * Right push to an array property. If property doesn't exist it will be set to [value]
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   rpush = function(name, value, parent_id, options={} ){  } 

    /**
    * Left pop from array property. If property doesn't exist it will be set to undefined.
    * Returns the new value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {ObjectId} parent_id - the id of the parent    
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array. 

    */    
   lpop = function(name, parent_id, options={} ){  }
   
    /**
    * Left pop from array property. If property doesn't exist it will be set to undefined.
    * Returns the new value.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array. 
    */    
    rpop = function(name, parent_id, options={} ){  }   
   
    /**
    * Adds a value to an array property that is treated as a set. If the same value  already exists it won't created a duplicate value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to add 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
   sadd = async function (name, value, parent, options={} ) {   }
    /**
    * Removes all entries from the  array property that match the value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to remove 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */    
    
    rem = async function (name, value, parent, options={} ) {    }    

    /**
    * Set the key value pair in the given property. If property or key doesn't exist it will be set to [value]
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to set 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    set = async function (name, key, value, parent, options ) {  	}	
    /**
    * Unset the key value pair in the given property. 
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object to unset 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */ 
    unset = async function (name, key,  parent, options ) {   }    
    /**
    * Increase the key value pair in the given property. If property or key doesn't exist it will be set to [value]
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to increase by 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric.   
    */     
    hincr = async function (name, key, value, parent, options ) {    }	
    /**
    * Multiply the key value pair in the given property. If property or key doesn't exist it will be set to 0
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  multiplication factor 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not numeric.   
    */  
   hmul = async function (name, key, value, parent, options ) {  }  
    /**
    * Left push to a property array entry. If property or key doesn't exist it will be set to [value]
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */   
    hlpush = async function (name, key, value, parent, options ) {  }
    /**
    * Left push to a property array entry. If property or key doesn't exist it will be set to [value]
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to push 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */   
   hrpush = async function (name, key, value, parent, options ) {   }    
    /**
    * Left pop from property array entry. If property doesn't exist it will be set to undefined.
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hlpop = async function (name, key, value, parent, options ) {  }   
    /**
    * Left pop from property array entry. If property doesn't exist it will be set to undefined.
    * @throws when current property value is not an array.
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hrpop = async function (name, key, parent, options ) {  }  
    /**
    * Removes all entries from the  property array entry that match the value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {string} key - the key of the property object
    * @param {object} value - the  value to remove
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hrem = async function (name, key, value, parent, options ) { } 
    /**
    * Adds a value to a property array entry that is treated as a set. If the same value  already exists it won't created a duplicate value
    *
    * @async
    * @param {string} name - the name of the property
    * @param {object} value - the  value to add 
    * @param {ObjectId} parent_id - the id of the parent
    * @param {object} options
    * @param {object} options.notify {boolean, default=true} notify scripts & sockets;  default false
    * @param {object} options.inline  {boolean, default=false} when a property is designated for processing by a script, a queue message containing the property_id is  queued, when `inline` is set to `true` the actual property value is being queued
    * @param {object} options.inline_parent {boolean, default=false} when a property is designated for processing by a script, a queue message containing the parent_id is queued, when `inline_parent` is set to `true` the actual parent value is being queued
    * @param {object} options.avoid_duplicate {boolean, default=false}  when true a value will be only added and notified if the value is different then the last value
    * @param {object} options.direct {boolean,  default=false} when true any matching script will be triggered immediately with no queuing
    * @param {object}  options.passive` (default:false) when set to `true` the property is only stored in parent object (either user, bot or * @return {Promise<object>} - the property
    * @throws when current property value is not an array.     
    */     
    hsadd = async function (name, key, value, parent, options ) { }     
  
    /**
    * Returns an array of properties that match the given conditions. You can query by name, value, created_at and parent_id. 
    * @see https://mongoosejs.com/docs/api.html#model_Model.find
    * @async
    * @return {Promise<number>} - the number of properties matching the condition.
    */    
    find = async function(conditions,projection,options){}

    /**
    * Counts number of documents matching filter in a database collection. 
    * https://mongoosejs.com/docs/api.html#model_Model.find
    * @async
    * @return {Promise<array>} - an array of properties
    */ 
    countDocuments = async function(filter){} 
}

Examples

// add a property named "accepting_requests" with the value true
await GlobalProperty.add("accepting_requests", "true" , null);   


// increments the property 'counter' by 1
await GlobalProperty.incr("counter", 1 , id);  


//get the last 100 global weather properties
const list = await GlobalProperty.find({name:"weather"},{},{sort: '-createdAt', limit: 100});

//count all global satellite properties
const count = await GlobalProperty.countDocuments({name:"satellite"});

User

Users can be created and queried in scripts and jobs.

/*
 * Library of methods to create or query a user. Data structure of a user:
 * 
 * {string} username - the name (unique required)
 * {string} email - the email
 * {date} created_at - creation date 
 * {date} updated_at - last updated date
 *
 * The user password is a virtual property stored in a hash and a salt.
 *
 * When you retrieve a user, it may also have properties. The latest of version of each property is stored with the user 
 * for quick access.
 * 
 * {object} properties - key value object where the key is the property name and value the complete property with all meta information as described below. 
 
 *    {string} name - the name
 *    {ObjectId} parent - the parent, the users id
 *    {object} value - the actual value
 *    {date} created_at - creation date 
 *    {number} sortable_id - an integer for sorting, each new sortable_id is +1 the latest sortable_id
 * 
 *   The ones below are set behind the scenes and most are only relevant for internals such as error propagation and analytics.
 * 
 *   {object} source_creator - an object describing who created the project
 *   {object} runnable_call - data describing how long it to took to create the object, if error occurred in a script during the creation, or a log entry was added 
 * 
 */ 

const User= {

 /**
  * Create a user with the give values.
    * @see https://mongoosejs.com/docs/api.html#model_Model.create
    * @async
    * {object} values - the values of the user to create {username:"player_1", password:"very_secret_123"}
    * @return {Promise<user>} - an object representing the user properties
    */    
 create = async function(values){}
 
 /**
    * Handy methods that finds users that match the conditions or creates a user with the conditions and the values.
    * @example: const user =async  User.findOrCreate({username:"user_2"},{email:"user_2@hexagram.io"});
    * @see https://github.com/drudge/mongoose-findorcreate#readme
    * @async
    * {object} conditions - the condition required to match, i.e. {username:"takeshi_kovacs"}
    * {object} values - that are applied if no user was
    * @return {Promise<array>} - an array of objects representing the user properties
    */    
 findOrCreateAsync = async function(conditions,values){} 
 
 /**
  * Find one user that matches the conditions.
    * @see https://mongoosejs.com/docs/api.html#model_Model.find
    * @async
    * {object} conditions - the condition required to match, i.e. {username:"takeshi_kovacs"}
    * @return {Promise<object>} - an object representing the user properties
    */    
 findOne = async function(conditions,projection,options){}

 /**
  * Find all users that match the conditions.
    * @see https://mongoosejs.com/docs/api.html#model_Model.find
    * @async
    * {object} conditions - the condition required to match, i.e. {username:"takeshi_kovacs"}
    * @return {Promise<array>} - an array of objects representing the user properties
    */    
 find = async function(conditions,projection,options){}

}

Examples


//find a user named rob
const user =  await User.findOne({username:"rob"})

//find all users whose username contains kay
const users =  await User.find({username: {$regex:/kay/} })

//create a user with the username "very_useful" 
const user =  await User.create({username:"very_useful"})

//create a user with the username "very_useful_2" and the password "1234abcd"
const user =  await User.create({username:"very_useful_2",password:"1234abcd"})

//find or create a user with the username "very_useful_3" 
const user =  (await User.findOrCreate({username:"very_useful_3"}))[0]

//find all user who at least unlocked level 3
//see: https://docs.mongodb.com/manual/reference/operator/query/gte/
const bots = await Bot.find({"properties.unlocked.value":{$gte:3}});

Storage

A storage object is a Mongoose Schema paired with a file storage plugin that interface with and provide abstraction of the storage vendor API.

{
  /**
   * Create a file
   * @param path the path
   * @param body the body
   * @param options other vendor-specific options
   */
  schema.methods.putObject = async function (path, body, options = {}) {
    await this.getImplementation().putObject(path, body, options);
  }


  /**
   * Get a file/object
   * @param path the path
   * @throws NotFoundError
   * @throws ForbiddenError
   * @throws UnauthorizedError*
   * @return {Promise<object content>} - the content
   */
  schema.methods.getObject = async function (path) {
    return await this.getImplementation().getObject(path);
  }

  /**
   * Returns a list of objects, order is vendor specific. Can be filtered by prefix
   * @param prefix the prefix
   * @throws NotFoundError
   * @throws ForbiddenError
   * @throws UnauthorizedError
   * @return {Promise<object content>} - array of files
   */
  schema.methods.listObjects = async function (prefix) {
    return await this.getImplementation().listObjects(prefix);
  }

  /**
   * Delete a file/object
   * @param path the path
   * @throws NotFoundError
   * @throws ForbiddenError
   * @throws UnauthorizedError
   * @return {Promise<object content>} - the content
   */
  schema.methods.deleteObject = async function (path) {
    await this.getImplementation().deleteObject(path);
  }
  /**
   * Retrieve a URL that allows to retrieve the file content without authentication
   * @param path the path of the file
   * @param ttl the TTL of URL
   * @throws NotFoundError
   * @throws ForbiddenError
   * @throws UnauthorizedError
   * @return {Promise<string>} the url
   */
  schema.methods.preSignedGetUrl = async function (path, ttl) {
    return await this.getImplementation().preSignedGetUrl(path, ttl);
  }
}

Examples


//get the storage
const storage =  await Storage.findOne({name:"skins"})

//get the stream for a file
const stream =  await storage.get("name_of_file")

//get the url for a file
const url =  await storage.preSignedGetUrl("name_of_file")