Skip to content

Commit 5394fa4

Browse files
authored
Merge pull request #279 from share/middleware-docs-reply
Update middleware docs: add "reply" action, other tweaks
2 parents d130700 + 8a47c18 commit 5394fa4

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

README.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,24 @@ Register a new middleware.
149149
* `'afterSubmit'`: An operation was successfully submitted to
150150
the database.
151151
* `'receive'`: Received a message from a client
152-
* `fn` _(Function(request, callback))_
152+
* `'reply'`: About to send a non-error reply to a client message
153+
* `fn` _(Function(context, callback))_
153154
Call this function at the time specified by `action`.
154-
`request` contains a subset of the following properties, as relevant for the action:
155-
* `action`: The action this middleware is handing
156-
* `agent`: An object corresponding to the server agent handing this client
157-
* `req`: The HTTP request being handled
158-
* `collection`: The collection name being handled
159-
* `id`: The document id being handled
160-
* `snapshots`: The retrieved snapshots for the `readSnapshots` action
161-
* `query`: The query object being handled
162-
* `op`: The op being handled
155+
* `context` will always have the following properties:
156+
* `action`: The action this middleware is hanlding
157+
* `agent`: A reference to the server agent handling this client
158+
* `backend`: A reference to this ShareDB backend instance
159+
* `context` can also have additional properties, as relevant for the action:
160+
* `collection`: The collection name being handled
161+
* `id`: The document id being handled
162+
* `op`: The op being handled
163+
* `req`: HTTP request being handled, if provided to `share.listen` (for 'connect')
164+
* `stream`: The duplex Stream provided to `share.listen` (for 'connect')
165+
* `query`: The query object being handled (for 'query')
166+
* `snapshots`: Array of retrieved snapshots (for 'readSnapshots')
167+
* `data`: Received client message (for 'receive')
168+
* `request`: Client message being replied to (for 'reply')
169+
* `reply`: Reply to be sent to the client (for 'reply')
163170

164171
### Projections
165172

0 commit comments

Comments
 (0)