@libp2p/record 1.0.5 → 2.0.2

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/README.md CHANGED
@@ -1,17 +1,27 @@
1
- # js-libp2p-record
1
+ # @libp2p/record <!-- omit in toc -->
2
2
 
3
- [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
4
- [![](https://img.shields.io/badge/project-libp2p-blue.svg?style=flat-square)](http://libp2p.io/)
5
- [![](https://img.shields.io/badge/freenode-%23libp2p-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
6
- [![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
7
- [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
8
- [![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-record/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-record?branch=master)
9
- [![Build Status](https://github.com/libp2p/js-libp2p-record/actions/workflows/js-test-and-release.yml/badge.svg?branch=main)](https://github.com/libp2p/js-libp2p-record/actions/workflows/js-test-and-release.yml)
10
- [![Dependency Status](https://david-dm.org/libp2p/js-libp2p-record.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-record) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
11
- ![](https://img.shields.io/badge/npm-%3E%3D3.0.0-orange.svg?style=flat-square)
12
- ![](https://img.shields.io/badge/Node.js-%3E%3D6.0.0-orange.svg?style=flat-square)
3
+ [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4
+ [![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
5
+ [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
6
+ [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-record.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-record)
7
+ [![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-record/actions/workflows/js-test-and-release.yml)
13
8
 
14
- > JavaScript implementation of libp2p record.
9
+ > libp2p record implementation
10
+
11
+ ## Table of contents <!-- omit in toc -->
12
+
13
+ - [Install](#install)
14
+ - [Description](#description)
15
+ - [Usage](#usage)
16
+ - [Contribute](#contribute)
17
+ - [License](#license)
18
+ - [Contribution](#contribution)
19
+
20
+ ## Install
21
+
22
+ ```console
23
+ $ npm i @libp2p/record
24
+ ```
15
25
 
16
26
  ## Description
17
27
 
@@ -19,22 +29,22 @@ Implementation of [go-libp2p-record](https://github.com/libp2p/go-libp2p-record)
19
29
 
20
30
  ## Usage
21
31
 
22
- See https://libp2p.github.io/js-libp2p-record/
32
+ See <https://libp2p.github.io/js-libp2p-record/>
23
33
 
24
34
  ## Contribute
25
35
 
26
36
  The libp2p implementation in JavaScript is a work in progress. As such, there are a few things you can do right now to help out:
27
37
 
28
- - Go through the modules and **check out existing issues**. This is especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
29
- - **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
38
+ - Go through the modules and **check out existing issues**. This is especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
39
+ - **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
30
40
 
31
41
  ## License
32
42
 
33
43
  Licensed under either of
34
44
 
35
- * Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / http://www.apache.org/licenses/LICENSE-2.0)
36
- * MIT ([LICENSE-MIT](LICENSE-MIT) / http://opensource.org/licenses/MIT)
45
+ - Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
46
+ - MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
37
47
 
38
- ### Contribution
48
+ ## Contribution
39
49
 
40
50
  Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
@@ -1,3 +1,4 @@
1
+ import type { Uint8ArrayList } from 'uint8arraylist';
1
2
  import { Record } from './record.js';
2
3
  export declare class Libp2pRecord {
3
4
  key: Uint8Array;
@@ -16,7 +17,7 @@ export declare class Libp2pRecord {
16
17
  /**
17
18
  * Decode a protobuf encoded record
18
19
  */
19
- static deserialize(raw: Uint8Array): Libp2pRecord;
20
+ static deserialize(raw: Uint8Array | Uint8ArrayList): Libp2pRecord;
20
21
  /**
21
22
  * Create a record from the raw object returned from the protobuf library
22
23
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACP,MAAM,aAAa,CAAA;AAGpB,qBAAa,YAAY;IAChB,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,UAAU,CAAA;IACjB,YAAY,EAAE,IAAI,CAAA;gBAEZ,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI;IAcnE,SAAS;IAIT;;OAEG;IACH,gBAAgB;;;;;IAQhB;;OAEG;IACH,MAAM,CAAC,WAAW,CAAE,GAAG,EAAE,UAAU;IAMnC;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAE,GAAG,EAAE,MAAM;CAiBrC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"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AA;QAED,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
@@ -1,3 +1,4 @@
1
+ import type { Uint8ArrayList } from 'uint8arraylist';
1
2
  import type { Codec } from 'protons-runtime';
2
3
  export interface Record {
3
4
  key: Uint8Array;
@@ -7,6 +8,6 @@ export interface Record {
7
8
  export declare namespace Record {
8
9
  const codec: () => Codec<Record>;
9
10
  const encode: (obj: Record) => Uint8Array;
10
- const decode: (buf: Uint8Array) => Record;
11
+ const decode: (buf: Uint8Array | Uint8ArrayList) => Record;
11
12
  }
12
13
  //# sourceMappingURL=record.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/record.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,UAAU,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,yBAAiB,MAAM,CAAC;IACf,MAAM,KAAK,QAAO,MAAM,MAAM,CAMpC,CAAA;IAEM,MAAM,MAAM,QAAS,MAAM,KAAG,UAEpC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,KAAG,MAExC,CAAA;CACF"}
1
+ {"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../../src/record.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAE5C,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,UAAU,CAAA;IACf,KAAK,EAAE,UAAU,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,yBAAiB,MAAM,CAAC;IAGf,MAAM,KAAK,QAAO,MAAM,MAAM,CA4EpC,CAAA;IAEM,MAAM,MAAM,QAAS,MAAM,KAAG,UAEpC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,MAEzD,CAAA;CACF"}
@@ -1,14 +1,76 @@
1
1
  /* eslint-disable import/export */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
- import { encodeMessage, decodeMessage, message, bytes, string } from 'protons-runtime';
3
+ import { encodeMessage, decodeMessage, message } from 'protons-runtime';
4
4
  export var Record;
5
5
  (function (Record) {
6
+ let _codec;
6
7
  Record.codec = () => {
7
- return message({
8
- 1: { name: 'key', codec: bytes },
9
- 2: { name: 'value', codec: bytes },
10
- 5: { name: 'timeReceived', codec: string }
11
- });
8
+ if (_codec == null) {
9
+ _codec = message((obj, writer, opts = {}) => {
10
+ if (opts.lengthDelimited !== false) {
11
+ writer.fork();
12
+ }
13
+ if (obj.key != null) {
14
+ writer.uint32(10);
15
+ writer.bytes(obj.key);
16
+ }
17
+ else {
18
+ throw new Error('Protocol error: required field "key" was not found in object');
19
+ }
20
+ if (obj.value != null) {
21
+ writer.uint32(18);
22
+ writer.bytes(obj.value);
23
+ }
24
+ else {
25
+ throw new Error('Protocol error: required field "value" was not found in object');
26
+ }
27
+ if (obj.timeReceived != null) {
28
+ writer.uint32(42);
29
+ writer.string(obj.timeReceived);
30
+ }
31
+ else {
32
+ throw new Error('Protocol error: required field "timeReceived" was not found in object');
33
+ }
34
+ if (opts.lengthDelimited !== false) {
35
+ writer.ldelim();
36
+ }
37
+ }, (reader, length) => {
38
+ const obj = {
39
+ key: new Uint8Array(0),
40
+ value: new Uint8Array(0),
41
+ timeReceived: ''
42
+ };
43
+ const end = length == null ? reader.len : reader.pos + length;
44
+ while (reader.pos < end) {
45
+ const tag = reader.uint32();
46
+ switch (tag >>> 3) {
47
+ case 1:
48
+ obj.key = reader.bytes();
49
+ break;
50
+ case 2:
51
+ obj.value = reader.bytes();
52
+ break;
53
+ case 5:
54
+ obj.timeReceived = reader.string();
55
+ break;
56
+ default:
57
+ reader.skipType(tag & 7);
58
+ break;
59
+ }
60
+ }
61
+ if (obj.key == null) {
62
+ throw new Error('Protocol error: value for required field "key" was not found in protobuf');
63
+ }
64
+ if (obj.value == null) {
65
+ throw new Error('Protocol error: value for required field "value" was not found in protobuf');
66
+ }
67
+ if (obj.timeReceived == null) {
68
+ throw new Error('Protocol error: value for required field "timeReceived" was not found in protobuf');
69
+ }
70
+ return obj;
71
+ });
72
+ }
73
+ return _codec;
12
74
  };
13
75
  Record.encode = (obj) => {
14
76
  return encodeMessage(obj, Record.codec());
@@ -1 +1 @@
1
- {"version":3,"file":"record.js","sourceRoot":"","sources":["../../src/record.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,oDAAoD;AAEpD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAStF,MAAM,KAAW,MAAM,CAgBtB;AAhBD,WAAiB,MAAM;IACR,YAAK,GAAG,GAAkB,EAAE;QACvC,OAAO,OAAO,CAAS;YACrB,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE;YAChC,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE;YAClC,CAAC,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE;SAC3C,CAAC,CAAA;IACJ,CAAC,CAAA;IAEY,aAAM,GAAG,CAAC,GAAW,EAAc,EAAE;QAChD,OAAO,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;IAC3C,CAAC,CAAA;IAEY,aAAM,GAAG,CAAC,GAAe,EAAU,EAAE;QAChD,OAAO,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;IAC3C,CAAC,CAAA;AACH,CAAC,EAhBgB,MAAM,KAAN,MAAM,QAgBtB"}
1
+ {"version":3,"file":"record.js","sourceRoot":"","sources":["../../src/record.ts"],"names":[],"mapp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;SACH;QAED,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IAEY,aAAM,GAAG,CAAC,GAAW,EAAc,EAAE;QAChD,OAAO,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;IAC3C,CAAC,CAAA;IAEY,aAAM,GAAG,CAAC,GAAgC,EAAU,EAAE;QACjE,OAAO,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;IAC3C,CAAC,CAAA;AACH,CAAC,EAxFgB,MAAM,KAAN,MAAM,QAwFtB"}
@@ -1,4 +1,4 @@
1
- import type { Selectors } from '@libp2p/interfaces/dht';
1
+ import type { Selectors } from '@libp2p/interface-dht';
2
2
  /**
3
3
  * Select the best record out of the given records
4
4
  */
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAEvD;;GAEG;AACH,wBAAgB,UAAU,CAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,UA6BrF;AAWD,eAAO,MAAM,SAAS,EAAE,SAEvB,CAAA"}
1
+ {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/selectors.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEtD;;GAEG;AACH,wBAAgB,UAAU,CAAE,SAAS,EAAE,SAAS,EAAE,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,EAAE,UA6BrF;AAWD,eAAO,MAAM,SAAS,EAAE,SAEvB,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import type { Libp2pRecord } from './index.js';
2
- import type { Validators } from '@libp2p/interfaces/dht';
2
+ import type { Validators } from '@libp2p/interface-dht';
3
3
  /**
4
4
  * Checks a record and ensures it is still valid.
5
5
  * It runs the needed validators.
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/validators.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAIxD;;;;GAIG;AACH,wBAAgB,YAAY,CAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,6BAmBzE;AAmCD,eAAO,MAAM,UAAU,EAAE,UAExB,CAAA"}
1
+ {"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/validators.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAIvD;;;;GAIG;AACH,wBAAgB,YAAY,CAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,6BAmBzE;AAmCD,eAAO,MAAM,UAAU,EAAE,UAExB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/record",
3
- "version": "1.0.5",
3
+ "version": "2.0.2",
4
4
  "description": "libp2p record implementation",
5
5
  "author": "Friedel Ziegelmayer <dignifiedquire@gmail.com>",
6
6
  "license": "Apache-2.0 OR MIT",
@@ -45,12 +45,15 @@
45
45
  ],
46
46
  "exports": {
47
47
  ".": {
48
+ "types": "./src/index.d.ts",
48
49
  "import": "./dist/src/index.js"
49
50
  },
50
51
  "./selectors": {
52
+ "types": "./dist/src/selectors.d.ts",
51
53
  "import": "./dist/src/selectors.js"
52
54
  },
53
55
  "./validators": {
56
+ "types": "./dist/src/validators.d.ts",
54
57
  "import": "./dist/src/validators.js"
55
58
  }
56
59
  },
@@ -90,15 +93,15 @@
90
93
  "release": "patch"
91
94
  },
92
95
  {
93
- "type": "chore",
96
+ "type": "docs",
94
97
  "release": "patch"
95
98
  },
96
99
  {
97
- "type": "docs",
100
+ "type": "test",
98
101
  "release": "patch"
99
102
  },
100
103
  {
101
- "type": "test",
104
+ "type": "deps",
102
105
  "release": "patch"
103
106
  },
104
107
  {
@@ -128,7 +131,11 @@
128
131
  },
129
132
  {
130
133
  "type": "docs",
131
- "section": "Trivial Changes"
134
+ "section": "Documentation"
135
+ },
136
+ {
137
+ "type": "deps",
138
+ "section": "Dependencies"
132
139
  },
133
140
  {
134
141
  "type": "test",
@@ -159,15 +166,16 @@
159
166
  "release": "aegir release"
160
167
  },
161
168
  "dependencies": {
162
- "@libp2p/interfaces": "^2.0.2",
169
+ "@libp2p/interface-dht": "^1.0.0",
163
170
  "err-code": "^3.0.1",
164
171
  "multiformats": "^9.4.5",
165
- "protons-runtime": "^1.0.2",
172
+ "protons-runtime": "^3.1.0",
173
+ "uint8arraylist": "^2.1.1",
166
174
  "uint8arrays": "^3.0.0"
167
175
  },
168
176
  "devDependencies": {
169
- "@libp2p/crypto": "^0.22.10",
177
+ "@libp2p/crypto": "^1.0.2",
170
178
  "aegir": "^37.0.13",
171
- "protons": "^3.0.2"
179
+ "protons": "^5.1.0"
172
180
  }
173
181
  }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Uint8ArrayList } from 'uint8arraylist'
1
2
  import {
2
3
  Record
3
4
  } from './record.js'
@@ -40,7 +41,7 @@ export class Libp2pRecord {
40
41
  /**
41
42
  * Decode a protobuf encoded record
42
43
  */
43
- static deserialize (raw: Uint8Array) {
44
+ static deserialize (raw: Uint8Array | Uint8ArrayList) {
44
45
  const rec = Record.decode(raw)
45
46
 
46
47
  return new Libp2pRecord(rec.key, rec.value, new Date(rec.timeReceived))
package/src/record.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /* eslint-disable import/export */
2
2
  /* eslint-disable @typescript-eslint/no-namespace */
3
3
 
4
- import { encodeMessage, decodeMessage, message, bytes, string } from 'protons-runtime'
4
+ import { encodeMessage, decodeMessage, message } from 'protons-runtime'
5
+ import type { Uint8ArrayList } from 'uint8arraylist'
5
6
  import type { Codec } from 'protons-runtime'
6
7
 
7
8
  export interface Record {
@@ -11,19 +12,91 @@ export interface Record {
11
12
  }
12
13
 
13
14
  export namespace Record {
15
+ let _codec: Codec<Record>
16
+
14
17
  export const codec = (): Codec<Record> => {
15
- return message<Record>({
16
- 1: { name: 'key', codec: bytes },
17
- 2: { name: 'value', codec: bytes },
18
- 5: { name: 'timeReceived', codec: string }
19
- })
18
+ if (_codec == null) {
19
+ _codec = message<Record>((obj, writer, opts = {}) => {
20
+ if (opts.lengthDelimited !== false) {
21
+ writer.fork()
22
+ }
23
+
24
+ if (obj.key != null) {
25
+ writer.uint32(10)
26
+ writer.bytes(obj.key)
27
+ } else {
28
+ throw new Error('Protocol error: required field "key" was not found in object')
29
+ }
30
+
31
+ if (obj.value != null) {
32
+ writer.uint32(18)
33
+ writer.bytes(obj.value)
34
+ } else {
35
+ throw new Error('Protocol error: required field "value" was not found in object')
36
+ }
37
+
38
+ if (obj.timeReceived != null) {
39
+ writer.uint32(42)
40
+ writer.string(obj.timeReceived)
41
+ } else {
42
+ throw new Error('Protocol error: required field "timeReceived" was not found in object')
43
+ }
44
+
45
+ if (opts.lengthDelimited !== false) {
46
+ writer.ldelim()
47
+ }
48
+ }, (reader, length) => {
49
+ const obj: any = {
50
+ key: new Uint8Array(0),
51
+ value: new Uint8Array(0),
52
+ timeReceived: ''
53
+ }
54
+
55
+ const end = length == null ? reader.len : reader.pos + length
56
+
57
+ while (reader.pos < end) {
58
+ const tag = reader.uint32()
59
+
60
+ switch (tag >>> 3) {
61
+ case 1:
62
+ obj.key = reader.bytes()
63
+ break
64
+ case 2:
65
+ obj.value = reader.bytes()
66
+ break
67
+ case 5:
68
+ obj.timeReceived = reader.string()
69
+ break
70
+ default:
71
+ reader.skipType(tag & 7)
72
+ break
73
+ }
74
+ }
75
+
76
+ if (obj.key == null) {
77
+ throw new Error('Protocol error: value for required field "key" was not found in protobuf')
78
+ }
79
+
80
+ if (obj.value == null) {
81
+ throw new Error('Protocol error: value for required field "value" was not found in protobuf')
82
+ }
83
+
84
+ if (obj.timeReceived == null) {
85
+ throw new Error('Protocol error: value for required field "timeReceived" was not found in protobuf')
86
+ }
87
+
88
+ return obj
89
+ })
90
+ }
91
+
92
+ return _codec
20
93
  }
21
94
 
22
95
  export const encode = (obj: Record): Uint8Array => {
23
96
  return encodeMessage(obj, Record.codec())
24
97
  }
25
98
 
26
- export const decode = (buf: Uint8Array): Record => {
99
+ export const decode = (buf: Uint8Array | Uint8ArrayList): Record => {
27
100
  return decodeMessage(buf, Record.codec())
28
101
  }
29
102
  }
package/src/selectors.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import errCode from 'err-code'
2
2
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
3
- import type { Selectors } from '@libp2p/interfaces/dht'
3
+ import type { Selectors } from '@libp2p/interface-dht'
4
4
 
5
5
  /**
6
6
  * Select the best record out of the given records
package/src/validators.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import errCode from 'err-code'
2
2
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
3
3
  import type { Libp2pRecord } from './index.js'
4
- import type { Validators } from '@libp2p/interfaces/dht'
4
+ import type { Validators } from '@libp2p/interface-dht'
5
5
  import { sha256 } from 'multiformats/hashes/sha2'
6
6
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
7
7