Skip to content

Commit d3f0bfb

Browse files
authored
Merge pull request #472 from share/submit-op-docs
📝 Add op submission lifecycle to middleware docs
2 parents 4e725df + e48eca7 commit d3f0bfb

File tree

5 files changed

+400
-234
lines changed

5 files changed

+400
-234
lines changed

docs/api/backend.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Optional
115115

116116
### `MIDDLEWARE_ACTIONS` -- Object
117117

118-
> Map of available [middleware actions]({{ site.baseurl }}{% link middleware/index.md %}#actions)
118+
> Map of available [middleware actions]({{ site.baseurl }}{% link middleware/actions.md %})
119119
120120
## Methods
121121

docs/middleware/actions.md

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
---
2+
title: Actions
3+
nav_order: 2
4+
layout: default
5+
parent: Middleware
6+
7+
copy:
8+
submit_request_props: |-
9+
`collection` -- string
10+
> The collection of the op
11+
12+
`id` -- string
13+
> The document ID
14+
15+
`op` -- Object
16+
> The submitted op
17+
18+
`snapshot` -- [`Snapshot`]({{ site.baseurl }}{% link api/snapshot.md %})
19+
> The snapshot
20+
21+
`extra` -- Object
22+
> `extra.source` -- Object
23+
>> The submitted source when [`doc.submitSource`]({{ site.baseurl }}{% link api/doc.md %}http://localhost:4000/api/doc#submitsource--boolean) is set to `true`
24+
25+
`saveMilestoneSnapshot` -- boolean
26+
> Flag to control [saving a milestone snapshot]({{ site.baseurl }}{% link adapters/milestone.md#requesting-snapshots %})
27+
28+
`suppressPublish` -- boolean
29+
> Flag to prevent broadcasting over [pub/sub]({{ site.baseurl }}{% link pub-sub.md %})
30+
31+
`retries` -- number
32+
> The number of times the op has attempted to submit
33+
34+
`maxRetries` -- number
35+
> The maximum number of times to retry submitting the op
36+
37+
`channels` -- string[]
38+
> The [pub/sub]({{ site.baseurl }}{% link pub-sub.md %}) channels the op will publish to
39+
40+
---
41+
42+
# Middleware actions
43+
{: .no_toc }
44+
45+
1. TOC
46+
{:toc}
47+
48+
The actions represent different stages of information flow through the server. These hooks are also available on [`backend.MIDDLEWARE_ACTIONS`]({{ site.baseurl }}{% link api/backend.md %}#middleware_actions--object).
49+
50+
All of the actions will have these `context` properties:
51+
52+
`action` -- string
53+
54+
> The triggered middleware action
55+
56+
`agent` -- [Agent]({{ site.baseurl }}{% link api/agent.md %})
57+
58+
> The [`Agent`]({{ site.baseurl }}{% link api/agent.md %}) communicating with the client
59+
60+
`backend` -- [Backend]({{ site.baseurl }}{% link api/backend.md %})
61+
62+
> The [`Backend`]({{ site.baseurl }}{% link api/backend.md %}) handling the request
63+
64+
## `'connect'`
65+
66+
A new client connected to the server.
67+
68+
This action has these additional `context` properties:
69+
70+
`stream` -- [Stream](https://nodejs.org/api/stream.html)
71+
72+
> The [`Stream`](https://nodejs.org/api/stream.html) that connected
73+
74+
`req` -- Object
75+
76+
> The `request` argument provided to [`backend.listen()`]({{ site.baseurl }}{% link api/backend.md %}#listen)
77+
78+
## `'receive'`
79+
80+
The server received a message from a client.
81+
82+
This action has these additional `context` properties:
83+
84+
`data` -- Object
85+
86+
> The received data
87+
88+
## `'reply'`
89+
90+
The server is about to send a non-error reply to a client message.
91+
92+
This action has these additional `context` properties:
93+
94+
`request` -- Object
95+
96+
> The client's received request
97+
98+
`reply` -- Object
99+
100+
> The reply about to be sent
101+
102+
## `'sendPresence'`
103+
104+
Presence information is about to be sent to a client.
105+
106+
This action has these additional `context` properties:
107+
108+
`collection` -- string
109+
110+
> The collection the presence is associated with
111+
112+
`presence` -- Object
113+
114+
> The presence object being sent. Its shape depends on its [type]({{ site.baseurl }}{% link types/index.md %})
115+
116+
## `'query'`
117+
118+
A new query request is about to be submitted to the database
119+
120+
This action has these additional `context` properties:
121+
122+
`index` -- string
123+
124+
> The name of the query's collection or [projection]({{ site.baseurl }}{% link projections.md %})
125+
126+
`collection` -- string
127+
128+
> The name of the query's target collection
129+
130+
`projection` -- string
131+
132+
> The name of the query's [projection]({{ site.baseurl }}{% link projections.md %})
133+
134+
`fields` -- Object
135+
136+
> The query's projection [fields]({{ site.baseurl }}{% link api/backend.md %}#addprojection)
137+
138+
`channel` -- string
139+
140+
> The [Pub/Sub]({{ site.baseurl }}{% link adapters/pub-sub.md %}) channel the query will subscribe to. Defaults to its collection channel.
141+
142+
`query` -- Object
143+
144+
> The query being submitted to the database adapter
145+
146+
`options` -- Object
147+
148+
> The query [options]({{ site.baseurl }}{% link api/connection.md %}#createfetchquery)
149+
150+
`db` -- [DB]({{ site.baseurl }}{% link adapters/database.md %})
151+
152+
> The database the query will be run against
153+
154+
## `'readSnapshots'`
155+
156+
One or more snapshots were loaded from the database for a fetch or subscribe.
157+
158+
This action has these additional `context` properties:
159+
160+
`collection` -- string
161+
162+
> The collection the snapshots belong to
163+
164+
`snapshots` -- [Snapshot[]]({{ site.baseurl }}{% link api/snapshot.md %})
165+
166+
> The [`Snapshot`]({{ site.baseurl }}{% link api/snapshot.md %})s being read
167+
168+
`snapshotType` -- string
169+
170+
> One of:
171+
> - `current` -- the snapshots are the latest version
172+
> - `byVersion` -- the snapshots are being fetched by version
173+
> - `byTimestamp` -- the snapshots are being fetched by timestamp
174+
175+
## `'op'`
176+
177+
An operation was loaded from the database.
178+
179+
This action has these additional `context` properties:
180+
181+
`collection` -- string
182+
183+
> The collection of the op
184+
185+
`id` -- string
186+
187+
> The document ID
188+
189+
`op` -- Object
190+
191+
> The op being read
192+
193+
## `'submit'`
194+
195+
An operation has been submitted to the server.
196+
197+
This action has these additional `context` properties:
198+
199+
{{ page.copy.submit_request_props }}
200+
201+
## `'apply'`
202+
203+
An operation is about to be applied to a snapshot, before committing.
204+
205+
This action has these additional `context` properties:
206+
207+
{{ page.copy.submit_request_props }}
208+
209+
## `'commit'`
210+
211+
An operation was applied to a snapshot, and is about to be committed to the database.
212+
213+
This action has these additional `context` properties:
214+
215+
{{ page.copy.submit_request_props }}
216+
217+
## `'afterWrite'`
218+
219+
An operation and its updated snapshot were successfully written to the database.
220+
221+
This action has these additional `context` properties:
222+
223+
{{ page.copy.submit_request_props }}

0 commit comments

Comments
 (0)