hyperbee2 1.2.0 → 2.0.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.
@@ -11,7 +11,7 @@ const VERSION = 1
11
11
  // eslint-disable-next-line no-unused-vars
12
12
  let version = VERSION
13
13
 
14
- // @bee/tree-pointer
14
+ // @bee/tree-pointer-0
15
15
  const encoding0 = {
16
16
  preencode(state, m) {
17
17
  c.uint.preencode(state, m.core)
@@ -36,8 +36,151 @@ const encoding0 = {
36
36
  }
37
37
  }
38
38
 
39
- // @bee/block-pointer
39
+ // @bee/tree-pointer
40
40
  const encoding1 = {
41
+ preencode(state, m) {
42
+ state.end++ // flags are fixed size
43
+
44
+ if (m.core) c.uint.preencode(state, m.core)
45
+ if (m.seq) c.uint.preencode(state, m.seq)
46
+ if (m.offset) c.uint.preencode(state, m.offset)
47
+ },
48
+ encode(state, m) {
49
+ const flags = (m.core ? 1 : 0) | (m.seq ? 2 : 0) | (m.offset ? 4 : 0)
50
+
51
+ c.uint8.encode(state, flags)
52
+
53
+ if (m.core) c.uint.encode(state, m.core)
54
+ if (m.seq) c.uint.encode(state, m.seq)
55
+ if (m.offset) c.uint.encode(state, m.offset)
56
+ },
57
+ decode(state) {
58
+ const flags = c.uint8.decode(state)
59
+
60
+ return {
61
+ core: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
62
+ seq: (flags & 2) !== 0 ? c.uint.decode(state) : 0,
63
+ offset: (flags & 4) !== 0 ? c.uint.decode(state) : 0
64
+ }
65
+ }
66
+ }
67
+
68
+ // @bee/tree-pointer (inline)
69
+ const encoding1_inline = {
70
+ preencode(state, m) {
71
+ if (m.core) c.uint.preencode(state, m.core)
72
+ if (m.seq) c.uint.preencode(state, m.seq)
73
+ if (m.offset) c.uint.preencode(state, m.offset)
74
+ },
75
+ encode(state, m) {
76
+ if (m.core) c.uint.encode(state, m.core)
77
+ if (m.seq) c.uint.encode(state, m.seq)
78
+ if (m.offset) c.uint.encode(state, m.offset)
79
+ },
80
+ decode(state, inlining) {
81
+ const flags = inlining
82
+
83
+ return {
84
+ core: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
85
+ seq: (flags & 2) !== 0 ? c.uint.decode(state) : 0,
86
+ offset: (flags & 4) !== 0 ? c.uint.decode(state) : 0
87
+ }
88
+ }
89
+ }
90
+
91
+ // @bee/tree-delta
92
+ const encoding2 = {
93
+ preencode(state, m) {
94
+ state.end++ // flags are fixed size
95
+
96
+ if (m.index) c.uint8.preencode(state, m.index)
97
+ if (m.pointer) encoding1_inline.preencode(state, m.pointer)
98
+ },
99
+ encode(state, m) {
100
+ let flags = (m.type & 7) | (m.index ? 8 : 0) | (m.pointer ? 16 : 0)
101
+ if (m.pointer) {
102
+ flags |= (m.pointer.core ? 32 : 0) | (m.pointer.seq ? 64 : 0) | (m.pointer.offset ? 128 : 0)
103
+ }
104
+
105
+ c.uint8.encode(state, flags)
106
+
107
+ if (m.index) c.uint8.encode(state, m.index)
108
+ if (m.pointer) encoding1_inline.encode(state, m.pointer)
109
+ },
110
+ decode(state) {
111
+ const flags = c.uint8.decode(state)
112
+
113
+ return {
114
+ type: flags & 7,
115
+ index: (flags & 8) !== 0 ? c.uint8.decode(state) : 0,
116
+ pointer: (flags & 16) !== 0 ? encoding1_inline.decode(state, flags >>> 5) : null
117
+ }
118
+ }
119
+ }
120
+
121
+ // @bee/cohort
122
+ const encoding3 = c.array(encoding2)
123
+
124
+ // @bee/value-pointer
125
+ const encoding4 = {
126
+ preencode(state, m) {
127
+ state.end++ // flags are fixed size
128
+
129
+ if (m.core) c.uint.preencode(state, m.core)
130
+ if (m.seq) c.uint.preencode(state, m.seq)
131
+ if (m.offset) c.uint.preencode(state, m.offset)
132
+ if (m.split) c.uint.preencode(state, m.split)
133
+ },
134
+ encode(state, m) {
135
+ const flags = (m.core ? 1 : 0) | (m.seq ? 2 : 0) | (m.offset ? 4 : 0) | (m.split ? 8 : 0)
136
+
137
+ c.uint8.encode(state, flags)
138
+
139
+ if (m.core) c.uint.encode(state, m.core)
140
+ if (m.seq) c.uint.encode(state, m.seq)
141
+ if (m.offset) c.uint.encode(state, m.offset)
142
+ if (m.split) c.uint.encode(state, m.split)
143
+ },
144
+ decode(state) {
145
+ const flags = c.uint8.decode(state)
146
+
147
+ return {
148
+ core: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
149
+ seq: (flags & 2) !== 0 ? c.uint.decode(state) : 0,
150
+ offset: (flags & 4) !== 0 ? c.uint.decode(state) : 0,
151
+ split: (flags & 8) !== 0 ? c.uint.decode(state) : 0
152
+ }
153
+ }
154
+ }
155
+
156
+ // @bee/value-pointer (inline)
157
+ const encoding4_inline = {
158
+ preencode(state, m) {
159
+ if (m.core) c.uint.preencode(state, m.core)
160
+ if (m.seq) c.uint.preencode(state, m.seq)
161
+ if (m.offset) c.uint.preencode(state, m.offset)
162
+ if (m.split) c.uint.preencode(state, m.split)
163
+ },
164
+ encode(state, m) {
165
+ if (m.core) c.uint.encode(state, m.core)
166
+ if (m.seq) c.uint.encode(state, m.seq)
167
+ if (m.offset) c.uint.encode(state, m.offset)
168
+ if (m.split) c.uint.encode(state, m.split)
169
+ },
170
+ decode(state, inlining) {
171
+ const flags = inlining
172
+
173
+ return {
174
+ core: (flags & 1) !== 0 ? c.uint.decode(state) : 0,
175
+ seq: (flags & 2) !== 0 ? c.uint.decode(state) : 0,
176
+ offset: (flags & 4) !== 0 ? c.uint.decode(state) : 0,
177
+ split: (flags & 8) !== 0 ? c.uint.decode(state) : 0
178
+ }
179
+ }
180
+ }
181
+
182
+ // @bee/block-pointer
183
+ const encoding5 = {
41
184
  preencode(state, m) {
42
185
  c.uint.preencode(state, m.core)
43
186
  c.uint.preencode(state, m.seq)
@@ -58,7 +201,7 @@ const encoding1 = {
58
201
  }
59
202
 
60
203
  // @bee/batch-pointer
61
- const encoding2 = {
204
+ const encoding6 = {
62
205
  preencode(state, m) {
63
206
  c.uint.preencode(state, m.start)
64
207
  c.uint.preencode(state, m.end)
@@ -78,24 +221,50 @@ const encoding2 = {
78
221
  }
79
222
  }
80
223
 
224
+ // @bee/tree-0.keys
225
+ const encoding7_0 = c.array(encoding0)
226
+ // @bee/tree-0.children
227
+ const encoding7_1 = encoding7_0
228
+
229
+ // @bee/tree-0
230
+ const encoding7 = {
231
+ preencode(state, m) {
232
+ encoding7_0.preencode(state, m.keys)
233
+ encoding7_1.preencode(state, m.children)
234
+ },
235
+ encode(state, m) {
236
+ encoding7_0.encode(state, m.keys)
237
+ encoding7_1.encode(state, m.children)
238
+ },
239
+ decode(state) {
240
+ const r0 = encoding7_0.decode(state)
241
+ const r1 = encoding7_1.decode(state)
242
+
243
+ return {
244
+ keys: r0,
245
+ children: r1
246
+ }
247
+ }
248
+ }
249
+
81
250
  // @bee/tree.keys
82
- const encoding3_0 = c.array(encoding0)
251
+ const encoding8_0 = encoding3
83
252
  // @bee/tree.children
84
- const encoding3_1 = encoding3_0
253
+ const encoding8_1 = encoding3
85
254
 
86
255
  // @bee/tree
87
- const encoding3 = {
256
+ const encoding8 = {
88
257
  preencode(state, m) {
89
- encoding3_0.preencode(state, m.keys)
90
- encoding3_1.preencode(state, m.children)
258
+ encoding8_0.preencode(state, m.keys)
259
+ encoding8_1.preencode(state, m.children)
91
260
  },
92
261
  encode(state, m) {
93
- encoding3_0.encode(state, m.keys)
94
- encoding3_1.encode(state, m.children)
262
+ encoding8_0.encode(state, m.keys)
263
+ encoding8_1.encode(state, m.children)
95
264
  },
96
265
  decode(state) {
97
- const r0 = encoding3_0.decode(state)
98
- const r1 = encoding3_1.decode(state)
266
+ const r0 = encoding8_0.decode(state)
267
+ const r1 = encoding8_1.decode(state)
99
268
 
100
269
  return {
101
270
  keys: r0,
@@ -105,7 +274,7 @@ const encoding3 = {
105
274
  }
106
275
 
107
276
  // @bee/data
108
- const encoding4 = {
277
+ const encoding9 = {
109
278
  preencode(state, m) {
110
279
  c.buffer.preencode(state, m.key)
111
280
  c.buffer.preencode(state, m.value)
@@ -125,11 +294,48 @@ const encoding4 = {
125
294
  }
126
295
  }
127
296
 
297
+ // @bee/key
298
+ const encoding10 = {
299
+ preencode(state, m) {
300
+ c.buffer.preencode(state, m.key)
301
+ state.end++ // flags are fixed size
302
+
303
+ if (m.value) c.buffer.preencode(state, m.value)
304
+ if (m.valuePointer) encoding4_inline.preencode(state, m.valuePointer)
305
+ },
306
+ encode(state, m) {
307
+ let flags = (m.value ? 1 : 0) | (m.valuePointer ? 2 : 0)
308
+ if (m.valuePointer) {
309
+ flags |=
310
+ (m.valuePointer.core ? 4 : 0) |
311
+ (m.valuePointer.seq ? 8 : 0) |
312
+ (m.valuePointer.offset ? 16 : 0) |
313
+ (m.valuePointer.split ? 32 : 0)
314
+ }
315
+
316
+ c.buffer.encode(state, m.key)
317
+ c.uint8.encode(state, flags)
318
+
319
+ if (m.value) c.buffer.encode(state, m.value)
320
+ if (m.valuePointer) encoding4_inline.encode(state, m.valuePointer)
321
+ },
322
+ decode(state) {
323
+ const r0 = c.buffer.decode(state)
324
+ const flags = c.uint8.decode(state)
325
+
326
+ return {
327
+ key: r0,
328
+ value: (flags & 1) !== 0 ? c.buffer.decode(state) : null,
329
+ valuePointer: (flags & 2) !== 0 ? encoding4_inline.decode(state, flags >>> 2) : null
330
+ }
331
+ }
332
+ }
333
+
128
334
  // @bee/core
129
- const encoding5 = {
335
+ const encoding11 = {
130
336
  preencode(state, m) {
131
337
  c.fixed32.preencode(state, m.key)
132
- state.end++ // max flag is 4 so always one byte
338
+ state.end++ // flags are fixed size
133
339
 
134
340
  if (m.fork) c.uint.preencode(state, m.fork)
135
341
  if (m.length) c.uint.preencode(state, m.length)
@@ -139,7 +345,7 @@ const encoding5 = {
139
345
  const flags = (m.fork ? 1 : 0) | (m.length ? 2 : 0) | (m.treeHash ? 4 : 0)
140
346
 
141
347
  c.fixed32.encode(state, m.key)
142
- c.uint.encode(state, flags)
348
+ c.uint8.encode(state, flags)
143
349
 
144
350
  if (m.fork) c.uint.encode(state, m.fork)
145
351
  if (m.length) c.uint.encode(state, m.length)
@@ -147,7 +353,7 @@ const encoding5 = {
147
353
  },
148
354
  decode(state) {
149
355
  const r0 = c.fixed32.decode(state)
150
- const flags = c.uint.decode(state)
356
+ const flags = c.uint8.decode(state)
151
357
 
152
358
  return {
153
359
  key: r0,
@@ -158,53 +364,140 @@ const encoding5 = {
158
364
  }
159
365
  }
160
366
 
161
- // @bee/block.tree
162
- const encoding6_4 = c.array(encoding3)
163
- // @bee/block.data
164
- const encoding6_5 = c.array(encoding4)
165
- // @bee/block.cores
166
- const encoding6_6 = c.array(encoding5)
367
+ // @bee/block-0.tree
368
+ const encoding12_4 = c.array(encoding7)
369
+ // @bee/block-0.data
370
+ const encoding12_5 = c.array(encoding9)
371
+ // @bee/block-0.cores
372
+ const encoding12_6 = c.array(encoding11)
167
373
 
168
- // @bee/block
169
- const encoding6 = {
374
+ // @bee/block-0
375
+ const encoding12 = {
170
376
  preencode(state, m) {
171
377
  c.uint.preencode(state, m.type)
172
378
  c.uint.preencode(state, m.checkpoint)
173
- encoding2.preencode(state, m.batch)
379
+ encoding6.preencode(state, m.batch)
174
380
  state.end++ // max flag is 8 so always one byte
175
381
 
176
- if (m.previous) encoding1.preencode(state, m.previous)
177
- if (m.tree) encoding6_4.preencode(state, m.tree)
178
- if (m.data) encoding6_5.preencode(state, m.data)
179
- if (m.cores) encoding6_6.preencode(state, m.cores)
382
+ if (m.previous) encoding5.preencode(state, m.previous)
383
+ if (m.tree) encoding12_4.preencode(state, m.tree)
384
+ if (m.data) encoding12_5.preencode(state, m.data)
385
+ if (m.cores) encoding12_6.preencode(state, m.cores)
180
386
  },
181
387
  encode(state, m) {
182
388
  const flags = (m.previous ? 1 : 0) | (m.tree ? 2 : 0) | (m.data ? 4 : 0) | (m.cores ? 8 : 0)
183
389
 
184
390
  c.uint.encode(state, m.type)
185
391
  c.uint.encode(state, m.checkpoint)
186
- encoding2.encode(state, m.batch)
392
+ encoding6.encode(state, m.batch)
187
393
  c.uint.encode(state, flags)
188
394
 
189
- if (m.previous) encoding1.encode(state, m.previous)
190
- if (m.tree) encoding6_4.encode(state, m.tree)
191
- if (m.data) encoding6_5.encode(state, m.data)
192
- if (m.cores) encoding6_6.encode(state, m.cores)
395
+ if (m.previous) encoding5.encode(state, m.previous)
396
+ if (m.tree) encoding12_4.encode(state, m.tree)
397
+ if (m.data) encoding12_5.encode(state, m.data)
398
+ if (m.cores) encoding12_6.encode(state, m.cores)
193
399
  },
194
400
  decode(state) {
195
401
  const r0 = c.uint.decode(state)
196
402
  const r1 = c.uint.decode(state)
197
- const r2 = encoding2.decode(state)
403
+ const r2 = encoding6.decode(state)
198
404
  const flags = c.uint.decode(state)
199
405
 
200
406
  return {
201
407
  type: r0,
202
408
  checkpoint: r1,
203
409
  batch: r2,
204
- previous: (flags & 1) !== 0 ? encoding1.decode(state) : null,
205
- tree: (flags & 2) !== 0 ? encoding6_4.decode(state) : null,
206
- data: (flags & 4) !== 0 ? encoding6_5.decode(state) : null,
207
- cores: (flags & 8) !== 0 ? encoding6_6.decode(state) : null
410
+ previous: (flags & 1) !== 0 ? encoding5.decode(state) : null,
411
+ tree: (flags & 2) !== 0 ? encoding12_4.decode(state) : null,
412
+ data: (flags & 4) !== 0 ? encoding12_5.decode(state) : null,
413
+ cores: (flags & 8) !== 0 ? encoding12_6.decode(state) : null
414
+ }
415
+ }
416
+ }
417
+
418
+ // @bee/metadata.cores
419
+ const encoding13_0 = encoding12_6
420
+
421
+ // @bee/metadata
422
+ const encoding13 = {
423
+ preencode(state, m) {
424
+ encoding13_0.preencode(state, m.cores)
425
+ },
426
+ encode(state, m) {
427
+ encoding13_0.encode(state, m.cores)
428
+ },
429
+ decode(state) {
430
+ const r0 = encoding13_0.decode(state)
431
+
432
+ return {
433
+ cores: r0
434
+ }
435
+ }
436
+ }
437
+
438
+ // @bee/block-1.metadata
439
+ const encoding14_4 = c.frame(encoding13)
440
+ // @bee/block-1.tree
441
+ const encoding14_5 = c.array(encoding8)
442
+ // @bee/block-1.keys
443
+ const encoding14_6 = c.array(encoding10)
444
+ // @bee/block-1.values
445
+ const encoding14_7 = c.array(c.buffer)
446
+ // @bee/block-1.cohorts
447
+ const encoding14_8 = c.array(encoding3)
448
+
449
+ // @bee/block-1
450
+ const encoding14 = {
451
+ preencode(state, m) {
452
+ c.uint.preencode(state, m.type)
453
+ c.uint.preencode(state, m.checkpoint)
454
+ encoding6.preencode(state, m.batch)
455
+ state.end++ // max flag is 32 so always one byte
456
+
457
+ if (m.previous) encoding5.preencode(state, m.previous)
458
+ if (m.metadata) encoding14_4.preencode(state, m.metadata)
459
+ if (m.tree) encoding14_5.preencode(state, m.tree)
460
+ if (m.keys) encoding14_6.preencode(state, m.keys)
461
+ if (m.values) encoding14_7.preencode(state, m.values)
462
+ if (m.cohorts) encoding14_8.preencode(state, m.cohorts)
463
+ },
464
+ encode(state, m) {
465
+ const flags =
466
+ (m.previous ? 1 : 0) |
467
+ (m.metadata ? 2 : 0) |
468
+ (m.tree ? 4 : 0) |
469
+ (m.keys ? 8 : 0) |
470
+ (m.values ? 16 : 0) |
471
+ (m.cohorts ? 32 : 0)
472
+
473
+ c.uint.encode(state, m.type)
474
+ c.uint.encode(state, m.checkpoint)
475
+ encoding6.encode(state, m.batch)
476
+ c.uint.encode(state, flags)
477
+
478
+ if (m.previous) encoding5.encode(state, m.previous)
479
+ if (m.metadata) encoding14_4.encode(state, m.metadata)
480
+ if (m.tree) encoding14_5.encode(state, m.tree)
481
+ if (m.keys) encoding14_6.encode(state, m.keys)
482
+ if (m.values) encoding14_7.encode(state, m.values)
483
+ if (m.cohorts) encoding14_8.encode(state, m.cohorts)
484
+ },
485
+ decode(state) {
486
+ const r0 = c.uint.decode(state)
487
+ const r1 = c.uint.decode(state)
488
+ const r2 = encoding6.decode(state)
489
+ const flags = c.uint.decode(state)
490
+
491
+ return {
492
+ type: r0,
493
+ checkpoint: r1,
494
+ batch: r2,
495
+ previous: (flags & 1) !== 0 ? encoding5.decode(state) : null,
496
+ metadata: (flags & 2) !== 0 ? encoding14_4.decode(state) : null,
497
+ tree: (flags & 4) !== 0 ? encoding14_5.decode(state) : null,
498
+ keys: (flags & 8) !== 0 ? encoding14_6.decode(state) : null,
499
+ values: (flags & 16) !== 0 ? encoding14_7.decode(state) : null,
500
+ cohorts: (flags & 32) !== 0 ? encoding14_8.decode(state) : null
208
501
  }
209
502
  }
210
503
  }
@@ -232,20 +525,36 @@ function getEnum(name) {
232
525
 
233
526
  function getEncoding(name) {
234
527
  switch (name) {
235
- case '@bee/tree-pointer':
528
+ case '@bee/tree-pointer-0':
236
529
  return encoding0
237
- case '@bee/block-pointer':
530
+ case '@bee/tree-pointer':
238
531
  return encoding1
239
- case '@bee/batch-pointer':
532
+ case '@bee/tree-delta':
240
533
  return encoding2
241
- case '@bee/tree':
534
+ case '@bee/cohort':
242
535
  return encoding3
243
- case '@bee/data':
536
+ case '@bee/value-pointer':
244
537
  return encoding4
245
- case '@bee/core':
538
+ case '@bee/block-pointer':
246
539
  return encoding5
247
- case '@bee/block':
540
+ case '@bee/batch-pointer':
248
541
  return encoding6
542
+ case '@bee/tree-0':
543
+ return encoding7
544
+ case '@bee/tree':
545
+ return encoding8
546
+ case '@bee/data':
547
+ return encoding9
548
+ case '@bee/key':
549
+ return encoding10
550
+ case '@bee/core':
551
+ return encoding11
552
+ case '@bee/block-0':
553
+ return encoding12
554
+ case '@bee/metadata':
555
+ return encoding13
556
+ case '@bee/block-1':
557
+ return encoding14
249
558
  default:
250
559
  throw new Error('Encoder not found ' + name)
251
560
  }