@velajs/live-protocol 1.0.0 → 1.0.1

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/dist/fixtures.js DELETED
@@ -1,592 +0,0 @@
1
- /**
2
- * Golden wire fixtures — the drift tripwire. The server suite (@velajs/vela)
3
- * and the client suite (@velajs/client) both run these through
4
- * `runProtocolConformance`, so an encoding change on either side fails a test
5
- * instead of surfacing as a production incompatibility.
6
- *
7
- * `wire` strings are byte-exact: they pin the canonical key order of
8
- * `encodeLiveEnvelope`. Do not reformat them.
9
- */ export const FRAME_FIXTURES = [
10
- {
11
- name: 'sub (full)',
12
- frame: {
13
- t: 'sub',
14
- sub: 's1',
15
- query: 'todos.list',
16
- args: {
17
- listId: 'l1'
18
- },
19
- sinceCursor: 42,
20
- sinceEpoch: 'e-1',
21
- key: 'id',
22
- v: 1
23
- },
24
- wire: '{"event":"$live","data":{"t":"sub","sub":"s1","query":"todos.list","args":{"listId":"l1"},"sinceCursor":42,"sinceEpoch":"e-1","key":"id","v":1}}'
25
- },
26
- {
27
- name: 'sub (minimal)',
28
- frame: {
29
- t: 'sub',
30
- sub: 's2',
31
- query: 'todos.all'
32
- },
33
- wire: '{"event":"$live","data":{"t":"sub","sub":"s2","query":"todos.all"}}'
34
- },
35
- {
36
- name: 'unsub',
37
- frame: {
38
- t: 'unsub',
39
- sub: 's1'
40
- },
41
- wire: '{"event":"$live","data":{"t":"unsub","sub":"s1"}}'
42
- },
43
- {
44
- name: 'presence',
45
- frame: {
46
- t: 'presence',
47
- room: 'r1',
48
- meta: {
49
- name: 'kauan'
50
- }
51
- },
52
- wire: '{"event":"$live","data":{"t":"presence","room":"r1","meta":{"name":"kauan"}}}'
53
- },
54
- {
55
- name: 'ack',
56
- frame: {
57
- t: 'ack',
58
- sub: 's1'
59
- },
60
- wire: '{"event":"$live","data":{"t":"ack","sub":"s1"}}'
61
- },
62
- {
63
- name: 'data',
64
- frame: {
65
- t: 'data',
66
- sub: 's1',
67
- snapshot: [
68
- {
69
- id: 'a',
70
- text: 'hi'
71
- }
72
- ],
73
- cursor: 7,
74
- epoch: 'e-1'
75
- },
76
- wire: '{"event":"$live","data":{"t":"data","sub":"s1","snapshot":[{"id":"a","text":"hi"}],"cursor":7,"epoch":"e-1"}}'
77
- },
78
- {
79
- name: 'data (cold, no cursor)',
80
- frame: {
81
- t: 'data',
82
- sub: 's1',
83
- snapshot: null
84
- },
85
- wire: '{"event":"$live","data":{"t":"data","sub":"s1","snapshot":null}}'
86
- },
87
- {
88
- name: 'delta',
89
- frame: {
90
- t: 'delta',
91
- sub: 's1',
92
- ops: [
93
- {
94
- op: 'delete',
95
- key: 'a'
96
- },
97
- {
98
- op: 'insert',
99
- key: 'b',
100
- row: {
101
- id: 'b'
102
- },
103
- before: null
104
- },
105
- {
106
- op: 'update',
107
- key: 'c',
108
- row: {
109
- id: 'c',
110
- n: 2
111
- }
112
- }
113
- ],
114
- cursor: 8,
115
- epoch: 'e-1'
116
- },
117
- wire: '{"event":"$live","data":{"t":"delta","sub":"s1","ops":[{"op":"delete","key":"a"},{"op":"insert","key":"b","row":{"id":"b"},"before":null},{"op":"update","key":"c","row":{"id":"c","n":2}}],"cursor":8,"epoch":"e-1"}}'
118
- },
119
- {
120
- name: 'settled',
121
- frame: {
122
- t: 'settled',
123
- sub: 's1',
124
- cursor: 9,
125
- epoch: 'e-1'
126
- },
127
- wire: '{"event":"$live","data":{"t":"settled","sub":"s1","cursor":9,"epoch":"e-1"}}'
128
- },
129
- {
130
- name: 'resume',
131
- frame: {
132
- t: 'resume',
133
- sub: 's1',
134
- cursor: 42,
135
- epoch: 'e-1'
136
- },
137
- wire: '{"event":"$live","data":{"t":"resume","sub":"s1","cursor":42,"epoch":"e-1"}}'
138
- },
139
- {
140
- name: 'error (subscription)',
141
- frame: {
142
- t: 'error',
143
- sub: 's1',
144
- code: 'forbidden',
145
- message: 'nope',
146
- fatal: true
147
- },
148
- wire: '{"event":"$live","data":{"t":"error","sub":"s1","code":"forbidden","message":"nope","fatal":true}}'
149
- },
150
- {
151
- name: 'error (connection)',
152
- frame: {
153
- t: 'error',
154
- code: 'unsupported_protocol',
155
- message: 'v2 required',
156
- fatal: true
157
- },
158
- wire: '{"event":"$live","data":{"t":"error","code":"unsupported_protocol","message":"v2 required","fatal":true}}'
159
- }
160
- ];
161
- export const DELTA_FIXTURES = [
162
- {
163
- name: 'noop',
164
- previous: [],
165
- next: [],
166
- expected: []
167
- },
168
- {
169
- name: 'insert into empty',
170
- previous: [],
171
- next: [
172
- {
173
- id: 'a',
174
- n: 1
175
- }
176
- ],
177
- expected: [
178
- {
179
- op: 'insert',
180
- key: 'a',
181
- row: {
182
- id: 'a',
183
- n: 1
184
- },
185
- before: null
186
- }
187
- ]
188
- },
189
- {
190
- name: 'insert head',
191
- previous: [
192
- {
193
- id: 'b'
194
- }
195
- ],
196
- next: [
197
- {
198
- id: 'a'
199
- },
200
- {
201
- id: 'b'
202
- }
203
- ],
204
- expected: [
205
- {
206
- op: 'insert',
207
- key: 'a',
208
- row: {
209
- id: 'a'
210
- },
211
- before: 'b'
212
- }
213
- ]
214
- },
215
- {
216
- name: 'insert middle',
217
- previous: [
218
- {
219
- id: 'a'
220
- },
221
- {
222
- id: 'c'
223
- }
224
- ],
225
- next: [
226
- {
227
- id: 'a'
228
- },
229
- {
230
- id: 'b'
231
- },
232
- {
233
- id: 'c'
234
- }
235
- ],
236
- expected: [
237
- {
238
- op: 'insert',
239
- key: 'b',
240
- row: {
241
- id: 'b'
242
- },
243
- before: 'c'
244
- }
245
- ]
246
- },
247
- {
248
- name: 'insert tail',
249
- previous: [
250
- {
251
- id: 'a'
252
- }
253
- ],
254
- next: [
255
- {
256
- id: 'a'
257
- },
258
- {
259
- id: 'b'
260
- }
261
- ],
262
- expected: [
263
- {
264
- op: 'insert',
265
- key: 'b',
266
- row: {
267
- id: 'b'
268
- },
269
- before: null
270
- }
271
- ]
272
- },
273
- {
274
- name: 'update in place',
275
- previous: [
276
- {
277
- id: 'a',
278
- n: 1
279
- }
280
- ],
281
- next: [
282
- {
283
- id: 'a',
284
- n: 2
285
- }
286
- ],
287
- expected: [
288
- {
289
- op: 'update',
290
- key: 'a',
291
- row: {
292
- id: 'a',
293
- n: 2
294
- }
295
- }
296
- ]
297
- },
298
- {
299
- name: 'delete one',
300
- previous: [
301
- {
302
- id: 'a'
303
- },
304
- {
305
- id: 'b'
306
- }
307
- ],
308
- next: [
309
- {
310
- id: 'a'
311
- }
312
- ],
313
- expected: [
314
- {
315
- op: 'delete',
316
- key: 'b'
317
- }
318
- ]
319
- },
320
- {
321
- name: 'mixed delete+update+insert',
322
- previous: [
323
- {
324
- id: 'a',
325
- n: 1
326
- },
327
- {
328
- id: 'b',
329
- n: 1
330
- },
331
- {
332
- id: 'c',
333
- n: 1
334
- }
335
- ],
336
- next: [
337
- {
338
- id: 'b',
339
- n: 2
340
- },
341
- {
342
- id: 'd',
343
- n: 1
344
- },
345
- {
346
- id: 'c',
347
- n: 1
348
- }
349
- ],
350
- expected: [
351
- {
352
- op: 'delete',
353
- key: 'a'
354
- },
355
- {
356
- op: 'update',
357
- key: 'b',
358
- row: {
359
- id: 'b',
360
- n: 2
361
- }
362
- },
363
- {
364
- op: 'insert',
365
- key: 'd',
366
- row: {
367
- id: 'd',
368
- n: 1
369
- },
370
- before: 'c'
371
- }
372
- ]
373
- },
374
- {
375
- name: 'stacked inserts share an anchor in next order',
376
- previous: [
377
- {
378
- id: 'z'
379
- }
380
- ],
381
- next: [
382
- {
383
- id: 'x'
384
- },
385
- {
386
- id: 'y'
387
- },
388
- {
389
- id: 'z'
390
- }
391
- ],
392
- expected: [
393
- {
394
- op: 'insert',
395
- key: 'x',
396
- row: {
397
- id: 'x'
398
- },
399
- before: 'z'
400
- },
401
- {
402
- op: 'insert',
403
- key: 'y',
404
- row: {
405
- id: 'y'
406
- },
407
- before: 'z'
408
- }
409
- ]
410
- },
411
- {
412
- name: 'custom key field',
413
- previous: [
414
- {
415
- _key: 'a',
416
- n: 1
417
- }
418
- ],
419
- next: [
420
- {
421
- _key: 'a',
422
- n: 2
423
- }
424
- ],
425
- keyField: '_key',
426
- expected: [
427
- {
428
- op: 'update',
429
- key: 'a',
430
- row: {
431
- _key: 'a',
432
- n: 2
433
- }
434
- }
435
- ]
436
- },
437
- // ---- bail cases (expected: null → full snapshot) ----
438
- {
439
- name: 'bail: clear list (rule 5)',
440
- previous: [
441
- {
442
- id: 'a'
443
- },
444
- {
445
- id: 'b'
446
- }
447
- ],
448
- next: [],
449
- expected: null
450
- },
451
- {
452
- name: 'bail: near-total change (rule 5)',
453
- previous: [
454
- {
455
- id: 'a'
456
- },
457
- {
458
- id: 'b'
459
- }
460
- ],
461
- next: [
462
- {
463
- id: 'c'
464
- },
465
- {
466
- id: 'd'
467
- },
468
- {
469
- id: 'e'
470
- }
471
- ],
472
- expected: null
473
- },
474
- {
475
- name: 'bail: previous not array (rule 1)',
476
- previous: {
477
- id: 'a'
478
- },
479
- next: [
480
- {
481
- id: 'a'
482
- }
483
- ],
484
- expected: null
485
- },
486
- {
487
- name: 'bail: next not array (rule 1)',
488
- previous: [
489
- {
490
- id: 'a'
491
- }
492
- ],
493
- next: {
494
- id: 'a'
495
- },
496
- expected: null
497
- },
498
- {
499
- name: 'bail: row missing key (rule 2)',
500
- previous: [
501
- {
502
- id: 'a'
503
- }
504
- ],
505
- next: [
506
- {
507
- text: 'no key'
508
- }
509
- ],
510
- expected: null
511
- },
512
- {
513
- name: 'bail: non-string key (rule 2)',
514
- previous: [
515
- {
516
- id: 'a'
517
- }
518
- ],
519
- next: [
520
- {
521
- id: 5
522
- }
523
- ],
524
- expected: null
525
- },
526
- {
527
- name: 'bail: scalar row (rule 2)',
528
- previous: [
529
- {
530
- id: 'a'
531
- }
532
- ],
533
- next: [
534
- 'a'
535
- ],
536
- expected: null
537
- },
538
- {
539
- name: 'bail: duplicate key in previous (rule 3)',
540
- previous: [
541
- {
542
- id: 'a'
543
- },
544
- {
545
- id: 'a'
546
- }
547
- ],
548
- next: [
549
- {
550
- id: 'a'
551
- }
552
- ],
553
- expected: null
554
- },
555
- {
556
- name: 'bail: duplicate key in next (rule 3)',
557
- previous: [
558
- {
559
- id: 'a'
560
- }
561
- ],
562
- next: [
563
- {
564
- id: 'a'
565
- },
566
- {
567
- id: 'a'
568
- }
569
- ],
570
- expected: null
571
- },
572
- {
573
- name: 'bail: survivors reordered (rule 4)',
574
- previous: [
575
- {
576
- id: 'a'
577
- },
578
- {
579
- id: 'b'
580
- }
581
- ],
582
- next: [
583
- {
584
- id: 'b'
585
- },
586
- {
587
- id: 'a'
588
- }
589
- ],
590
- expected: null
591
- }
592
- ];