@leofcoin/peernet 0.14.12 → 0.14.14

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.
@@ -357,6 +357,13 @@ function _interopNamespace(e) {
357
357
 
358
358
  var PubSub__default = /*#__PURE__*/_interopDefaultLegacy(PubSub);
359
359
 
360
+ const BufferToUint8Array = () => {
361
+ if (data.type === 'Buffer') {
362
+ data = new Uint8Array(data.data);
363
+ }
364
+ return data
365
+ };
366
+
360
367
  const protoFor = (message) => {
361
368
  const codec = new codecFormatInterface.Codec(message);
362
369
  if (!codec.name) throw new Error('proto not found')
@@ -1144,7 +1151,7 @@ class Peernet {
1144
1151
  return {
1145
1152
  get: async (hash) => {
1146
1153
  const data = await blockStore.has(hash);
1147
- if (data) return await blockStore.get(hash)
1154
+ if (data) return blockStore.get(hash)
1148
1155
  return this.requestData(hash, 'block')
1149
1156
  },
1150
1157
  put: async (hash, data) => {
@@ -1195,11 +1202,10 @@ class Peernet {
1195
1202
  });
1196
1203
  if (closest[0]) data = await closest[0].request(node.encoded);
1197
1204
  }
1198
- console.log({data});
1199
1205
  data = new Uint8Array(Object.values(data));
1200
1206
  const proto = await protoFor(data);
1201
1207
  // TODO: store data automaticly or not
1202
- return proto.decoded.data
1208
+ return BufferToUint8Array(proto.decoded.data)
1203
1209
 
1204
1210
  // this.put(hash, proto.decoded.data)
1205
1211
  }
@@ -2423,7 +2429,7 @@ class Peer {
2423
2429
 
2424
2430
  async #runQue() {
2425
2431
  this.#queRunning = true
2426
- if (this.#messageQue.length > 0 && this.channel.bufferedAmount + this.#messageQue[0]?.length < this.#MAX_BUFFERED_AMOUNT) {
2432
+ if (this.#messageQue.length > 0 && this.channel?.bufferedAmount + this.#messageQue[0]?.length < this.#MAX_BUFFERED_AMOUNT) {
2427
2433
  const message = this.#messageQue.shift()
2428
2434
 
2429
2435
  switch (this.channel?.readyState) {
@@ -28,6 +28,13 @@ function _interopNamespace(e) {
28
28
  var PubSub__default = /*#__PURE__*/_interopDefaultLegacy(PubSub);
29
29
  var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
30
30
 
31
+ const BufferToUint8Array = () => {
32
+ if (data.type === 'Buffer') {
33
+ data = new Uint8Array(data.data);
34
+ }
35
+ return data
36
+ };
37
+
31
38
  const protoFor = (message) => {
32
39
  const codec = new codecFormatInterface.Codec(message);
33
40
  if (!codec.name) throw new Error('proto not found')
@@ -815,7 +822,7 @@ class Peernet {
815
822
  return {
816
823
  get: async (hash) => {
817
824
  const data = await blockStore.has(hash);
818
- if (data) return await blockStore.get(hash)
825
+ if (data) return blockStore.get(hash)
819
826
  return this.requestData(hash, 'block')
820
827
  },
821
828
  put: async (hash, data) => {
@@ -866,11 +873,10 @@ class Peernet {
866
873
  });
867
874
  if (closest[0]) data = await closest[0].request(node.encoded);
868
875
  }
869
- console.log({data});
870
876
  data = new Uint8Array(Object.values(data));
871
877
  const proto = await protoFor(data);
872
878
  // TODO: store data automaticly or not
873
- return proto.decoded.data
879
+ return BufferToUint8Array(proto.decoded.data)
874
880
 
875
881
  // this.put(hash, proto.decoded.data)
876
882
  }
@@ -26,6 +26,13 @@ function _interopNamespace(e) {
26
26
 
27
27
  var PubSub__default = /*#__PURE__*/_interopDefaultLegacy(PubSub);
28
28
 
29
+ const BufferToUint8Array = () => {
30
+ if (data.type === 'Buffer') {
31
+ data = new Uint8Array(data.data);
32
+ }
33
+ return data
34
+ };
35
+
29
36
  const protoFor = (message) => {
30
37
  const codec = new codecFormatInterface.Codec(message);
31
38
  if (!codec.name) throw new Error('proto not found')
@@ -813,7 +820,7 @@ class Peernet {
813
820
  return {
814
821
  get: async (hash) => {
815
822
  const data = await blockStore.has(hash);
816
- if (data) return await blockStore.get(hash)
823
+ if (data) return blockStore.get(hash)
817
824
  return this.requestData(hash, 'block')
818
825
  },
819
826
  put: async (hash, data) => {
@@ -864,11 +871,10 @@ class Peernet {
864
871
  });
865
872
  if (closest[0]) data = await closest[0].request(node.encoded);
866
873
  }
867
- console.log({data});
868
874
  data = new Uint8Array(Object.values(data));
869
875
  const proto = await protoFor(data);
870
876
  // TODO: store data automaticly or not
871
- return proto.decoded.data
877
+ return BufferToUint8Array(proto.decoded.data)
872
878
 
873
879
  // this.put(hash, proto.decoded.data)
874
880
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "0.14.12",
3
+ "version": "0.14.14",
4
4
  "description": "",
5
5
  "source": "src/peernet.js",
6
6
  "main": "dist/commonjs/peernet.js",
package/src/peernet.js CHANGED
@@ -3,7 +3,7 @@ import PubSub from '@vandeurenglenn/little-pubsub'
3
3
  import PeerDiscovery from './discovery/peer-discovery'
4
4
  import DHT from './dht/dht.js'
5
5
  import codecs from './../node_modules/@leofcoin/codec-format-interface/src/codecs'
6
- import { protoFor, target } from './utils/utils.js'
6
+ import { BufferToUint8Array, protoFor, target } from './utils/utils.js'
7
7
  import MessageHandler from './handlers/message.js'
8
8
  import dataHandler from './handlers/data.js'
9
9
  import { encapsulatedError, dhtError,
@@ -402,7 +402,7 @@ export default class Peernet {
402
402
  return {
403
403
  get: async (hash) => {
404
404
  const data = await blockStore.has(hash)
405
- if (data) return await blockStore.get(hash)
405
+ if (data) return blockStore.get(hash)
406
406
  return this.requestData(hash, 'block')
407
407
  },
408
408
  put: async (hash, data) => {
@@ -453,11 +453,10 @@ export default class Peernet {
453
453
  })
454
454
  if (closest[0]) data = await closest[0].request(node.encoded)
455
455
  }
456
- console.log({data});
457
456
  data = new Uint8Array(Object.values(data))
458
457
  const proto = await protoFor(data)
459
458
  // TODO: store data automaticly or not
460
- return proto.decoded.data
459
+ return BufferToUint8Array(proto.decoded.data)
461
460
 
462
461
  // this.put(hash, proto.decoded.data)
463
462
  }
@@ -2,6 +2,13 @@ import fetch from 'node-fetch'
2
2
 
3
3
  import { Codec } from '@leofcoin/codec-format-interface'
4
4
 
5
+ export const BufferToUint8Array = () => {
6
+ if (data.type === 'Buffer') {
7
+ data = new Uint8Array(data.data)
8
+ }
9
+ return data
10
+ }
11
+
5
12
  export const expected = (expected, actual) => {
6
13
  const rule = (entry) => {
7
14
  return !entry ? `: undefined - ${entry} ` :`: ${typeof entry} - `