Skip to content

Commit ecc46cc

Browse files
authoredApr 8, 2022
fix: update aegir, make codec creation dynamic (#26)
To avoid having to work out which classes depend on which, make codec generation dynamic. Also upgrade to latest aegir.
1 parent 64fe094 commit ecc46cc

File tree

18 files changed

+951
-77
lines changed

18 files changed

+951
-77
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"build": "lerna run build",
3434
"lint": "lerna run lint",
3535
"dep-check": "lerna run dep-check",
36-
"release": "lerna run release --concurrency 1"
36+
"release": "lerna run release --concurrency 1 -- --"
3737
},
3838
"dependencies": {
3939
"lerna": "^4.0.0",

‎packages/protons-benchmark/.aegir.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
export default {
3+
build: {
4+
config: {
5+
platform: 'node'
6+
}
7+
}
8+
}

‎packages/protons-benchmark/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@
5959
]
6060
},
6161
"scripts": {
62+
"clean": "aegir clean",
6263
"lint": "aegir lint",
63-
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
64-
"build": "tsc && cp src/protobufjs/bench.js dist/src/protobufjs",
64+
"dep-check": "aegir dep-check",
65+
"build": "aegir build && cp -R src/protobufjs dist/src/protobufjs",
6566
"prestart": "npm run build",
6667
"start": "node dist/src/index.js"
6768
},
@@ -73,7 +74,7 @@
7374
"protons-runtime": "^0.0.0"
7475
},
7576
"devDependencies": {
76-
"aegir": "^36.1.3"
77+
"aegir": "^37.0.5"
7778
},
7879
"private": true
7980
}

‎packages/protons-benchmark/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import benny from 'benny'
3-
import { expect } from 'aegir/utils/chai.js'
3+
import { expect } from 'aegir/chai'
44
import { Test as ProtonsTest } from './protons/bench.js'
55
import { encodeTest as pbjsEncodeTest, decodeTest as pbjsDecodeTest } from './pbjs/bench.js'
66
import { Test as ProtobufjsTest } from './protobufjs/bench.js'

‎packages/protons-benchmark/src/protobufjs/bench.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*eslint-disable*/
22
// @ts-nocheck
3+
34
import $protobuf from "protobufjs/minimal.js";
45

56
// Common aliases

‎packages/protons-benchmark/src/protons/bench.ts

+42-30
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ export interface Foo {
88
}
99

1010
export namespace Foo {
11-
export const codec = message<Foo>({
12-
1: { name: 'baz', codec: uint32 }
13-
})
11+
export const codec = () => {
12+
return message<Foo>({
13+
1: { name: 'baz', codec: uint32 }
14+
})
15+
}
1416

1517
export const encode = (obj: Foo): Uint8Array => {
16-
return encodeMessage(obj, Foo.codec)
18+
return encodeMessage(obj, Foo.codec())
1719
}
1820

1921
export const decode = (buf: Uint8Array): Foo => {
20-
return decodeMessage(buf, Foo.codec)
22+
return decodeMessage(buf, Foo.codec())
2123
}
2224
}
2325

@@ -26,16 +28,18 @@ export interface Bar {
2628
}
2729

2830
export namespace Bar {
29-
export const codec = message<Bar>({
30-
1: { name: 'tmp', codec: Foo.codec }
31-
})
31+
export const codec = () => {
32+
return message<Bar>({
33+
1: { name: 'tmp', codec: Foo.codec() }
34+
})
35+
}
3236

3337
export const encode = (obj: Bar): Uint8Array => {
34-
return encodeMessage(obj, Bar.codec)
38+
return encodeMessage(obj, Bar.codec())
3539
}
3640

3741
export const decode = (buf: Uint8Array): Bar => {
38-
return decodeMessage(buf, Bar.codec)
42+
return decodeMessage(buf, Bar.codec())
3943
}
4044
}
4145

@@ -45,24 +49,28 @@ export enum FOO {
4549
}
4650

4751
export namespace FOO {
48-
export const codec = enumeration<typeof FOO>(FOO)
52+
export const codec = () => {
53+
return enumeration<typeof FOO>(FOO)
54+
}
4955
}
5056

5157
export interface Yo {
5258
lol: FOO[]
5359
}
5460

5561
export namespace Yo {
56-
export const codec = message<Yo>({
57-
1: { name: 'lol', codec: FOO.codec, repeats: true }
58-
})
62+
export const codec = () => {
63+
return message<Yo>({
64+
1: { name: 'lol', codec: FOO.codec(), repeats: true }
65+
})
66+
}
5967

6068
export const encode = (obj: Yo): Uint8Array => {
61-
return encodeMessage(obj, Yo.codec)
69+
return encodeMessage(obj, Yo.codec())
6270
}
6371

6472
export const decode = (buf: Uint8Array): Yo => {
65-
return decodeMessage(buf, Yo.codec)
73+
return decodeMessage(buf, Yo.codec())
6674
}
6775
}
6876

@@ -72,17 +80,19 @@ export interface Lol {
7280
}
7381

7482
export namespace Lol {
75-
export const codec = message<Lol>({
76-
1: { name: 'lol', codec: string },
77-
2: { name: 'b', codec: Bar.codec }
78-
})
83+
export const codec = () => {
84+
return message<Lol>({
85+
1: { name: 'lol', codec: string },
86+
2: { name: 'b', codec: Bar.codec() }
87+
})
88+
}
7989

8090
export const encode = (obj: Lol): Uint8Array => {
81-
return encodeMessage(obj, Lol.codec)
91+
return encodeMessage(obj, Lol.codec())
8292
}
8393

8494
export const decode = (buf: Uint8Array): Lol => {
85-
return decodeMessage(buf, Lol.codec)
95+
return decodeMessage(buf, Lol.codec())
8696
}
8797
}
8898

@@ -94,18 +104,20 @@ export interface Test {
94104
}
95105

96106
export namespace Test {
97-
export const codec = message<Test>({
98-
6: { name: 'meh', codec: Lol.codec },
99-
3: { name: 'hello', codec: uint32 },
100-
1: { name: 'foo', codec: string },
101-
7: { name: 'payload', codec: bytes }
102-
})
107+
export const codec = () => {
108+
return message<Test>({
109+
6: { name: 'meh', codec: Lol.codec() },
110+
3: { name: 'hello', codec: uint32 },
111+
1: { name: 'foo', codec: string },
112+
7: { name: 'payload', codec: bytes }
113+
})
114+
}
103115

104116
export const encode = (obj: Test): Uint8Array => {
105-
return encodeMessage(obj, Test.codec)
117+
return encodeMessage(obj, Test.codec())
106118
}
107119

108120
export const decode = (buf: Uint8Array): Test => {
109-
return decodeMessage(buf, Test.codec)
121+
return decodeMessage(buf, Test.codec())
110122
}
111123
}

‎packages/protons-benchmark/tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"extends": "aegir/src/config/tsconfig.aegir.json",
33
"compilerOptions": {
4-
"outDir": "dist",
5-
"emitDeclarationOnly": false,
6-
"module": "ES2020"
4+
"outDir": "dist"
75
},
86
"include": [
97
"bin",

‎packages/protons-runtime/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@
138138
},
139139
"scripts": {
140140
"lint": "aegir lint",
141-
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
142-
"build": "tsc",
143-
"release": "semantic-release -e semantic-release-monorepo"
141+
"dep-check": "aegir dep-check",
142+
"build": "aegir build",
143+
"release": "aegir release"
144144
},
145145
"dependencies": {
146146
"uint8arraylist": "^1.4.0",
147147
"uint8arrays": "^3.0.0"
148148
},
149149
"devDependencies": {
150-
"aegir": "^36.1.3"
150+
"aegir": "^37.0.5"
151151
}
152152
}

‎packages/protons-runtime/src/codecs/message.ts

+2-15
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,10 @@ export function message <T> (fieldDefs: FieldDefs): Codec<T> {
6464
const decode: DecodeFunction<T> = function messageDecode (buffer, offset) {
6565
const length = unsigned.decode(buffer, offset)
6666
offset += unsigned.encodingLength(length)
67-
67+
const end = offset + length
6868
const fields: any = {}
6969

70-
while (offset < buffer.length) {
71-
// console.info('start offset', offset)
72-
70+
while (offset < end) {
7371
const key = unsigned.decode(buffer, offset)
7472
offset += unsigned.encodingLength(key)
7573

@@ -78,10 +76,7 @@ export function message <T> (fieldDefs: FieldDefs): Codec<T> {
7876
const fieldDef = fieldDefs[fieldNumber]
7977
let fieldLength = 0
8078

81-
// console.info('fieldNumber', fieldNumber, 'wireType', wireType, 'offset', offset)
82-
8379
if (wireType === CODEC_TYPES.VARINT) {
84-
// console.info('decode varint')
8580
if (fieldDef != null) {
8681
// use the codec if it is available as this could be a bigint
8782
const value = fieldDef.codec.decode(buffer, offset)
@@ -91,25 +86,19 @@ export function message <T> (fieldDefs: FieldDefs): Codec<T> {
9186
fieldLength = unsigned.encodingLength(value)
9287
}
9388
} else if (wireType === CODEC_TYPES.BIT64) {
94-
// console.info('decode 64bit')
9589
fieldLength = 8
9690
} else if (wireType === CODEC_TYPES.LENGTH_DELIMITED) {
97-
// console.info('decode length delimited')
9891
const valueLength = unsigned.decode(buffer, offset)
9992
fieldLength = valueLength + unsigned.encodingLength(valueLength)
10093
} else if (wireType === CODEC_TYPES.BIT32) {
101-
// console.info('decode 32 bit')
10294
fieldLength = 4
10395
} else if (wireType === CODEC_TYPES.START_GROUP) {
10496
throw new Error('Unsupported wire type START_GROUP')
10597
} else if (wireType === CODEC_TYPES.END_GROUP) {
10698
throw new Error('Unsupported wire type END_GROUP')
10799
}
108100

109-
// console.info('fieldLength', fieldLength)
110-
111101
if (fieldDef != null) {
112-
// console.info('decode', fieldDef.codec.name, fieldDef.name, 'at offset', offset)
113102
const value = fieldDef.codec.decode(buffer, offset)
114103

115104
if (fieldDef.repeats === true) {
@@ -121,8 +110,6 @@ export function message <T> (fieldDefs: FieldDefs): Codec<T> {
121110
} else {
122111
fields[fieldDef.name] = value
123112
}
124-
125-
// console.info('decoded', value)
126113
}
127114

128115
offset += fieldLength

‎packages/protons/.aegir.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
export default {
3+
build: {
4+
config: {
5+
platform: 'node'
6+
}
7+
}
8+
}

‎packages/protons/package.json

+6-7
Original file line numberDiff line numberDiff line change
@@ -141,19 +141,18 @@
141141
},
142142
"scripts": {
143143
"lint": "aegir lint",
144-
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js",
145-
"build": "tsc",
146-
"pretest": "npm run build",
147-
"test": "aegir test -t node -f ./dist/test/*.js -f ./dist/test/**/*.js",
148-
"test:node": "npm run test -- -t node --cov",
149-
"release": "semantic-release -e semantic-release-monorepo"
144+
"dep-check": "aegir dep-check",
145+
"build": "aegir build",
146+
"test": "aegir test -t node",
147+
"test:node": "aegir test -t node --cov",
148+
"release": "aegir release"
150149
},
151150
"dependencies": {
152151
"meow": "^10.1.2",
153152
"protobufjs": "^6.11.2"
154153
},
155154
"devDependencies": {
156-
"aegir": "^36.1.3",
155+
"aegir": "^37.0.5",
157156
"pbjs": "^0.0.14",
158157
"protons-runtime": "^1.0.0"
159158
}

‎packages/protons/src/index.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,16 @@ function compileMessage (messageDef: MessageDef, moduleDef: ModuleDef): string {
131131
return `
132132
export enum ${messageDef.name} {
133133
${
134-
Object.entries(messageDef.values).map(([enumValueName, enumValue]) => {
134+
Object.keys(messageDef.values).map(enumValueName => {
135135
return `${enumValueName} = '${enumValueName}'`
136136
}).join(',\n ').trim()
137137
}
138138
}
139139
140140
export namespace ${messageDef.name} {
141-
export const codec = enumeration<typeof ${messageDef.name}>(${messageDef.name})
141+
export const codec = () => {
142+
return enumeration<typeof ${messageDef.name}>(${messageDef.name})
143+
}
142144
}
143145
`
144146
}
@@ -173,8 +175,9 @@ export interface ${messageDef.name} {
173175
}
174176
175177
export namespace ${messageDef.name} {${nested}
176-
export const codec = message<${messageDef.name}>({
177-
${Object.entries(fields)
178+
export const codec = () => {
179+
return message<${messageDef.name}>({
180+
${Object.entries(fields)
178181
.map(([name, fieldDef]) => {
179182
let codec = encoders[fieldDef.type]
180183
@@ -188,21 +191,22 @@ export namespace ${messageDef.name} {${nested}
188191
}
189192
190193
const typeName = findTypeName(fieldDef.type, messageDef, moduleDef)
191-
codec = `${typeName}.codec`
194+
codec = `${typeName}.codec()`
192195
} else {
193196
moduleDef.imports.add(codec)
194197
}
195198
196199
return `${fieldDef.id}: { name: '${name}', codec: ${codec}${fieldDef.options?.proto3_optional === true ? ', optional: true' : ''}${fieldDef.rule === 'repeated' ? ', repeats: true' : ''} }`
197-
}).join(',\n ')}
198-
})
200+
}).join(',\n ')}
201+
})
202+
}
199203
200204
export const encode = (obj: ${messageDef.name}): Uint8Array => {
201-
return encodeMessage(obj, ${messageDef.name}.codec)
205+
return encodeMessage(obj, ${messageDef.name}.codec())
202206
}
203207
204208
export const decode = (buf: Uint8Array): ${messageDef.name} => {
205-
return decodeMessage(buf, ${messageDef.name}.codec)
209+
return decodeMessage(buf, ${messageDef.name}.codec())
206210
}
207211
}
208212
`
+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
syntax = "proto3";
2+
3+
message Request {
4+
enum Type {
5+
IDENTIFY = 0;
6+
CONNECT = 1;
7+
STREAM_OPEN = 2;
8+
STREAM_HANDLER = 3;
9+
DHT = 4;
10+
LIST_PEERS = 5;
11+
CONNMANAGER = 6;
12+
DISCONNECT = 7;
13+
PUBSUB = 8;
14+
PEERSTORE = 9;
15+
}
16+
17+
required Type type = 1;
18+
19+
optional ConnectRequest connect = 2;
20+
optional StreamOpenRequest streamOpen = 3;
21+
optional StreamHandlerRequest streamHandler = 4;
22+
optional DHTRequest dht = 5;
23+
optional ConnManagerRequest connManager = 6;
24+
optional DisconnectRequest disconnect = 7;
25+
optional PSRequest pubsub = 8;
26+
optional PeerstoreRequest peerStore = 9;
27+
}
28+
29+
message Response {
30+
enum Type {
31+
OK = 0;
32+
ERROR = 1;
33+
}
34+
35+
required Type type = 1;
36+
optional ErrorResponse error = 2;
37+
optional StreamInfo streamInfo = 3;
38+
optional IdentifyResponse identify = 4;
39+
optional DHTResponse dht = 5;
40+
repeated PeerInfo peers = 6;
41+
optional PSResponse pubsub = 7;
42+
optional PeerstoreResponse peerStore = 8;
43+
}
44+
45+
message IdentifyResponse {
46+
required bytes id = 1;
47+
repeated bytes addrs = 2;
48+
}
49+
50+
message ConnectRequest {
51+
required bytes peer = 1;
52+
repeated bytes addrs = 2;
53+
optional int64 timeout = 3;
54+
}
55+
56+
message StreamOpenRequest {
57+
required bytes peer = 1;
58+
repeated string proto = 2;
59+
optional int64 timeout = 3;
60+
}
61+
62+
message StreamHandlerRequest {
63+
required bytes addr = 1;
64+
repeated string proto = 2;
65+
}
66+
67+
message ErrorResponse {
68+
required string msg = 1;
69+
}
70+
71+
message StreamInfo {
72+
required bytes peer = 1;
73+
required bytes addr = 2;
74+
required string proto = 3;
75+
}
76+
77+
message DHTRequest {
78+
enum Type {
79+
FIND_PEER = 0;
80+
FIND_PEERS_CONNECTED_TO_PEER = 1;
81+
FIND_PROVIDERS = 2;
82+
GET_CLOSEST_PEERS = 3;
83+
GET_PUBLIC_KEY = 4;
84+
GET_VALUE = 5;
85+
SEARCH_VALUE = 6;
86+
PUT_VALUE = 7;
87+
PROVIDE = 8;
88+
}
89+
90+
required Type type = 1;
91+
optional bytes peer = 2;
92+
optional bytes cid = 3;
93+
optional bytes key = 4;
94+
optional bytes value = 5;
95+
optional int32 count = 6;
96+
optional int64 timeout = 7;
97+
}
98+
99+
message DHTResponse {
100+
enum Type {
101+
BEGIN = 0;
102+
VALUE = 1;
103+
END = 2;
104+
}
105+
106+
required Type type = 1;
107+
optional PeerInfo peer = 2;
108+
optional bytes value = 3;
109+
}
110+
111+
message PeerInfo {
112+
required bytes id = 1;
113+
repeated bytes addrs = 2;
114+
}
115+
116+
message ConnManagerRequest {
117+
enum Type {
118+
TAG_PEER = 0;
119+
UNTAG_PEER = 1;
120+
TRIM = 2;
121+
}
122+
123+
required Type type = 1;
124+
125+
optional bytes peer = 2;
126+
optional string tag = 3;
127+
optional int64 weight = 4;
128+
}
129+
130+
message DisconnectRequest {
131+
required bytes peer = 1;
132+
}
133+
134+
message PSRequest {
135+
enum Type {
136+
GET_TOPICS = 0;
137+
LIST_PEERS = 1;
138+
PUBLISH = 2;
139+
SUBSCRIBE = 3;
140+
}
141+
142+
required Type type = 1;
143+
optional string topic = 2;
144+
optional bytes data = 3;
145+
}
146+
147+
message PSMessage {
148+
optional bytes from = 1;
149+
optional bytes data = 2;
150+
optional bytes seqno = 3;
151+
repeated string topicIDs = 4;
152+
optional bytes signature = 5;
153+
optional bytes key = 6;
154+
}
155+
156+
message PSResponse {
157+
repeated string topics = 1;
158+
repeated bytes peerIDs = 2;
159+
}
160+
161+
message PeerstoreRequest {
162+
enum Type {
163+
GET_PROTOCOLS = 1;
164+
GET_PEER_INFO = 2;
165+
}
166+
167+
required Type type = 1;
168+
optional bytes id = 2;
169+
repeated string protos = 3;
170+
}
171+
172+
message PeerstoreResponse {
173+
optional PeerInfo peer = 1;
174+
repeated string protos = 2;
175+
}

‎packages/protons/test/fixtures/daemon.ts

+552
Large diffs are not rendered by default.
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
syntax = "proto3";
2+
3+
message Peer {
4+
// Multiaddrs we know about
5+
repeated Address addresses = 1;
6+
7+
// The protocols the peer supports
8+
repeated string protocols = 2;
9+
10+
// Any peer metadata
11+
repeated Metadata metadata = 3;
12+
13+
// The public key of the peer
14+
optional bytes pub_key = 4;
15+
16+
// The most recently received signed PeerRecord
17+
optional bytes peer_record_envelope = 5;
18+
}
19+
20+
// Address represents a single multiaddr
21+
message Address {
22+
bytes multiaddr = 1;
23+
24+
// Flag to indicate if the address comes from a certified source
25+
optional bool isCertified = 2;
26+
}
27+
28+
message Metadata {
29+
string key = 1;
30+
bytes value = 2;
31+
}
+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/* eslint-disable import/export */
2+
/* eslint-disable @typescript-eslint/no-namespace */
3+
4+
import { encodeMessage, decodeMessage, message, string, bytes, bool } from 'protons-runtime'
5+
6+
export interface Peer {
7+
addresses: Address[]
8+
protocols: string[]
9+
metadata: Metadata[]
10+
pubKey?: Uint8Array
11+
peerRecordEnvelope?: Uint8Array
12+
}
13+
14+
export namespace Peer {
15+
export const codec = () => {
16+
return message<Peer>({
17+
1: { name: 'addresses', codec: Address.codec(), repeats: true },
18+
2: { name: 'protocols', codec: string, repeats: true },
19+
3: { name: 'metadata', codec: Metadata.codec(), repeats: true },
20+
4: { name: 'pubKey', codec: bytes, optional: true },
21+
5: { name: 'peerRecordEnvelope', codec: bytes, optional: true }
22+
})
23+
}
24+
25+
export const encode = (obj: Peer): Uint8Array => {
26+
return encodeMessage(obj, Peer.codec())
27+
}
28+
29+
export const decode = (buf: Uint8Array): Peer => {
30+
return decodeMessage(buf, Peer.codec())
31+
}
32+
}
33+
34+
export interface Address {
35+
multiaddr: Uint8Array
36+
isCertified?: boolean
37+
}
38+
39+
export namespace Address {
40+
export const codec = () => {
41+
return message<Address>({
42+
1: { name: 'multiaddr', codec: bytes },
43+
2: { name: 'isCertified', codec: bool, optional: true }
44+
})
45+
}
46+
47+
export const encode = (obj: Address): Uint8Array => {
48+
return encodeMessage(obj, Address.codec())
49+
}
50+
51+
export const decode = (buf: Uint8Array): Address => {
52+
return decodeMessage(buf, Address.codec())
53+
}
54+
}
55+
56+
export interface Metadata {
57+
key: string
58+
value: Uint8Array
59+
}
60+
61+
export namespace Metadata {
62+
export const codec = () => {
63+
return message<Metadata>({
64+
1: { name: 'key', codec: string },
65+
2: { name: 'value', codec: bytes }
66+
})
67+
}
68+
69+
export const encode = (obj: Metadata): Uint8Array => {
70+
return encodeMessage(obj, Metadata.codec())
71+
}
72+
73+
export const decode = (buf: Uint8Array): Metadata => {
74+
return decodeMessage(buf, Metadata.codec())
75+
}
76+
}

‎packages/protons/test/index.spec.ts

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-env mocha */
22
/* eslint-disable @typescript-eslint/restrict-template-expressions */
33

4-
import { expect } from 'aegir/utils/chai.js'
4+
import { expect } from 'aegir/chai'
55
import pbjs from 'pbjs'
66
import { Basic } from './fixtures/basic.js'
77
import { AllTheTypes, AnEnum } from './fixtures/test.js'
88
import fs from 'fs'
99
import protobufjs from 'protobufjs'
10+
import { Peer } from './fixtures/peer.js'
1011

1112
const Long = protobufjs.util.Long
1213

@@ -136,4 +137,27 @@ describe('encode', () => {
136137
expect(AllTheTypes.decode(encoded)).to.deep.equal(allTheTypes)
137138
expect(AllTheTypes.decode(pbjsBuf)).to.deep.equal(allTheTypes)
138139
})
140+
141+
it('decodes multiple sub messages', () => {
142+
const peer: Peer = {
143+
protocols: ['protocol1', 'protocol2'],
144+
metadata: [],
145+
addresses: [{
146+
multiaddr: Uint8Array.from([4, 127, 0, 0, 1, 6, 31, 64]),
147+
isCertified: false
148+
}, {
149+
multiaddr: Uint8Array.from([4, 20, 0, 0, 1, 6, 31, 65]),
150+
isCertified: false
151+
}]
152+
}
153+
154+
const schema = pbjs.parseSchema(fs.readFileSync('./test/fixtures/peer.proto', 'utf-8')).compile()
155+
const pbjsBuf = schema.encodePeer(peer)
156+
157+
const encoded = Peer.encode(peer)
158+
expect(encoded).to.equalBytes(pbjsBuf)
159+
160+
expect(Peer.decode(encoded)).to.deep.equal(peer)
161+
expect(Peer.decode(pbjsBuf)).to.deep.equal(peer)
162+
})
139163
})

‎packages/protons/tsconfig.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"extends": "aegir/src/config/tsconfig.aegir.json",
33
"compilerOptions": {
4-
"outDir": "dist",
5-
"emitDeclarationOnly": false,
6-
"module": "ES2020"
4+
"outDir": "dist"
75
},
86
"include": [
97
"bin",

0 commit comments

Comments
 (0)
Please sign in to comment.