@libp2p/record 2.0.1 → 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.
@@ -5,7 +5,7 @@ export declare class Libp2pRecord {
5
5
  value: Uint8Array;
6
6
  timeReceived: Date;
7
7
  constructor(key: Uint8Array, value: Uint8Array, timeReceived: Date);
8
- serialize(): Uint8ArrayList;
8
+ serialize(): Uint8Array;
9
9
  /**
10
10
  * Return the object format ready to be given to the protobuf library.
11
11
  */
@@ -1,5 +1,5 @@
1
- import type { Codec } from 'protons-runtime';
2
1
  import type { Uint8ArrayList } from 'uint8arraylist';
2
+ import type { Codec } from 'protons-runtime';
3
3
  export interface Record {
4
4
  key: Uint8Array;
5
5
  value: Uint8Array;
@@ -7,7 +7,7 @@ export interface Record {
7
7
  }
8
8
  export declare namespace Record {
9
9
  const codec: () => Codec<Record>;
10
- const encode: (obj: Record) => Uint8ArrayList;
10
+ const encode: (obj: Record) => Uint8Array;
11
11
  const decode: (buf: Uint8Array | Uint8ArrayList) => Record;
12
12
  }
13
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;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,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,cAEpC,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,GAAG,cAAc,KAAG,MAEzD,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;AAUtF,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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AAA;4BACxB,MAAK;qBACR;iBACF;gBAED,IAAI,GAAG,CAAC,GAAG,IAAI,IAAI,EAAE;oBACnB,MAAM,IAAI,KAAK,CAAC,0EAA0E,CAAC,CAAA;iBAC5F;gBAED,IAAI,GAAG,CAAC,KAAK,IAAI,IAAI,EAAE;oBACrB,MAAM,IAAI,KAAK,CAAC,4EAA4E,CAAC,CAAA;iBAC9F;gBAED,IAAI,GAAG,CAAC,YAAY,IAAI,IAAI,EAAE;oBAC5B,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAA;iBACrG;gBAED,OAAO,GAAG,CAAA;YACZ,CAAC,CAAC,CAAA;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/record",
3
- "version": "2.0.1",
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",
@@ -169,13 +169,13 @@
169
169
  "@libp2p/interface-dht": "^1.0.0",
170
170
  "err-code": "^3.0.1",
171
171
  "multiformats": "^9.4.5",
172
- "protons-runtime": "^2.0.2",
172
+ "protons-runtime": "^3.1.0",
173
173
  "uint8arraylist": "^2.1.1",
174
174
  "uint8arrays": "^3.0.0"
175
175
  },
176
176
  "devDependencies": {
177
177
  "@libp2p/crypto": "^1.0.2",
178
178
  "aegir": "^37.0.13",
179
- "protons": "^4.0.1"
179
+ "protons": "^5.1.0"
180
180
  }
181
181
  }
package/src/record.ts CHANGED
@@ -1,9 +1,9 @@
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'
5
- import type { Codec } from 'protons-runtime'
4
+ import { encodeMessage, decodeMessage, message } from 'protons-runtime'
6
5
  import type { Uint8ArrayList } from 'uint8arraylist'
6
+ import type { Codec } from 'protons-runtime'
7
7
 
8
8
  export interface Record {
9
9
  key: Uint8Array
@@ -12,15 +12,87 @@ export interface Record {
12
12
  }
13
13
 
14
14
  export namespace Record {
15
+ let _codec: Codec<Record>
16
+
15
17
  export const codec = (): Codec<Record> => {
16
- return message<Record>({
17
- 1: { name: 'key', codec: bytes },
18
- 2: { name: 'value', codec: bytes },
19
- 5: { name: 'timeReceived', codec: string }
20
- })
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
21
93
  }
22
94
 
23
- export const encode = (obj: Record): Uint8ArrayList => {
95
+ export const encode = (obj: Record): Uint8Array => {
24
96
  return encodeMessage(obj, Record.codec())
25
97
  }
26
98