autobee 2.0.0-rc.30 → 2.0.0-rc.31

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.
@@ -280,8 +280,8 @@ const SystemWriterV0 = {
280
280
 
281
281
  return {
282
282
  version: 0,
283
- isIndexer: flags & 1,
284
- isRemoved: flags & 2,
283
+ isIndexer: (flags & 1) !== 0,
284
+ isRemoved: (flags & 2) !== 0,
285
285
  length: c.uint.decode(state)
286
286
  }
287
287
  }
@@ -300,11 +300,35 @@ function infoLegacyMap(info) {
300
300
  }
301
301
 
302
302
  function memberLegacyMap(m) {
303
+ const weight = m.isIndexer ? 2 : 1
304
+
303
305
  return {
304
306
  version: 0,
305
307
  isRemoved: m.isRemoved,
306
- weight: m.isIndexer ? 2 : 1,
307
- length: m.length
308
+ isOplog: false,
309
+ isGenesis: false,
310
+ weight,
311
+ maxWeight: weight,
312
+ length: m.length,
313
+ timestamp: 0
314
+ }
315
+ }
316
+
317
+ // a v3 node's witness is a signed attestation, which confers weight through a
318
+ // mechanism that no longer exists - it maps to null, so the node sorts at the
319
+ // standing its record already carries instead of failing to decode
320
+ function oplogLegacyMap(m) {
321
+ return {
322
+ version: m.version,
323
+ timestamp: m.timestamp,
324
+ links: m.links,
325
+ batch: m.batch,
326
+ views: m.views,
327
+ trusted: m.trusted,
328
+ witness: null,
329
+ approvals: null,
330
+ optimistic: m.optimistic,
331
+ value: m.value
308
332
  }
309
333
  }
310
334
 
@@ -314,5 +338,6 @@ module.exports = {
314
338
  OplogMessageV1,
315
339
  SystemWriterV0,
316
340
  infoLegacyMap,
317
- memberLegacyMap
341
+ memberLegacyMap,
342
+ oplogLegacyMap
318
343
  }
@@ -12,6 +12,36 @@ const VERSION = 1
12
12
  // eslint-disable-next-line no-unused-vars
13
13
  let version = VERSION
14
14
 
15
+ // array of bools, packed as a bitfield
16
+ const boolArray = {
17
+ preencode(state, m) {
18
+ c.uint.preencode(state, m.length)
19
+ state.end += Math.ceil(m.length / 8)
20
+ },
21
+ encode(state, m) {
22
+ c.uint.encode(state, m.length)
23
+ for (let i = 0; i < m.length; i += 8) {
24
+ let byte = 0
25
+ for (let j = 0; j < 8 && i + j < m.length; j++) {
26
+ if (m[i + j]) byte |= 1 << j
27
+ }
28
+ state.buffer[state.start++] = byte
29
+ }
30
+ },
31
+ decode(state) {
32
+ const n = c.uint.decode(state)
33
+ if (state.end - state.start < Math.ceil(n / 8)) throw new Error('Out of bounds')
34
+ const m = new Array(n)
35
+ for (let i = 0; i < n; i += 8) {
36
+ const byte = state.buffer[state.start++]
37
+ for (let j = 0; j < 8 && i + j < n; j++) {
38
+ m[i + j] = (byte & (1 << j)) !== 0
39
+ }
40
+ }
41
+ return m
42
+ }
43
+ }
44
+
15
45
  // @autobase-compat/checkout
16
46
  const encoding0 = {
17
47
  preencode(state, m) {
@@ -454,6 +484,9 @@ const encoding16 = {
454
484
 
455
485
  const encoding17 = external0.SystemWriterV0
456
486
 
487
+ // @autobee/system-info-v3.pending
488
+ const encoding18_5 = boolArray
489
+
457
490
  // @autobee/system-info-v3
458
491
  const encoding18 = {
459
492
  preencode(state, m) {
@@ -461,12 +494,13 @@ const encoding18 = {
461
494
  c.uint.preencode(state, m.flushes)
462
495
  encoding22.preencode(state, m.view)
463
496
  encoding18_3.preencode(state, m.heads)
464
- state.end++ // max flag is 1 so always one byte
497
+ state.end++ // max flag is 2 so always one byte
465
498
 
466
499
  if (m.indexers) encoding18_4.preencode(state, m.indexers)
500
+ if (m.pending) encoding18_5.preencode(state, m.pending)
467
501
  },
468
502
  encode(state, m) {
469
- const flags = m.indexers ? 1 : 0
503
+ const flags = (m.indexers ? 1 : 0) | (m.pending ? 2 : 0)
470
504
 
471
505
  c.uint.encode(state, m.timestamp)
472
506
  c.uint.encode(state, m.flushes)
@@ -475,6 +509,7 @@ const encoding18 = {
475
509
  c.uint.encode(state, flags)
476
510
 
477
511
  if (m.indexers) encoding18_4.encode(state, m.indexers)
512
+ if (m.pending) encoding18_5.encode(state, m.pending)
478
513
  },
479
514
  decode(state) {
480
515
  const v = c.uint.decode(state)
@@ -490,7 +525,8 @@ const encoding18 = {
490
525
  flushes: r1,
491
526
  view: r2,
492
527
  heads: r3,
493
- indexers: (flags & 1) !== 0 ? encoding18_4.decode(state) : null
528
+ indexers: (flags & 1) !== 0 ? encoding18_4.decode(state) : null,
529
+ pending: (flags & 2) !== 0 ? encoding18_5.decode(state) : null
494
530
  }
495
531
  }
496
532
  }
@@ -607,7 +643,7 @@ const encoding20 = {
607
643
  // @autobee/system-writer
608
644
  const encoding21 = {
609
645
  preencode(state, m) {
610
- const v = m.version ?? 4
646
+ const v = m.version ?? 5
611
647
  c.uint.preencode(state, v)
612
648
  switch (v) {
613
649
  case 0:
@@ -619,12 +655,15 @@ const encoding21 = {
619
655
  case 4:
620
656
  encoding20.preencode(state, m)
621
657
  break
658
+ case 5:
659
+ encoding34.preencode(state, m)
660
+ break
622
661
  default:
623
662
  throw new Error('Unsupported version')
624
663
  }
625
664
  },
626
665
  encode(state, m) {
627
- const v = m.version ?? 4
666
+ const v = m.version ?? 5
628
667
  c.uint.encode(state, v)
629
668
  switch (v) {
630
669
  case 0:
@@ -636,6 +675,9 @@ const encoding21 = {
636
675
  case 4:
637
676
  encoding20.encode(state, m)
638
677
  break
678
+ case 5:
679
+ encoding34.encode(state, m)
680
+ break
639
681
  default:
640
682
  throw new Error('Unsupported version')
641
683
  }
@@ -657,6 +699,10 @@ const encoding21 = {
657
699
  const decoded = encoding20.decode(state)
658
700
  return decoded
659
701
  }
702
+ case 5: {
703
+ const decoded = encoding34.decode(state)
704
+ return decoded
705
+ }
660
706
  default:
661
707
  throw new Error('Unsupported version')
662
708
  }
@@ -927,7 +973,7 @@ const encoding29 = {
927
973
  // @autobee/oplog
928
974
  const encoding30 = {
929
975
  preencode(state, m) {
930
- const v = m.version ?? 3
976
+ const v = m.version ?? 4
931
977
  c.uint.preencode(state, v)
932
978
  switch (v) {
933
979
  case 0:
@@ -942,12 +988,15 @@ const encoding30 = {
942
988
  case 3:
943
989
  encoding29.preencode(state, m)
944
990
  break
991
+ case 4:
992
+ encoding37.preencode(state, m)
993
+ break
945
994
  default:
946
995
  throw new Error('Unsupported version')
947
996
  }
948
997
  },
949
998
  encode(state, m) {
950
- const v = m.version ?? 3
999
+ const v = m.version ?? 4
951
1000
  c.uint.encode(state, v)
952
1001
  switch (v) {
953
1002
  case 0:
@@ -962,6 +1011,9 @@ const encoding30 = {
962
1011
  case 3:
963
1012
  encoding29.encode(state, m)
964
1013
  break
1014
+ case 4:
1015
+ encoding37.encode(state, m)
1016
+ break
965
1017
  default:
966
1018
  throw new Error('Unsupported version')
967
1019
  }
@@ -985,6 +1037,11 @@ const encoding30 = {
985
1037
  }
986
1038
  case 3: {
987
1039
  const decoded = encoding29.decode(state)
1040
+ const map = external0.oplogLegacyMap
1041
+ return map(decoded)
1042
+ }
1043
+ case 4: {
1044
+ const decoded = encoding37.decode(state)
988
1045
  return decoded
989
1046
  }
990
1047
  default:
@@ -1075,6 +1132,142 @@ const encoding33 = {
1075
1132
  }
1076
1133
  }
1077
1134
 
1135
+ // @autobee/system-writer-v5
1136
+ const encoding34 = {
1137
+ preencode(state, m) {
1138
+ state.end++ // max flag is 4 so always one byte
1139
+ c.uint.preencode(state, m.weight)
1140
+ c.uint.preencode(state, m.maxWeight)
1141
+ c.uint.preencode(state, m.length)
1142
+ c.uint.preencode(state, m.timestamp)
1143
+ },
1144
+ encode(state, m) {
1145
+ const flags = (m.isRemoved ? 1 : 0) | (m.isOplog ? 2 : 0) | (m.isGenesis ? 4 : 0)
1146
+
1147
+ c.uint.encode(state, flags)
1148
+ c.uint.encode(state, m.weight)
1149
+ c.uint.encode(state, m.maxWeight)
1150
+ c.uint.encode(state, m.length)
1151
+ c.uint.encode(state, m.timestamp)
1152
+ },
1153
+ decode(state) {
1154
+ const v = c.uint.decode(state)
1155
+ const flags = c.uint.decode(state)
1156
+
1157
+ return {
1158
+ version: v,
1159
+ isRemoved: (flags & 1) !== 0,
1160
+ isOplog: (flags & 2) !== 0,
1161
+ isGenesis: (flags & 4) !== 0,
1162
+ weight: c.uint.decode(state),
1163
+ maxWeight: c.uint.decode(state),
1164
+ length: c.uint.decode(state),
1165
+ timestamp: c.uint.decode(state)
1166
+ }
1167
+ }
1168
+ }
1169
+
1170
+ // @autobee/grant-witness
1171
+ const encoding35 = {
1172
+ preencode(state, m) {
1173
+ c.uint.preencode(state, m.weight)
1174
+ encoding22.preencode(state, m.link)
1175
+ },
1176
+ encode(state, m) {
1177
+ c.uint.encode(state, m.weight)
1178
+ encoding22.encode(state, m.link)
1179
+ },
1180
+ decode(state) {
1181
+ const r0 = c.uint.decode(state)
1182
+ const r1 = encoding22.decode(state)
1183
+
1184
+ return {
1185
+ weight: r0,
1186
+ link: r1
1187
+ }
1188
+ }
1189
+ }
1190
+
1191
+ // @autobee/approval
1192
+ const encoding36 = {
1193
+ preencode(state, m) {
1194
+ c.fixed32.preencode(state, m.key)
1195
+ c.uint.preencode(state, m.weight)
1196
+ },
1197
+ encode(state, m) {
1198
+ c.fixed32.encode(state, m.key)
1199
+ c.uint.encode(state, m.weight)
1200
+ },
1201
+ decode(state) {
1202
+ const r0 = c.fixed32.decode(state)
1203
+ const r1 = c.uint.decode(state)
1204
+
1205
+ return {
1206
+ key: r0,
1207
+ weight: r1
1208
+ }
1209
+ }
1210
+ }
1211
+
1212
+ // @autobee/oplog-message-v4.approvals
1213
+ const encoding37_6 = c.array(encoding36)
1214
+
1215
+ // @autobee/oplog-message-v4
1216
+ const encoding37 = {
1217
+ preencode(state, m) {
1218
+ c.uint.preencode(state, m.timestamp)
1219
+ encoding37_1.preencode(state, m.links)
1220
+ state.end++ // max flag is 64 so always one byte
1221
+
1222
+ if (m.batch) encoding24.preencode(state, m.batch)
1223
+ if (m.views) encoding25.preencode(state, m.views)
1224
+ if (m.trusted) encoding37_4.preencode(state, m.trusted)
1225
+ if (m.witness) encoding35.preencode(state, m.witness)
1226
+ if (m.approvals) encoding37_6.preencode(state, m.approvals)
1227
+ if (m.value) c.buffer.preencode(state, m.value)
1228
+ },
1229
+ encode(state, m) {
1230
+ const flags =
1231
+ (m.batch ? 1 : 0) |
1232
+ (m.views ? 2 : 0) |
1233
+ (m.trusted ? 4 : 0) |
1234
+ (m.witness ? 8 : 0) |
1235
+ (m.approvals ? 16 : 0) |
1236
+ (m.optimistic ? 32 : 0) |
1237
+ (m.value ? 64 : 0)
1238
+
1239
+ c.uint.encode(state, m.timestamp)
1240
+ encoding37_1.encode(state, m.links)
1241
+ c.uint.encode(state, flags)
1242
+
1243
+ if (m.batch) encoding24.encode(state, m.batch)
1244
+ if (m.views) encoding25.encode(state, m.views)
1245
+ if (m.trusted) encoding37_4.encode(state, m.trusted)
1246
+ if (m.witness) encoding35.encode(state, m.witness)
1247
+ if (m.approvals) encoding37_6.encode(state, m.approvals)
1248
+ if (m.value) c.buffer.encode(state, m.value)
1249
+ },
1250
+ decode(state) {
1251
+ const v = c.uint.decode(state)
1252
+ const r0 = c.uint.decode(state)
1253
+ const r1 = encoding37_1.decode(state)
1254
+ const flags = c.uint.decode(state)
1255
+
1256
+ return {
1257
+ version: v,
1258
+ timestamp: r0,
1259
+ links: r1,
1260
+ batch: (flags & 1) !== 0 ? encoding24.decode(state) : null,
1261
+ views: (flags & 2) !== 0 ? encoding25.decode(state) : null,
1262
+ trusted: (flags & 4) !== 0 ? encoding37_4.decode(state) : null,
1263
+ witness: (flags & 8) !== 0 ? encoding35.decode(state) : null,
1264
+ approvals: (flags & 16) !== 0 ? encoding37_6.decode(state) : null,
1265
+ optimistic: (flags & 32) !== 0,
1266
+ value: (flags & 64) !== 0 ? c.buffer.decode(state) : null
1267
+ }
1268
+ }
1269
+ }
1270
+
1078
1271
  // @autobee/system-info-v3.heads, deferred due to recusive use
1079
1272
  const encoding18_3 = c.array(encoding22)
1080
1273
  // @autobee/system-info-v3.indexers, deferred due to recusive use
@@ -1083,6 +1276,10 @@ const encoding18_4 = encoding18_3
1083
1276
  const encoding29_1 = encoding18_3
1084
1277
  // @autobee/oplog-message-v3.trusted, deferred due to recusive use
1085
1278
  const encoding29_8 = c.array(c.frame(encoding32))
1279
+ // @autobee/oplog-message-v4.links, deferred due to recusive use
1280
+ const encoding37_1 = encoding18_3
1281
+ // @autobee/oplog-message-v4.trusted, deferred due to recusive use
1282
+ const encoding37_4 = encoding18_3
1086
1283
 
1087
1284
  function setVersion(v) {
1088
1285
  version = v
@@ -1175,6 +1372,14 @@ function getEncoding(name) {
1175
1372
  return encoding32
1176
1373
  case '@autobee/migrated-head':
1177
1374
  return encoding33
1375
+ case '@autobee/system-writer-v5':
1376
+ return encoding34
1377
+ case '@autobee/grant-witness':
1378
+ return encoding35
1379
+ case '@autobee/approval':
1380
+ return encoding36
1381
+ case '@autobee/oplog-message-v4':
1382
+ return encoding37
1178
1383
  default:
1179
1384
  throw new Error('Encoder not found ' + name)
1180
1385
  }
@@ -428,6 +428,12 @@
428
428
  "array": true,
429
429
  "type": "@autobee/link",
430
430
  "version": 1
431
+ },
432
+ {
433
+ "name": "pending",
434
+ "array": true,
435
+ "type": "bool",
436
+ "version": 1
431
437
  }
432
438
  ]
433
439
  },
@@ -527,6 +533,11 @@
527
533
  "type": "@autobee/system-writer-v4",
528
534
  "map": null,
529
535
  "version": 4
536
+ },
537
+ {
538
+ "type": "@autobee/system-writer-v5",
539
+ "map": null,
540
+ "version": 5
530
541
  }
531
542
  ]
532
543
  },
@@ -780,8 +791,13 @@
780
791
  },
781
792
  {
782
793
  "type": "@autobee/oplog-message-v3",
783
- "map": null,
794
+ "map": "oplogLegacyMap",
784
795
  "version": 3
796
+ },
797
+ {
798
+ "type": "@autobee/oplog-message-v4",
799
+ "map": null,
800
+ "version": 4
785
801
  }
786
802
  ]
787
803
  },
@@ -856,6 +872,154 @@
856
872
  "version": 1
857
873
  }
858
874
  ]
875
+ },
876
+ {
877
+ "name": "system-writer-v5",
878
+ "namespace": "autobee",
879
+ "compact": false,
880
+ "flagsPosition": 0,
881
+ "fields": [
882
+ {
883
+ "name": "isRemoved",
884
+ "required": false,
885
+ "type": "bool",
886
+ "version": 1
887
+ },
888
+ {
889
+ "name": "isOplog",
890
+ "required": false,
891
+ "type": "bool",
892
+ "version": 1
893
+ },
894
+ {
895
+ "name": "isGenesis",
896
+ "required": false,
897
+ "type": "bool",
898
+ "version": 1
899
+ },
900
+ {
901
+ "name": "weight",
902
+ "required": true,
903
+ "type": "uint",
904
+ "version": 1
905
+ },
906
+ {
907
+ "name": "maxWeight",
908
+ "required": true,
909
+ "type": "uint",
910
+ "version": 1
911
+ },
912
+ {
913
+ "name": "length",
914
+ "required": true,
915
+ "type": "uint",
916
+ "version": 1
917
+ },
918
+ {
919
+ "name": "timestamp",
920
+ "required": true,
921
+ "type": "uint",
922
+ "version": 1
923
+ }
924
+ ]
925
+ },
926
+ {
927
+ "name": "grant-witness",
928
+ "namespace": "autobee",
929
+ "compact": true,
930
+ "flagsPosition": -1,
931
+ "fields": [
932
+ {
933
+ "name": "weight",
934
+ "required": true,
935
+ "type": "uint",
936
+ "version": 1
937
+ },
938
+ {
939
+ "name": "link",
940
+ "required": true,
941
+ "type": "@autobee/link",
942
+ "version": 1
943
+ }
944
+ ]
945
+ },
946
+ {
947
+ "name": "approval",
948
+ "namespace": "autobee",
949
+ "compact": true,
950
+ "flagsPosition": -1,
951
+ "fields": [
952
+ {
953
+ "name": "key",
954
+ "required": true,
955
+ "type": "fixed32",
956
+ "version": 1
957
+ },
958
+ {
959
+ "name": "weight",
960
+ "required": true,
961
+ "type": "uint",
962
+ "version": 1
963
+ }
964
+ ]
965
+ },
966
+ {
967
+ "name": "oplog-message-v4",
968
+ "namespace": "autobee",
969
+ "compact": false,
970
+ "flagsPosition": 2,
971
+ "fields": [
972
+ {
973
+ "name": "timestamp",
974
+ "required": true,
975
+ "type": "uint",
976
+ "version": 1
977
+ },
978
+ {
979
+ "name": "links",
980
+ "required": true,
981
+ "array": true,
982
+ "type": "@autobee/link",
983
+ "version": 1
984
+ },
985
+ {
986
+ "name": "batch",
987
+ "type": "@autobee/batch",
988
+ "version": 1
989
+ },
990
+ {
991
+ "name": "views",
992
+ "type": "@autobee/views",
993
+ "version": 1
994
+ },
995
+ {
996
+ "name": "trusted",
997
+ "array": true,
998
+ "type": "@autobee/link",
999
+ "version": 1
1000
+ },
1001
+ {
1002
+ "name": "witness",
1003
+ "type": "@autobee/grant-witness",
1004
+ "version": 1
1005
+ },
1006
+ {
1007
+ "name": "approvals",
1008
+ "array": true,
1009
+ "type": "@autobee/approval",
1010
+ "version": 1
1011
+ },
1012
+ {
1013
+ "name": "optimistic",
1014
+ "type": "bool",
1015
+ "version": 1
1016
+ },
1017
+ {
1018
+ "name": "value",
1019
+ "type": "buffer",
1020
+ "version": 1
1021
+ }
1022
+ ]
859
1023
  }
860
1024
  ],
861
1025
  "namespaces": [