@hattoriai/poney 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/brief.md +4 -4
- package/dist/{chunk-BCOS4LFB.js → chunk-4JIZI7QP.js} +14 -8
- package/dist/chunk-4JIZI7QP.js.map +1 -0
- package/dist/{chunk-YLKV6LIU.js → chunk-KV5CB763.js} +5 -5
- package/dist/{chunk-YLKV6LIU.js.map → chunk-KV5CB763.js.map} +1 -1
- package/dist/cli.js +1 -1
- package/dist/hub-ASHTCSDG.js +4 -0
- package/dist/hub-ASHTCSDG.js.map +1 -0
- package/dist/mcp.js +1 -1
- package/dist/ops.d.ts +27 -27
- package/dist/plugins/index.js +1 -1
- package/dist/run-AYEEUZVG.js +3 -0
- package/dist/run-AYEEUZVG.js.map +1 -0
- package/examples/tour.poney +498 -75
- package/examples/walkthrough.poney +5 -5
- package/package.json +7 -7
- package/studio/assets/{dist-_ey1iXf6.js → dist-Db6f3Sb_.js} +1 -1
- package/studio/assets/{elk.bundled-Bw5WzyyE.js → elk.bundled-Iz862-nW.js} +1 -1
- package/studio/assets/index-B9b62rng.js +889 -0
- package/studio/assets/index-CREHDNTh.css +1 -0
- package/studio/assets/src-2FlYo1t7.js +88 -0
- package/studio/index.html +2 -2
- package/dist/chunk-BCOS4LFB.js.map +0 -1
- package/dist/hub-FERXNPJS.js +0 -4
- package/dist/hub-FERXNPJS.js.map +0 -1
- package/dist/run-25PP2HWH.js +0 -3
- package/dist/run-25PP2HWH.js.map +0 -1
- package/studio/assets/index-B-C2JUUu.css +0 -1
- package/studio/assets/index-DOjop_HJ.js +0 -889
- package/studio/assets/src-Br__iChL.js +0 -88
package/examples/tour.poney
CHANGED
|
@@ -1,30 +1,196 @@
|
|
|
1
1
|
{
|
|
2
|
-
"poneyVersion": "0.
|
|
3
|
-
"project": {
|
|
2
|
+
"poneyVersion": "0.2.0",
|
|
3
|
+
"project": {
|
|
4
|
+
"id": "acme-notes",
|
|
5
|
+
"name": "Acme Notes",
|
|
6
|
+
"description": "A note-taking web app."
|
|
7
|
+
},
|
|
4
8
|
"model": {
|
|
5
9
|
"entities": [
|
|
6
|
-
{
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
{
|
|
11
|
+
"id": "user",
|
|
12
|
+
"kind": "person",
|
|
13
|
+
"name": "User",
|
|
14
|
+
"summary": "Writes and searches notes."
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "web",
|
|
18
|
+
"kind": "web-app",
|
|
19
|
+
"name": "Web app",
|
|
20
|
+
"summary": "The editor in the browser.",
|
|
21
|
+
"technology": "React",
|
|
22
|
+
"sourceRefs": [
|
|
23
|
+
{
|
|
24
|
+
"path": "web/src"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "editor",
|
|
30
|
+
"kind": "component",
|
|
31
|
+
"name": "Editor",
|
|
32
|
+
"summary": "Turns key presses into edits.",
|
|
33
|
+
"parent": "web",
|
|
34
|
+
"sourceRefs": [
|
|
35
|
+
{
|
|
36
|
+
"path": "web/src/editor"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"id": "sync",
|
|
42
|
+
"kind": "component",
|
|
43
|
+
"name": "Sync client",
|
|
44
|
+
"summary": "Sends edits to the API, a second after typing stops.",
|
|
45
|
+
"parent": "web",
|
|
46
|
+
"sourceRefs": [
|
|
47
|
+
{
|
|
48
|
+
"path": "web/src/sync/client.ts",
|
|
49
|
+
"symbol": "flush"
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "api",
|
|
55
|
+
"kind": "service",
|
|
56
|
+
"name": "Notes API",
|
|
57
|
+
"summary": "Keeps notes and who may read them.",
|
|
58
|
+
"technology": "Node, Fastify",
|
|
59
|
+
"sourceRefs": [
|
|
60
|
+
{
|
|
61
|
+
"path": "api/src"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"id": "router",
|
|
67
|
+
"kind": "component",
|
|
68
|
+
"name": "Routes",
|
|
69
|
+
"summary": "Every HTTP route, in one file.",
|
|
70
|
+
"parent": "api",
|
|
71
|
+
"sourceRefs": [
|
|
72
|
+
{
|
|
73
|
+
"path": "api/src/routes.ts"
|
|
74
|
+
}
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"id": "auth",
|
|
79
|
+
"kind": "component",
|
|
80
|
+
"name": "Sessions",
|
|
81
|
+
"summary": "Finds the user from the session cookie.",
|
|
82
|
+
"parent": "api",
|
|
83
|
+
"sourceRefs": [
|
|
84
|
+
{
|
|
85
|
+
"path": "api/src/auth/session.ts",
|
|
86
|
+
"symbol": "requireUser"
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"id": "notes",
|
|
92
|
+
"kind": "component",
|
|
93
|
+
"name": "Notes",
|
|
94
|
+
"summary": "Saves notes, with a version check.",
|
|
95
|
+
"parent": "api",
|
|
96
|
+
"sourceRefs": [
|
|
97
|
+
{
|
|
98
|
+
"path": "api/src/notes/save.ts",
|
|
99
|
+
"symbol": "saveNote"
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"id": "search",
|
|
105
|
+
"kind": "component",
|
|
106
|
+
"name": "Search",
|
|
107
|
+
"summary": "Keeps the search index up to date.",
|
|
108
|
+
"parent": "api",
|
|
109
|
+
"sourceRefs": [
|
|
110
|
+
{
|
|
111
|
+
"path": "api/src/search/queue.ts"
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"id": "db",
|
|
117
|
+
"kind": "database",
|
|
118
|
+
"name": "Postgres",
|
|
119
|
+
"summary": "Notes, users and sessions."
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"id": "index",
|
|
123
|
+
"kind": "database",
|
|
124
|
+
"name": "Search index",
|
|
125
|
+
"summary": "Full-text index of every note.",
|
|
126
|
+
"technology": "Meilisearch"
|
|
127
|
+
}
|
|
17
128
|
],
|
|
18
129
|
"relationships": [
|
|
19
|
-
{
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
{
|
|
27
|
-
|
|
130
|
+
{
|
|
131
|
+
"id": "r-user-web",
|
|
132
|
+
"kind": "uses",
|
|
133
|
+
"source": "user",
|
|
134
|
+
"target": "web",
|
|
135
|
+
"label": "Writes notes in"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
"id": "r-editor-sync",
|
|
139
|
+
"kind": "calls",
|
|
140
|
+
"source": "editor",
|
|
141
|
+
"target": "sync",
|
|
142
|
+
"label": "Hands over edits"
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
"id": "r-sync-router",
|
|
146
|
+
"kind": "calls",
|
|
147
|
+
"source": "sync",
|
|
148
|
+
"target": "router",
|
|
149
|
+
"label": "PUT /notes/:id",
|
|
150
|
+
"protocol": "HTTPS"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"id": "r-router-auth",
|
|
154
|
+
"kind": "calls",
|
|
155
|
+
"source": "router",
|
|
156
|
+
"target": "auth",
|
|
157
|
+
"label": "Checks the session"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"id": "r-router-notes",
|
|
161
|
+
"kind": "calls",
|
|
162
|
+
"source": "router",
|
|
163
|
+
"target": "notes",
|
|
164
|
+
"label": "Calls saveNote"
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"id": "r-auth-db",
|
|
168
|
+
"kind": "reads",
|
|
169
|
+
"source": "auth",
|
|
170
|
+
"target": "db",
|
|
171
|
+
"label": "Reads sessions"
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
"id": "r-notes-db",
|
|
175
|
+
"kind": "writes",
|
|
176
|
+
"source": "notes",
|
|
177
|
+
"target": "db",
|
|
178
|
+
"label": "Writes the note row"
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"id": "r-notes-search",
|
|
182
|
+
"kind": "publishes",
|
|
183
|
+
"source": "notes",
|
|
184
|
+
"target": "search",
|
|
185
|
+
"label": "Queues a re-index"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"id": "r-search-index",
|
|
189
|
+
"kind": "writes",
|
|
190
|
+
"source": "search",
|
|
191
|
+
"target": "index",
|
|
192
|
+
"label": "Updates the index"
|
|
193
|
+
}
|
|
28
194
|
],
|
|
29
195
|
"behaviors": [
|
|
30
196
|
{
|
|
@@ -32,13 +198,55 @@
|
|
|
32
198
|
"kind": "interaction",
|
|
33
199
|
"name": "Save a note",
|
|
34
200
|
"summary": "One save, from the editor to Postgres.",
|
|
35
|
-
"participants": [
|
|
201
|
+
"participants": [
|
|
202
|
+
"sync",
|
|
203
|
+
"router",
|
|
204
|
+
"auth",
|
|
205
|
+
"notes",
|
|
206
|
+
"db",
|
|
207
|
+
"search"
|
|
208
|
+
],
|
|
36
209
|
"steps": [
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
210
|
+
{
|
|
211
|
+
"type": "message",
|
|
212
|
+
"id": "m1",
|
|
213
|
+
"kind": "call",
|
|
214
|
+
"from": "sync",
|
|
215
|
+
"to": "router",
|
|
216
|
+
"label": "PUT /notes/:id with the version"
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
"type": "message",
|
|
220
|
+
"id": "m2",
|
|
221
|
+
"kind": "call",
|
|
222
|
+
"from": "router",
|
|
223
|
+
"to": "auth",
|
|
224
|
+
"label": "Check the session cookie"
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
"type": "message",
|
|
228
|
+
"id": "m3",
|
|
229
|
+
"kind": "return",
|
|
230
|
+
"from": "auth",
|
|
231
|
+
"to": "router",
|
|
232
|
+
"label": "User id"
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
"type": "message",
|
|
236
|
+
"id": "m4",
|
|
237
|
+
"kind": "call",
|
|
238
|
+
"from": "router",
|
|
239
|
+
"to": "notes",
|
|
240
|
+
"label": "saveNote(user, id, edit)"
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
"type": "message",
|
|
244
|
+
"id": "m5",
|
|
245
|
+
"kind": "call",
|
|
246
|
+
"from": "notes",
|
|
247
|
+
"to": "db",
|
|
248
|
+
"label": "UPDATE … WHERE version = $v"
|
|
249
|
+
},
|
|
42
250
|
{
|
|
43
251
|
"type": "fragment",
|
|
44
252
|
"id": "f-version",
|
|
@@ -48,21 +256,63 @@
|
|
|
48
256
|
{
|
|
49
257
|
"guard": "one row updated",
|
|
50
258
|
"steps": [
|
|
51
|
-
{
|
|
52
|
-
|
|
53
|
-
|
|
259
|
+
{
|
|
260
|
+
"type": "message",
|
|
261
|
+
"id": "m6",
|
|
262
|
+
"kind": "return",
|
|
263
|
+
"from": "db",
|
|
264
|
+
"to": "notes",
|
|
265
|
+
"label": "1 row"
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
"type": "message",
|
|
269
|
+
"id": "m7",
|
|
270
|
+
"kind": "async",
|
|
271
|
+
"from": "notes",
|
|
272
|
+
"to": "search",
|
|
273
|
+
"label": "Queue a re-index"
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
"type": "message",
|
|
277
|
+
"id": "m8",
|
|
278
|
+
"kind": "return",
|
|
279
|
+
"from": "notes",
|
|
280
|
+
"to": "router",
|
|
281
|
+
"label": "Note, version + 1"
|
|
282
|
+
}
|
|
54
283
|
]
|
|
55
284
|
},
|
|
56
285
|
{
|
|
57
286
|
"guard": "no row: someone saved first",
|
|
58
287
|
"steps": [
|
|
59
|
-
{
|
|
60
|
-
|
|
288
|
+
{
|
|
289
|
+
"type": "message",
|
|
290
|
+
"id": "m9",
|
|
291
|
+
"kind": "return",
|
|
292
|
+
"from": "db",
|
|
293
|
+
"to": "notes",
|
|
294
|
+
"label": "0 rows"
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
"type": "message",
|
|
298
|
+
"id": "m10",
|
|
299
|
+
"kind": "return",
|
|
300
|
+
"from": "notes",
|
|
301
|
+
"to": "router",
|
|
302
|
+
"label": "Conflict"
|
|
303
|
+
}
|
|
61
304
|
]
|
|
62
305
|
}
|
|
63
306
|
]
|
|
64
307
|
},
|
|
65
|
-
{
|
|
308
|
+
{
|
|
309
|
+
"type": "message",
|
|
310
|
+
"id": "m11",
|
|
311
|
+
"kind": "return",
|
|
312
|
+
"from": "router",
|
|
313
|
+
"to": "sync",
|
|
314
|
+
"label": "200 with the note, or 409"
|
|
315
|
+
}
|
|
66
316
|
]
|
|
67
317
|
}
|
|
68
318
|
]
|
|
@@ -74,8 +324,23 @@
|
|
|
74
324
|
"title": "Acme Notes",
|
|
75
325
|
"description": "The two apps and the two stores.",
|
|
76
326
|
"category": "walkthrough",
|
|
77
|
-
"entities": [
|
|
78
|
-
|
|
327
|
+
"entities": [
|
|
328
|
+
"user",
|
|
329
|
+
"web",
|
|
330
|
+
"editor",
|
|
331
|
+
"sync",
|
|
332
|
+
"api",
|
|
333
|
+
"router",
|
|
334
|
+
"auth",
|
|
335
|
+
"notes",
|
|
336
|
+
"search",
|
|
337
|
+
"db",
|
|
338
|
+
"index"
|
|
339
|
+
],
|
|
340
|
+
"collapsed": [
|
|
341
|
+
"web",
|
|
342
|
+
"api"
|
|
343
|
+
]
|
|
79
344
|
}
|
|
80
345
|
],
|
|
81
346
|
"walkthroughs": [
|
|
@@ -84,7 +349,11 @@
|
|
|
84
349
|
"kind": "tour",
|
|
85
350
|
"title": "How Acme Notes saves a note",
|
|
86
351
|
"summary": "A first walk through the Acme Notes code: its parts, and the path of one save from the editor to the database.",
|
|
87
|
-
"source": {
|
|
352
|
+
"source": {
|
|
353
|
+
"kind": "Repository",
|
|
354
|
+
"repository": "acme/notes",
|
|
355
|
+
"head": "4f2c9a1"
|
|
356
|
+
},
|
|
88
357
|
"story": {
|
|
89
358
|
"text": "Acme Notes is a web editor for notes, with a small API behind it. People type; the app saves a second after they stop, and search finds the note a few seconds later. This tour follows one save. It leaves out sign-up, sharing and billing."
|
|
90
359
|
},
|
|
@@ -92,12 +361,30 @@
|
|
|
92
361
|
"verdict": {
|
|
93
362
|
"risk": "routine",
|
|
94
363
|
"facts": [
|
|
95
|
-
{
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
364
|
+
{
|
|
365
|
+
"label": "Stack",
|
|
366
|
+
"value": "TypeScript: React in web/, Fastify in api/"
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
"label": "Run it",
|
|
370
|
+
"value": "npm run dev, with Postgres from docker compose"
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
"label": "Tests",
|
|
374
|
+
"value": "npm test; the API tests need Postgres"
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
"label": "Read first",
|
|
378
|
+
"value": "api/src/routes.ts, then api/src/notes/save.ts"
|
|
379
|
+
}
|
|
99
380
|
],
|
|
100
|
-
"findings": [
|
|
381
|
+
"findings": [
|
|
382
|
+
{
|
|
383
|
+
"text": "Search lags a few seconds behind a save: a note that was just saved may not be found yet.",
|
|
384
|
+
"severity": "note",
|
|
385
|
+
"scene": "s-search"
|
|
386
|
+
}
|
|
387
|
+
]
|
|
101
388
|
},
|
|
102
389
|
"scenes": [
|
|
103
390
|
{
|
|
@@ -106,25 +393,60 @@
|
|
|
106
393
|
"text": "The web app and the API are the two big parts; open them to see their modules. Postgres keeps everything that matters. The search index is a copy that can be rebuilt.",
|
|
107
394
|
"view": "tour-map",
|
|
108
395
|
"callouts": [
|
|
109
|
-
{
|
|
110
|
-
|
|
111
|
-
|
|
396
|
+
{
|
|
397
|
+
"target": "entity:web",
|
|
398
|
+
"text": "The browser app. Editing and syncing are separate modules."
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
"target": "entity:api",
|
|
402
|
+
"text": "One Fastify service. Routes, sessions, notes and search."
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
"target": "entity:index",
|
|
406
|
+
"text": "Only a copy: the API can rebuild it from Postgres."
|
|
407
|
+
}
|
|
112
408
|
]
|
|
113
409
|
},
|
|
114
410
|
{
|
|
115
411
|
"id": "s-entry",
|
|
116
412
|
"title": "Every request enters through one file",
|
|
117
413
|
"text": "All HTTP routes are in api/src/routes.ts. Each route first finds the user from the session, then calls one function in a module. To find what a URL does, start here.",
|
|
118
|
-
"view": {
|
|
119
|
-
|
|
120
|
-
|
|
414
|
+
"view": {
|
|
415
|
+
"type": "map",
|
|
416
|
+
"title": "Inside the API",
|
|
417
|
+
"entities": [
|
|
418
|
+
"sync",
|
|
419
|
+
"api",
|
|
420
|
+
"router",
|
|
421
|
+
"auth",
|
|
422
|
+
"notes",
|
|
423
|
+
"search",
|
|
424
|
+
"db"
|
|
425
|
+
]
|
|
426
|
+
},
|
|
427
|
+
"focus": [
|
|
428
|
+
"entity:router",
|
|
429
|
+
"relationship:r-router-auth",
|
|
430
|
+
"relationship:r-router-notes"
|
|
431
|
+
],
|
|
432
|
+
"callouts": [
|
|
433
|
+
{
|
|
434
|
+
"target": "entity:router",
|
|
435
|
+
"text": "Routes stay thin: they check the session and call a module."
|
|
436
|
+
}
|
|
437
|
+
],
|
|
121
438
|
"code": [
|
|
122
439
|
{
|
|
123
440
|
"path": "api/src/routes.ts",
|
|
124
441
|
"title": "The save route",
|
|
125
442
|
"start": 31,
|
|
126
443
|
"text": "app.put('/notes/:id', async (req, reply) => {\n const user = await requireUser(req)\n const result = await saveNote(user, req.params.id, req.body)\n if (result.conflict) return reply.code(409).send(result.current)\n return result.note\n})",
|
|
127
|
-
"notes": [
|
|
444
|
+
"notes": [
|
|
445
|
+
{
|
|
446
|
+
"line": 32,
|
|
447
|
+
"text": "Throws a 401 when the cookie is missing or old."
|
|
448
|
+
}
|
|
449
|
+
]
|
|
128
450
|
}
|
|
129
451
|
]
|
|
130
452
|
},
|
|
@@ -132,29 +454,75 @@
|
|
|
132
454
|
"id": "s-save",
|
|
133
455
|
"title": "One save, from the editor to Postgres",
|
|
134
456
|
"text": "The sync client sends the whole note with the version it last saw. The API checks the session, then updates the row only if the version still matches. Search is told later, without waiting.",
|
|
135
|
-
"view": {
|
|
457
|
+
"view": {
|
|
458
|
+
"type": "sequence",
|
|
459
|
+
"title": "Save a note",
|
|
460
|
+
"interaction": "save-note"
|
|
461
|
+
},
|
|
136
462
|
"callouts": [
|
|
137
|
-
{
|
|
138
|
-
|
|
139
|
-
|
|
463
|
+
{
|
|
464
|
+
"target": "message:save-note:m1",
|
|
465
|
+
"text": "The client sends the version it started from."
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
"target": "message:save-note:m5",
|
|
469
|
+
"text": "One UPDATE does the check and the write together."
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
"target": "message:save-note:m7",
|
|
473
|
+
"text": "Search is queued; the save does not wait for it."
|
|
474
|
+
}
|
|
140
475
|
],
|
|
141
476
|
"trace": [
|
|
142
|
-
{
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
{
|
|
147
|
-
|
|
477
|
+
{
|
|
478
|
+
"ref": "message:save-note:m1",
|
|
479
|
+
"caption": "The client sends the edit and its version."
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
"ref": "message:save-note:m2",
|
|
483
|
+
"caption": "Routes find the user from the cookie."
|
|
484
|
+
},
|
|
485
|
+
{
|
|
486
|
+
"ref": "message:save-note:m4",
|
|
487
|
+
"caption": "Routes hand the edit to saveNote."
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
"ref": "message:save-note:m5",
|
|
491
|
+
"caption": "One UPDATE checks the version and writes."
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
"ref": "message:save-note:m7",
|
|
495
|
+
"caption": "Search is queued, without waiting."
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
"ref": "message:save-note:m11",
|
|
499
|
+
"caption": "The client gets the saved note back."
|
|
500
|
+
}
|
|
501
|
+
],
|
|
502
|
+
"effects": [
|
|
503
|
+
{
|
|
504
|
+
"target": "message:save-note:m7",
|
|
505
|
+
"as": "flow"
|
|
506
|
+
}
|
|
507
|
+
],
|
|
508
|
+
"badges": [
|
|
509
|
+
{
|
|
510
|
+
"target": "message:save-note:m5",
|
|
511
|
+
"text": "p95 12 ms"
|
|
512
|
+
}
|
|
148
513
|
],
|
|
149
|
-
"effects": [{ "target": "message:save-note:m7", "as": "flow" }],
|
|
150
|
-
"badges": [{ "target": "message:save-note:m5", "text": "p95 12 ms" }],
|
|
151
514
|
"code": [
|
|
152
515
|
{
|
|
153
516
|
"path": "api/src/notes/save.ts",
|
|
154
517
|
"title": "saveNote",
|
|
155
518
|
"start": 14,
|
|
156
519
|
"text": " const rows = await db.query(\n 'UPDATE notes SET body = $1, version = version + 1 WHERE id = $2 AND version = $3 RETURNING *',\n [edit.body, id, edit.version],\n )\n if (rows.length === 0) return { conflict: true, current: await findNote(id) }\n await queueReindex(id)\n return { note: rows[0] }",
|
|
157
|
-
"notes": [
|
|
520
|
+
"notes": [
|
|
521
|
+
{
|
|
522
|
+
"line": 18,
|
|
523
|
+
"text": "No row means another tab saved first."
|
|
524
|
+
}
|
|
525
|
+
]
|
|
158
526
|
}
|
|
159
527
|
]
|
|
160
528
|
},
|
|
@@ -163,30 +531,85 @@
|
|
|
163
531
|
"title": "Two tabs, one note: the version check",
|
|
164
532
|
"text": "When two tabs edit the same note, the second save finds no row with its version. The API answers 409 with the note as it is now, and the sync client shows both versions to the user.",
|
|
165
533
|
"risk": "look",
|
|
166
|
-
"view": {
|
|
167
|
-
|
|
534
|
+
"view": {
|
|
535
|
+
"type": "sequence",
|
|
536
|
+
"title": "Save a note: a conflict",
|
|
537
|
+
"interaction": "save-note"
|
|
538
|
+
},
|
|
539
|
+
"focus": [
|
|
540
|
+
"message:save-note:m5",
|
|
541
|
+
"message:save-note:m9",
|
|
542
|
+
"message:save-note:m10",
|
|
543
|
+
"message:save-note:m11"
|
|
544
|
+
],
|
|
168
545
|
"cases": [
|
|
169
|
-
{
|
|
170
|
-
|
|
546
|
+
{
|
|
547
|
+
"when": "The version matches",
|
|
548
|
+
"then": "The row is updated and the version goes up by one"
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
"when": "Another tab saved first",
|
|
552
|
+
"then": "409, with the current note",
|
|
553
|
+
"note": "Nothing is written."
|
|
554
|
+
}
|
|
555
|
+
],
|
|
556
|
+
"proof": [
|
|
557
|
+
{
|
|
558
|
+
"text": "A stale version gets a 409 and changes nothing",
|
|
559
|
+
"source": "api/test/notes.test.ts",
|
|
560
|
+
"test": "returns 409 when the version is stale"
|
|
561
|
+
}
|
|
171
562
|
],
|
|
172
|
-
"proof": [{ "text": "A stale version gets a 409 and changes nothing", "source": "api/test/notes.test.ts", "test": "returns 409 when the version is stale" }],
|
|
173
563
|
"question": "Where would you change the code to merge the two versions on the server?"
|
|
174
564
|
},
|
|
175
565
|
{
|
|
176
566
|
"id": "s-search",
|
|
177
567
|
"title": "Search is updated later, not at once",
|
|
178
568
|
"text": "Saving only queues a re-index. A worker in the Search module updates the index a few seconds later. If the index is lost, a script rebuilds it from Postgres.",
|
|
179
|
-
"view": {
|
|
180
|
-
|
|
181
|
-
|
|
569
|
+
"view": {
|
|
570
|
+
"type": "map",
|
|
571
|
+
"title": "Search",
|
|
572
|
+
"entities": [
|
|
573
|
+
"api",
|
|
574
|
+
"notes",
|
|
575
|
+
"search",
|
|
576
|
+
"db",
|
|
577
|
+
"index"
|
|
578
|
+
]
|
|
579
|
+
},
|
|
580
|
+
"focus": [
|
|
581
|
+
"relationship:r-notes-search",
|
|
582
|
+
"relationship:r-search-index"
|
|
583
|
+
],
|
|
584
|
+
"callouts": [
|
|
585
|
+
{
|
|
586
|
+
"target": "relationship:r-notes-search",
|
|
587
|
+
"text": "A queue in Postgres, not a message broker."
|
|
588
|
+
}
|
|
589
|
+
],
|
|
182
590
|
"effects": [
|
|
183
|
-
{
|
|
184
|
-
|
|
185
|
-
|
|
591
|
+
{
|
|
592
|
+
"target": "relationship:r-notes-search",
|
|
593
|
+
"as": "flow"
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
"target": "relationship:r-search-index",
|
|
597
|
+
"as": "slow"
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
"target": "entity:index",
|
|
601
|
+
"as": "attention"
|
|
602
|
+
}
|
|
186
603
|
],
|
|
187
604
|
"badges": [
|
|
188
|
-
{
|
|
189
|
-
|
|
605
|
+
{
|
|
606
|
+
"target": "relationship:r-search-index",
|
|
607
|
+
"text": "2–5 s behind"
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
"target": "entity:index",
|
|
611
|
+
"text": "120 k notes"
|
|
612
|
+
}
|
|
190
613
|
]
|
|
191
614
|
}
|
|
192
615
|
]
|