powered by Authenteo

Persistent JavaScript

Persistent JS API

Persistent JavaScript defines an API for accessing and manipulating persistent objects. The API is contained in the pjs namespace.

pjs.load(id:String[, callback:Function]):*

Returns an object with the given id. All persisted objects should have an id, and this functions provides the ability to retrieve an object by its id. callback is an optional parameter if an asynchronous non-blocking operation is used to load the id. If available, callback will be called when the load is finished, and will be called with a single parameter, the value loaded.

pjs.set(target:Object,key:String,value:*):*

This will set a persistent property of the given target object.

pjs.get(target:Object,key:String[, callback:Function]):*

This will retrieve a property from the given target object. This should act essentially the same as target[key]. callback is an optional parameter if an asynchronous non-blocking operation is used to get the property (lazy loading). If available, callback will be called when the get is finished, and will be called with a single parameter, the value retrieved.

pjs.commit([callback:Function])

Commits all the changes that have been made in the current transaction. callback is an optional parameter if an asynchronous non-blocking operation is used to commit. If available, callback will be called when the commit is finished, and will be called with a single parameter, a boolean indicating the success of the operation.

pjs.rollback()

Rolls back all the changes that have been made in the current transaction.

pjs.changing(object)

Prepares an object to be modified, this is not necessary if you using orthogonal persistence.

pjs.save(object)

Saves the changes made to a persistent object in the current transaction.

pjs.getAccessLevel(object:Object):Number

Returns the access level of the current user on the given object. The access level should be an integer denoted a permission according to this table:

    * 0 - none - can not access any of the fields on this object

    * 1 - browse - can only read from a limited set of fields (usually name and basis)

    * 2 - read - can read all the information from this object, but can not make any modifications to this object

    * 3 - append - for list objects, entries can be appended, but no property modifications can be made

    * 5 - write - any modifications can be made to this object

    * Note that Persistent JavaScript is garbage collection based so there is no concept of deleting an object, only properties. Objects are deleted when all references to them are removed.

pjs.getId(object:Object)

Returns the object id for the given object.

pjs.isPersisted(object:Object)

Returns true if the object has been persisted or is in the act of being persisted.

pjs.newInstance(basis:Object):Object

This function is called whenever the new operator is applied to an object (not a function). This returns a new object with a basis of the provided basis parameter.