docs.md

November 21, 2025 · View on GitHub

Classes

ResClient

ResClient represents a client connection to a RES API.

ResCollection

ResCollection represents a collection provided over the RES API.

ResModel

ResModel represents a model provided over the RES API.

ResError

ResError represents a RES API error.

Typedefs

eventCallback : function

Event callback

ResClient

ResClient represents a client connection to a RES API.

Kind: global class

new ResClient(hostUrlOrFactory, [opt])

Creates a ResClient instance

ParamTypeDescription
hostUrlOrFactorystring | websocketFactoryWebsocket host path, or websocket factory function. Path may be relative to current path.
[opt]objectOptional parameters.
[opt.onConnect]functionOn connect callback called prior resolving the connect promise and subscribing to stale resources. May return a promise.
[opt.namespace]stringEvent bus namespace. Defaults to 'resclient'.
[opt.reconnectDelay]booleanMilliseconds between WebSocket reconnect attempts. Defaults to 3000.
[opt.subscribeStaleDelay]booleanMilliseconds until a subscribe attempt is made on a stale resource. Zero means no attempt to subscribe. Defaults to 2000.
[opt.subscribeRetryDelay]booleanMilliseconds between subscribe attempts on a stale resource after a failed stale subscribe. Zero means no retries. Defaults to 10000.
[opt.unsubscribeDelay]booleanMilliseconds between stopping listening to a resource, and the resource being unsubscribed. Defaults to 5000.
[opt.debug]boolean | functionFlag to debug log all WebSocket communication, or logging function. Defaults to false. Function has schema: (type:string,msg:string,ctx:any) => void.
[opt.eventBus]module:modapp~EventBusEvent bus.

resClient.supportedProtocol ⇒ string

RES protocol level supported by this client version.

Kind: instance property of ResClient
Returns: string - Supported RES protocol version.

resClient.connect() ⇒ Promise

Connects the instance to the server. Can be called even if a connection is already established.

Kind: instance method of ResClient
Returns: Promise - A promise to the established connection.

resClient.disconnect()

Disconnects any current connection and stops attempts of reconnecting.

Kind: instance method of ResClient

resClient.getHostUrl() ⇒ string

Gets the host URL to the RES API

Kind: instance method of ResClient
Returns: string - Host URL

resClient.on(events, handler)

Attach an event handler function for one or more instance events. Available events are 'connect', 'disconnect', and 'error'.

Kind: instance method of ResClient

ParamTypeDescription
eventsstringOne or more space-separated events. Null means any event.
handlerconnectCallback | disconnectCallback | errorCallbackHandler function to execute when the event is emitted.

resClient.off(events, [handler])

Remove an instance event handler. Available events are 'connect', 'disconnect', and 'error'.

Kind: instance method of ResClient

ParamTypeDescription
eventsstringOne or more space-separated events. Null means any event.
[handler]connectCallback | disconnectCallback | errorCallbackHandler function to remove.

resClient.setOnConnect(onConnect) ⇒ this

Sets the onConnect callback.

Kind: instance method of ResClient

ParamTypeDescription
onConnectonConnectCallbackOn connect callback called prior resolving the connect promise and subscribing to stale resources. May return a promise.

resClient.registerModelType(pattern, factory) ⇒ this

Register a model type. The pattern may use the following wild cards:

  • The asterisk (*) matches any part at any level of the resource name.
  • The greater than symbol (>) matches one or more parts at the end of a resource name, and must be the last part.

Kind: instance method of ResClient

ParamTypeDescription
patternstringPattern of the model type.
factorymodelFactoryModel factory callback

resClient.unregisterModelType(pattern) ⇒ modelFactory

Unregister a previously registered model type pattern.

Kind: instance method of ResClient
Returns: modelFactory - Unregistered model factory callback

ParamTypeDescription
patternstringPattern of the model type.

resClient.registerCollectionType(pattern, factory) ⇒ this

Register a collection type. The pattern may use the following wild cards:

  • The asterisk (*) matches any part at any level of the resource name.
  • The greater than symbol (>) matches one or more parts at the end of a resource name, and must be the last part.

Kind: instance method of ResClient

ParamTypeDescription
patternstringPattern of the collection type.
factorycollectionFactoryCollection factory callback

resClient.unregisterCollectionType(pattern) ⇒ collectionFactory

Unregister a previously registered collection type pattern.

Kind: instance method of ResClient
Returns: collectionFactory - Unregistered collection factory callback

ParamTypeDescription
patternstringPattern of the collection type.

resClient.get(rid, [collectionFactory]) ⇒ Promise.<(ResModel|ResCollection)>

Get a resource from the API

Kind: instance method of ResClient
Returns: Promise.<(ResModel|ResCollection)> - Promise of the resource.

ParamTypeDescription
ridstringResource ID
[collectionFactory]functionCollection factory function.

resClient.call(rid, method, params) ⇒ Promise.<object>

Calls a method on a resource.

Kind: instance method of ResClient
Returns: Promise.<object> - Promise of the call result.

ParamTypeDescription
ridstringResource ID.
methodstringMethod name
params*Method parameters

resClient.authenticate(rid, method, params) ⇒ Promise.<object>

Invokes a authentication method on a resource.

Kind: instance method of ResClient
Returns: Promise.<object> - Promise of the authentication result.

ParamTypeDescription
ridstringResource ID.
methodstringMethod name
params*Method parameters

resClient.create(rid, params) ⇒ Promise.<(ResModel|ResCollection)>

Deprecated

Creates a new resource by calling the 'new' method.
Use call with 'new' as method parameter instead.

Kind: instance method of ResClient
Returns: Promise.<(ResModel|ResCollection)> - Promise of the resource.

ParamTypeDescription
rid*Resource ID
params*Method parameters

resClient.setModel(modelId, props) ⇒ Promise.<object>

Calls the set method to update model properties.

Kind: instance method of ResClient
Returns: Promise.<object> - Promise of the call being completed.

ParamTypeDescription
modelIdstringModel resource ID.
propsobjectProperties. Set value to undefined to delete a property.

ResClient~connectCallback : function

Connect event emitted on connect.

Kind: inner typedef of ResClient

ParamTypeDescription
eventobjectWebSocket open event object

ResClient~disconnectCallback : function

Disconnect event emitted on disconnect.

Kind: inner typedef of ResClient

ParamTypeDescription
eventobjectWebSocket close event object

ResClient~errorCallback : function

Error event emitted on error.

Kind: inner typedef of ResClient

ParamTypeDescription
errResErrorResError object

ResClient~websocketFactory ⇒ WebSocket

WebSocket factory function.

Kind: inner typedef of ResClient
Returns: WebSocket - WebSocket instance implementing the WebSocket API.

ResClient~onConnectCallback ⇒ Promise

OnConnect callback function.

Kind: inner typedef of ResClient
Returns: Promise - Promise for the onConnect handlers completion. Must always resolve.

ParamTypeDescription
ResClientResClientinstance

ResClient~modelFactory ⇒ ResModel

Model factory callback

Kind: inner typedef of ResClient
Returns: ResModel - Model instance object.

ParamTypeDescription
apiResClientResClient instance
ridstringResource ID

ResClient~collectionFactory ⇒ ResCollection

Collection factory callback

Kind: inner typedef of ResClient
Returns: ResCollection - Collection instance object.

ParamTypeDescription
apiResClientResClient instance
ridstringResource ID

ResCollection

ResCollection represents a collection provided over the RES API.

Kind: global class
Implements: module:modapp~Collection

new ResCollection(api, rid, [opt])

Creates an ResCollection instance

ParamTypeDescription
apiResClientResClient instance
ridstringResource id.
[opt]objectOptional settings
[opt.idCallback]functionId callback function.

resCollection.length

Length of the collection

Kind: instance property of ResCollection

resCollection.list

Internal collection array. Do not mutate directly.

Kind: instance property of ResCollection

resCollection.getClient() ⇒ ResClient

ResClient instance.

Kind: instance method of ResCollection
Returns: ResClient - ResClient instance

resCollection.getResourceId() ⇒ string

Collection resource ID

Kind: instance method of ResCollection
Returns: string - Resource ID

resCollection.on([events], [handler]) ⇒ this

Attach a collection event handler function for one or more events. If no event or handler is provided, the collection will still be considered listened to, until a matching off call without arguments is made. Available events are 'add', 'remove', and custom events.

Kind: instance method of ResCollection

ParamTypeDescription
[events]stringOne or more space-separated events. Null means any event.
[handler]addCallback | removeCallback | eventCallbackHandler function to execute when the event is emitted.

resCollection.off([events], [handler]) ⇒ this

Remove a collection event handler function. Available events are 'add', 'remove', and custom events.

Kind: instance method of ResCollection

ParamTypeDescription
[events]stringOne or more space-separated events. Null means any event.
[handler]addCallback | removeCallback | eventCallbackHandler function to remove.

resCollection.get(id) ⇒ *

Get an item from the collection by id. Requires that id callback is defined for the collection.

Kind: instance method of ResCollection
Returns: * - Item with the id. Undefined if key doesn't exist

ParamTypeDescription
idstringId of the item

resCollection.indexOf(item) ⇒ number

Retrieves the order index of an item.

Kind: instance method of ResCollection
Returns: number - Order index of the first matching item. -1 if the item doesn't exist.

ParamTypeDescription
item*Item to find

resCollection.atIndex(idx) ⇒ *

Gets an item from the collection by index position

Kind: instance method of ResCollection
Returns: * - Item at the given index. Undefined if the index is out of bounds.

ParamTypeDescription
idxnumberIndex of the item

resCollection.call(method, params) ⇒ Promise.<object>

Calls a method on the collection.

Kind: instance method of ResCollection
Returns: Promise.<object> - Promise of the call result.

ParamTypeDescription
methodstringMethod name
params*Method parameters

resCollection.auth(method, params) ⇒ Promise.<object>

Calls an auth method on the collection.

Kind: instance method of ResCollection
Returns: Promise.<object> - Promise of the auth result.

ParamTypeDescription
methodstringAuth method name
params*Method parameters

resCollection.toArray() ⇒ Array.<*>

Returns a shallow clone of the internal array.

Kind: instance method of ResCollection
Returns: Array.<*> - Clone of internal array

ResCollection~addEvent : object

Add event data

Kind: inner typedef of ResCollection
Properties

NameTypeDescription
item*Item being added to the collection.
idxnumberIndex where item was added.

ResCollection~addCallback : function

Add event emitted on any item being added to the collection.

Kind: inner typedef of ResCollection

ParamTypeDescription
eventaddEventAdd event data.
collectionResCollectionCollection emitting event.
eventstringEvent name including namespace.
actionstringEvent action.

ResCollection~removeEvent : object

Remove event data

Kind: inner typedef of ResCollection
Properties

NameTypeDescription
item*Item being removed from the collection.
idxnumberIndex from where the item was removed.

ResCollection~removeCallback : function

Remove event emitted on any item being added to the collection.

Kind: inner typedef of ResCollection

ParamTypeDescription
eventremoveEventRemove event data.
collectionResCollectionCollection emitting event.
eventstringEvent name including namespace.
actionstringEvent action.

ResModel

ResModel represents a model provided over the RES API.

Kind: global class
Implements: module:modapp~Model

new ResModel(api, rid, [opt])

Creates a ResModel instance

ParamTypeDescription
apiResClientResClient instance
ridstringResource id.
[opt]objectOptional parameters.
[opt.definition]objectObject definition. If not provided, any value will be allowed.

resModel.props ⇒ object

Model properties.

Kind: instance property of ResModel
Returns: object - Anonymous object with all model properties.

resModel.getClient() ⇒ ResClient

ResClient instance.

Kind: instance method of ResModel
Returns: ResClient - ResClient instance

resModel.getResourceId() ⇒ string

Model resource ID

Kind: instance method of ResModel
Returns: string - Resource ID

resModel.on([events], [handler]) ⇒ this

Attach a model event handler function for one or more events. If no event or handler is provided, the model will still be considered listened to, until a matching off call without arguments is made. Available events are 'change', or custom events.

Kind: instance method of ResModel

ParamTypeDescription
[events]stringOne or more space-separated events. Null means any event.
[handler]changeCallback | eventCallbackHandler function to execute when the event is emitted.

resModel.off(events, [handler]) ⇒ this

Remove a model event handler function. Available events are 'change', or custom events.

Kind: instance method of ResModel

ParamTypeDescription
eventsstringOne or more space-separated events. Null means any event.
[handler]changeCallback | eventCallbackHandler function to remove.

resModel.set(props) ⇒ Promise.<object>

Calls the set method to update model properties.

Kind: instance method of ResModel
Returns: Promise.<object> - Promise of the call being completed.

ParamTypeDescription
propsobjectProperties. Set value to undefined to delete a property.

resModel.call(method, params) ⇒ Promise.<object>

Calls a method on the model.

Kind: instance method of ResModel
Returns: Promise.<object> - Promise of the call result.

ParamTypeDescription
methodstringMethod name
params*Method parameters

resModel.auth(method, params) ⇒ Promise.<object>

Calls an auth method on the model.

Kind: instance method of ResModel
Returns: Promise.<object> - Promise of the auth result.

ParamTypeDescription
methodstringAuth method name
params*Method parameters

ResModel~changeCallback : function

Change event emitted on any change to one or more public (non-underscore) properties.

Kind: inner typedef of ResModel

ParamTypeDescription
changedObject.<string, *>Changed key/value object where key is the changed property, and value is the old property value.
modelModelResModel emitting the event.
eventstringEvent name including namespace.
actionstringEvent action.

ResError

ResError represents a RES API error.

Kind: global class

resError.code : string

Error code

Kind: instance property of ResError

resError.message : string

Error message

Kind: instance property of ResError

resError.data : *

Error data object

Kind: instance property of ResError

resError.getResourceId() ⇒ string

Error resource ID

Kind: instance method of ResError
Returns: string - Resource ID

eventCallback : function

Event callback

Kind: global typedef

ParamTypeDescription
dataobjectEvent data object
resourceobjectResource emitting the event
eventstringEvent name including namespace
actionstringEvent action