Skip to content

Commit 04bf67d

Browse files
authored
deps: bump uint8arrays, protons and multiformats (libp2p#29)
1 parent aa89850 commit 04bf67d

File tree

5 files changed

+42
-84
lines changed

5 files changed

+42
-84
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,19 @@
159159
"it-foreach": "^0.1.1",
160160
"it-map": "^1.0.6",
161161
"it-pipe": "^2.0.3",
162-
"multiformats": "^9.6.3",
163-
"protons-runtime": "^3.1.0",
162+
"multiformats": "^10.0.0",
163+
"protons-runtime": "^4.0.1",
164164
"uint8-varint": "^1.0.2",
165165
"uint8arraylist": "^2.1.0",
166-
"uint8arrays": "^3.0.0",
166+
"uint8arrays": "^4.0.2",
167167
"varint": "^6.0.0"
168168
},
169169
"devDependencies": {
170170
"@libp2p/interface-record-compliance-tests": "^2.0.0",
171171
"@libp2p/peer-id-factory": "^1.0.0",
172172
"@types/varint": "^6.0.0",
173173
"aegir": "^37.3.0",
174-
"protons": "^5.1.0",
174+
"protons": "^6.0.0",
175175
"sinon": "^14.0.0"
176176
}
177177
}

src/envelope/envelope.ts

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable import/export */
2+
/* eslint-disable complexity */
23
/* eslint-disable @typescript-eslint/no-namespace */
4+
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
35

46
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
57
import type { Uint8ArrayList } from 'uint8arraylist'
@@ -17,41 +19,33 @@ export namespace Envelope {
1719

1820
export const codec = (): Codec<Envelope> => {
1921
if (_codec == null) {
20-
_codec = message<Envelope>((obj, writer, opts = {}) => {
22+
_codec = message<Envelope>((obj, w, opts = {}) => {
2123
if (opts.lengthDelimited !== false) {
22-
writer.fork()
24+
w.fork()
2325
}
2426

25-
if (obj.publicKey != null) {
26-
writer.uint32(10)
27-
writer.bytes(obj.publicKey)
28-
} else {
29-
throw new Error('Protocol error: required field "publicKey" was not found in object')
27+
if (opts.writeDefaults === true || (obj.publicKey != null && obj.publicKey.byteLength > 0)) {
28+
w.uint32(10)
29+
w.bytes(obj.publicKey)
3030
}
3131

32-
if (obj.payloadType != null) {
33-
writer.uint32(18)
34-
writer.bytes(obj.payloadType)
35-
} else {
36-
throw new Error('Protocol error: required field "payloadType" was not found in object')
32+
if (opts.writeDefaults === true || (obj.payloadType != null && obj.payloadType.byteLength > 0)) {
33+
w.uint32(18)
34+
w.bytes(obj.payloadType)
3735
}
3836

39-
if (obj.payload != null) {
40-
writer.uint32(26)
41-
writer.bytes(obj.payload)
42-
} else {
43-
throw new Error('Protocol error: required field "payload" was not found in object')
37+
if (opts.writeDefaults === true || (obj.payload != null && obj.payload.byteLength > 0)) {
38+
w.uint32(26)
39+
w.bytes(obj.payload)
4440
}
4541

46-
if (obj.signature != null) {
47-
writer.uint32(42)
48-
writer.bytes(obj.signature)
49-
} else {
50-
throw new Error('Protocol error: required field "signature" was not found in object')
42+
if (opts.writeDefaults === true || (obj.signature != null && obj.signature.byteLength > 0)) {
43+
w.uint32(42)
44+
w.bytes(obj.signature)
5145
}
5246

5347
if (opts.lengthDelimited !== false) {
54-
writer.ldelim()
48+
w.ldelim()
5549
}
5650
}, (reader, length) => {
5751
const obj: any = {
@@ -85,22 +79,6 @@ export namespace Envelope {
8579
}
8680
}
8781

88-
if (obj.publicKey == null) {
89-
throw new Error('Protocol error: value for required field "publicKey" was not found in protobuf')
90-
}
91-
92-
if (obj.payloadType == null) {
93-
throw new Error('Protocol error: value for required field "payloadType" was not found in protobuf')
94-
}
95-
96-
if (obj.payload == null) {
97-
throw new Error('Protocol error: value for required field "payload" was not found in protobuf')
98-
}
99-
100-
if (obj.signature == null) {
101-
throw new Error('Protocol error: value for required field "signature" was not found in protobuf')
102-
}
103-
10482
return obj
10583
})
10684
}
File renamed without changes.

src/peer-record/peer-record.ts

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-disable import/export */
2+
/* eslint-disable complexity */
23
/* eslint-disable @typescript-eslint/no-namespace */
4+
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
35

46
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
57
import type { Uint8ArrayList } from 'uint8arraylist'
@@ -21,20 +23,18 @@ export namespace PeerRecord {
2123

2224
export const codec = (): Codec<AddressInfo> => {
2325
if (_codec == null) {
24-
_codec = message<AddressInfo>((obj, writer, opts = {}) => {
26+
_codec = message<AddressInfo>((obj, w, opts = {}) => {
2527
if (opts.lengthDelimited !== false) {
26-
writer.fork()
28+
w.fork()
2729
}
2830

29-
if (obj.multiaddr != null) {
30-
writer.uint32(10)
31-
writer.bytes(obj.multiaddr)
32-
} else {
33-
throw new Error('Protocol error: required field "multiaddr" was not found in object')
31+
if (opts.writeDefaults === true || (obj.multiaddr != null && obj.multiaddr.byteLength > 0)) {
32+
w.uint32(10)
33+
w.bytes(obj.multiaddr)
3434
}
3535

3636
if (opts.lengthDelimited !== false) {
37-
writer.ldelim()
37+
w.ldelim()
3838
}
3939
}, (reader, length) => {
4040
const obj: any = {
@@ -56,10 +56,6 @@ export namespace PeerRecord {
5656
}
5757
}
5858

59-
if (obj.multiaddr == null) {
60-
throw new Error('Protocol error: value for required field "multiaddr" was not found in protobuf')
61-
}
62-
6359
return obj
6460
})
6561
}
@@ -80,36 +76,32 @@ export namespace PeerRecord {
8076

8177
export const codec = (): Codec<PeerRecord> => {
8278
if (_codec == null) {
83-
_codec = message<PeerRecord>((obj, writer, opts = {}) => {
79+
_codec = message<PeerRecord>((obj, w, opts = {}) => {
8480
if (opts.lengthDelimited !== false) {
85-
writer.fork()
81+
w.fork()
8682
}
8783

88-
if (obj.peerId != null) {
89-
writer.uint32(10)
90-
writer.bytes(obj.peerId)
91-
} else {
92-
throw new Error('Protocol error: required field "peerId" was not found in object')
84+
if (opts.writeDefaults === true || (obj.peerId != null && obj.peerId.byteLength > 0)) {
85+
w.uint32(10)
86+
w.bytes(obj.peerId)
9387
}
9488

95-
if (obj.seq != null) {
96-
writer.uint32(16)
97-
writer.uint64(obj.seq)
98-
} else {
99-
throw new Error('Protocol error: required field "seq" was not found in object')
89+
if (opts.writeDefaults === true || obj.seq !== 0n) {
90+
w.uint32(16)
91+
w.uint64(obj.seq)
10092
}
10193

10294
if (obj.addresses != null) {
10395
for (const value of obj.addresses) {
104-
writer.uint32(26)
105-
PeerRecord.AddressInfo.codec().encode(value, writer)
96+
w.uint32(26)
97+
PeerRecord.AddressInfo.codec().encode(value, w, {
98+
writeDefaults: true
99+
})
106100
}
107-
} else {
108-
throw new Error('Protocol error: required field "addresses" was not found in object')
109101
}
110102

111103
if (opts.lengthDelimited !== false) {
112-
writer.ldelim()
104+
w.ldelim()
113105
}
114106
}, (reader, length) => {
115107
const obj: any = {
@@ -139,14 +131,6 @@ export namespace PeerRecord {
139131
}
140132
}
141133

142-
if (obj.peerId == null) {
143-
throw new Error('Protocol error: value for required field "peerId" was not found in protobuf')
144-
}
145-
146-
if (obj.seq == null) {
147-
throw new Error('Protocol error: value for required field "seq" was not found in protobuf')
148-
}
149-
150134
return obj
151135
})
152136
}

tsconfig.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,5 @@
66
"include": [
77
"src",
88
"test"
9-
],
10-
"exclude": [
11-
"src/envelope/envelope.js",
12-
"src/peer-record/peer-record.js"
139
]
1410
}

0 commit comments

Comments
 (0)