hypercore 9.11.0 → 10.0.0-alpha.10

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.
Files changed (85) hide show
  1. package/.github/workflows/test-node.yml +3 -4
  2. package/README.md +123 -409
  3. package/__snapshots__/test/storage.js.snapshot.cjs +15 -0
  4. package/examples/announce.js +19 -0
  5. package/examples/basic.js +10 -0
  6. package/examples/http.js +123 -0
  7. package/examples/lookup.js +20 -0
  8. package/index.js +362 -1597
  9. package/lib/bitfield.js +113 -285
  10. package/lib/block-encryption.js +68 -0
  11. package/lib/block-store.js +58 -0
  12. package/lib/core.js +468 -0
  13. package/lib/extensions.js +76 -0
  14. package/lib/merkle-tree.js +1110 -0
  15. package/lib/messages.js +571 -0
  16. package/lib/mutex.js +39 -0
  17. package/lib/oplog.js +224 -0
  18. package/lib/protocol.js +525 -0
  19. package/lib/random-iterator.js +46 -0
  20. package/lib/remote-bitfield.js +24 -0
  21. package/lib/replicator.js +857 -0
  22. package/package.json +44 -45
  23. package/test/basic.js +59 -471
  24. package/test/bitfield.js +48 -133
  25. package/test/core.js +290 -0
  26. package/test/encodings.js +18 -0
  27. package/test/encryption.js +123 -0
  28. package/test/extension.js +71 -0
  29. package/test/helpers/index.js +23 -0
  30. package/test/merkle-tree.js +518 -0
  31. package/test/mutex.js +137 -0
  32. package/test/oplog.js +399 -0
  33. package/test/preload.js +72 -0
  34. package/test/replicate.js +227 -824
  35. package/test/sessions.js +173 -0
  36. package/test/storage.js +31 -0
  37. package/test/user-data.js +47 -0
  38. package/bench/all.sh +0 -65
  39. package/bench/copy-64kb-blocks.js +0 -51
  40. package/bench/helpers/read-throttled.js +0 -27
  41. package/bench/helpers/read.js +0 -47
  42. package/bench/helpers/write.js +0 -29
  43. package/bench/read-16kb-blocks-proof-throttled.js +0 -1
  44. package/bench/read-16kb-blocks-proof.js +0 -1
  45. package/bench/read-16kb-blocks-throttled.js +0 -1
  46. package/bench/read-16kb-blocks.js +0 -1
  47. package/bench/read-512b-blocks.js +0 -1
  48. package/bench/read-64kb-blocks-linear-batch.js +0 -18
  49. package/bench/read-64kb-blocks-linear.js +0 -18
  50. package/bench/read-64kb-blocks-proof.js +0 -1
  51. package/bench/read-64kb-blocks.js +0 -1
  52. package/bench/replicate-16kb-blocks.js +0 -19
  53. package/bench/replicate-64kb-blocks.js +0 -19
  54. package/bench/write-16kb-blocks.js +0 -1
  55. package/bench/write-512b-blocks.js +0 -1
  56. package/bench/write-64kb-blocks-static.js +0 -1
  57. package/bench/write-64kb-blocks.js +0 -1
  58. package/example.js +0 -23
  59. package/lib/cache.js +0 -26
  60. package/lib/crypto.js +0 -5
  61. package/lib/replicate.js +0 -829
  62. package/lib/safe-buffer-equals.js +0 -6
  63. package/lib/storage.js +0 -421
  64. package/lib/tree-index.js +0 -183
  65. package/test/ack.js +0 -306
  66. package/test/audit.js +0 -36
  67. package/test/cache.js +0 -93
  68. package/test/compat.js +0 -209
  69. package/test/copy.js +0 -377
  70. package/test/default-storage.js +0 -51
  71. package/test/extensions.js +0 -137
  72. package/test/get.js +0 -64
  73. package/test/head.js +0 -65
  74. package/test/helpers/create-tracking-ram.js +0 -27
  75. package/test/helpers/create.js +0 -6
  76. package/test/helpers/replicate.js +0 -4
  77. package/test/seek.js +0 -234
  78. package/test/selections.js +0 -95
  79. package/test/set-uploading-downloading.js +0 -91
  80. package/test/stats.js +0 -77
  81. package/test/streams.js +0 -162
  82. package/test/timeouts.js +0 -22
  83. package/test/tree-index.js +0 -841
  84. package/test/update.js +0 -156
  85. package/test/value-encoding.js +0 -52
package/test/update.js DELETED
@@ -1,156 +0,0 @@
1
- const tape = require('tape')
2
- const create = require('./helpers/create')
3
- const replicate = require('./helpers/replicate')
4
-
5
- tape('update', function (t) {
6
- const feed = create()
7
-
8
- feed.ready(function () {
9
- const clone = create(feed.key, { sparse: true, eagerUpdate: true })
10
-
11
- replicate(feed, clone, { live: true })
12
-
13
- clone.once('append', function () {
14
- t.same(clone.length, 4, 'did an eager update')
15
- t.end()
16
- })
17
-
18
- feed.append(['hi', 'ho', 'hi', 'ho'])
19
- })
20
- })
21
-
22
- tape('disable eager update', function (t) {
23
- const feed = create()
24
-
25
- feed.ready(function () {
26
- const clone = create(feed.key, { sparse: true, eagerUpdate: false })
27
-
28
- replicate(feed, clone, { live: true })
29
-
30
- clone.once('append', function () {
31
- t.fail('should not update')
32
- })
33
-
34
- feed.append(['hi', 'ho', 'hi', 'ho'], function () {
35
- setTimeout(() => t.end(), 50)
36
- })
37
- })
38
- })
39
-
40
- tape('update if available', function (t) {
41
- const feed = create()
42
-
43
- feed.append(['a', 'b', 'c'], function () {
44
- const clone = create(feed.key, { sparse: true })
45
-
46
- replicate(feed, clone, { live: true })
47
-
48
- clone.update({ ifAvailable: true }, function (err) {
49
- t.error(err, 'no error')
50
- t.same(clone.length, feed.length, 'was updated')
51
- t.end()
52
- })
53
- })
54
- })
55
-
56
- tape('update if available (no peers)', function (t) {
57
- const feed = create()
58
-
59
- feed.append(['a', 'b', 'c'], function () {
60
- const clone = create(feed.key, { sparse: true })
61
-
62
- clone.update({ ifAvailable: true }, function (err) {
63
- t.ok(err)
64
- t.same(clone.length, 0, 'was not updated')
65
- t.end()
66
- })
67
- })
68
- })
69
-
70
- tape('update if available (no one has it)', function (t) {
71
- const feed = create()
72
-
73
- feed.append(['a', 'b', 'c'], function () {
74
- const clone = create(feed.key, { sparse: true })
75
-
76
- replicate(feed, clone, { live: true })
77
-
78
- clone.update({ ifAvailable: true, minLength: 4 }, function (err) {
79
- t.ok(err)
80
- t.same(clone.length, 0, 'was not updated')
81
- t.end()
82
- })
83
- })
84
- })
85
-
86
- tape('update if available through top-level option', function (t) {
87
- const feed = create()
88
-
89
- feed.append(['a', 'b', 'c'], function () {
90
- const clone = create(feed.key, { sparse: true, ifAvailable: true })
91
-
92
- replicate(feed, clone, { live: true })
93
-
94
- clone.update({ minLength: 4 }, function (err) {
95
- t.ok(err)
96
- t.same(clone.length, 0, 'was not updated')
97
- t.end()
98
- })
99
- })
100
- })
101
-
102
- tape('update with block data', function (t) {
103
- const feed = create()
104
-
105
- feed.append(['a', 'b', 'c', 'd'], function () {
106
- const clone = create(feed.key, { sparse: true })
107
-
108
- replicate(feed, clone, { live: true })
109
-
110
- clone.update({ hash: false }, function () {
111
- t.ok(clone.has(3))
112
- t.end()
113
- })
114
- })
115
- })
116
-
117
- tape('update without hash option should not download block', function (t) {
118
- const feed = create()
119
-
120
- feed.append(['a', 'b', 'c'], function () {
121
- const clone = create(feed.key, { sparse: true })
122
-
123
- replicate(feed, clone, { live: true })
124
-
125
- clone.on('download', function (index, data) {
126
- t.fail('should not trigger a download event')
127
- })
128
-
129
- clone.update({ ifAvailable: true }, function (err) {
130
- t.error(err, 'no error')
131
- t.same(clone.length, 3, 'was updated')
132
- t.same(clone.downloaded(), 0, 'block was not downloaded')
133
- t.end()
134
- })
135
- })
136
- })
137
-
138
- tape('update with block data', function (t) {
139
- const feed = create()
140
-
141
- feed.append(['a', 'b', 'c', 'd'], function () {
142
- const clone1 = create(feed.key, { sparse: true })
143
- const clone2 = create(feed.key, { sparse: true })
144
-
145
- replicate(feed, clone1, { live: true })
146
- replicate(clone1, clone2, { live: true })
147
-
148
- clone1.get(3, () => {
149
- clone2.update(function () {
150
- t.same(clone1.length, clone2.length)
151
- t.same(clone1.length, feed.length)
152
- t.end()
153
- })
154
- })
155
- })
156
- })
@@ -1,52 +0,0 @@
1
- var tape = require('tape')
2
- var create = require('./helpers/create')
3
-
4
- tape('basic value encoding', function (t) {
5
- var feed = create({
6
- valueEncoding: 'json'
7
- })
8
-
9
- feed.append({ hello: 'world' }, function () {
10
- feed.get(0, function (err, val) {
11
- t.error(err, 'no error')
12
- t.same(val, { hello: 'world' })
13
- t.end()
14
- })
15
- })
16
- })
17
-
18
- tape('value encoding read-stream', function (t) {
19
- var feed = create({
20
- valueEncoding: 'json'
21
- })
22
-
23
- feed.append({ hello: 'world' }, function () {
24
- feed.createReadStream()
25
- .on('data', function (data) {
26
- t.same(data, { hello: 'world' })
27
- })
28
- .on('end', function () {
29
- feed.createReadStream({ valueEncoding: 'utf-8' })
30
- .on('data', function (data) {
31
- t.same(data, '{"hello":"world"}\n')
32
- t.end()
33
- })
34
- })
35
- })
36
- })
37
-
38
- tape('value encoding write-stream', function (t) {
39
- var feed = create({
40
- valueEncoding: 'json'
41
- })
42
-
43
- var ws = feed.createWriteStream()
44
- ws.write([1, 2, 3])
45
- ws.end(function () {
46
- feed.get(0, function (err, val) {
47
- t.error(err, 'no error')
48
- t.same(val, [1, 2, 3])
49
- t.end()
50
- })
51
- })
52
- })