Middleware actions
'connect'
'receive'
'reply'
'receivePresence'
'sendPresence'
'query'
'readSnapshots'
'op'
'submit'
'apply'
'commit'
'afterWrite'
The actions represent different stages of information flow through the server. These hooks are also available on backend.MIDDLEWARE_ACTIONS
.
All of the actions will have these context
properties:
action
– string
The triggered middleware action
agent
– Agent
The
Agent
communicating with the client
backend
– Backend
The
Backend
handling the request
'connect'
A new client connected to the server.
This action has these additional context
properties:
stream
– Stream
The
Stream
that connected
req
– Object
The
request
argument provided tobackend.listen()
'receive'
The server received a message from a client.
This action has these additional context
properties:
data
– Object
The received data
'reply'
The server is about to send a non-error reply to a client message.
This action has these additional context
properties:
request
– Object
The client’s received request
reply
– Object
The reply about to be sent
'receivePresence'
Presence information has just been received from a client. The presence has not yet been transformed against any ops it has missed.
This action has these additional context
properties:
collection
– string
The collection the presence is associated with
presence
– Object
The presence object that was received. Its shape depends on its type
'sendPresence'
Presence information is about to be sent to a client.
This action has these additional context
properties:
collection
– string
The collection the presence is associated with
presence
– Object
The presence object being sent. Its shape depends on its type
'query'
A new query request is about to be submitted to the database
This action has these additional context
properties:
index
– string
The name of the query’s collection or projection
collection
– string
The name of the query’s target collection
projection
– string
The name of the query’s projection
fields
– Object
The query’s projection fields
channel
– string (deprecated)
This property is deprecated use
channels
instead. The Pub/Sub channels the query will subscribe to. Defaults to its collection channel.
channels
– string[]
The Pub/Sub channels the query will subscribe to. Defaults to its collection channel.
query
– Object
The query being submitted to the database adapter
options
– Object
The query options
db
– DB
The database the query will be run against
'readSnapshots'
One or more snapshots were loaded from the database for a fetch or subscribe.
This action has these additional context
properties:
collection
– string
The collection the snapshots belong to
snapshots
– Snapshot[]
The
Snapshot
s being read
snapshotType
– string
One of:
current
– the snapshots are the latest versionbyVersion
– the snapshots are being fetched by versionbyTimestamp
– the snapshots are being fetched by timestamp
'op'
An operation was loaded from the database.
This action has these additional context
properties:
collection
– string
The collection of the op
id
– string
The document ID
op
– Object
The op being read
'submit'
An operation has been submitted to the server.
This action has these additional context
properties:
collection
– string
The collection of the op
id
– string
The document ID
op
– Object
The submitted op
snapshot
– Snapshot
The snapshot
extra
– Object
extra.source
– ObjectThe submitted source when
doc.submitSource
is set totrue
saveMilestoneSnapshot
– boolean
Flag to control saving a milestone snapshot
suppressPublish
– boolean
Flag to prevent broadcasting over pub/sub
retries
– number
The number of times the op has attempted to submit
maxRetries
– number
The maximum number of times to retry submitting the op
channels
– string[]
The pub/sub channels the op will publish to
'apply'
An operation is about to be applied to a snapshot, before committing.
This action has the same additional context
properties as 'submit'
.
'commit'
An operation was applied to a snapshot, and is about to be committed to the database.
This action has the same additional context
properties as 'submit'
.
'afterWrite'
An operation and its updated snapshot were successfully written to the database.
This action has the same additional context
properties as 'submit'
.