@waku/interfaces 0.0.1 → 0.0.3
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/dist/index.d.ts +25 -15
- package/package.json +3 -94
- package/src/index.ts +27 -14
package/dist/index.d.ts
CHANGED
@@ -23,10 +23,10 @@ export declare type ProtocolOptions = {
|
|
23
23
|
};
|
24
24
|
export declare type Callback<T extends Message> = (msg: T) => void | Promise<void>;
|
25
25
|
export interface Filter extends PointToPointProtocol {
|
26
|
-
subscribe: <T extends
|
26
|
+
subscribe: <T extends DecodedMessage>(decoders: Decoder<T>[], callback: Callback<T>, opts?: ProtocolOptions) => Promise<() => Promise<void>>;
|
27
27
|
}
|
28
28
|
export interface LightPush extends PointToPointProtocol {
|
29
|
-
push: (encoder: Encoder, message:
|
29
|
+
push: (encoder: Encoder, message: Message, opts?: ProtocolOptions) => Promise<SendResult>;
|
30
30
|
}
|
31
31
|
export declare enum PageDirection {
|
32
32
|
BACKWARD = "backward",
|
@@ -50,8 +50,6 @@ export declare type StoreQueryOptions = {
|
|
50
50
|
pageDirection?: PageDirection;
|
51
51
|
/**
|
52
52
|
* The number of message per page.
|
53
|
-
*
|
54
|
-
* @default { @link DefaultPageSize }
|
55
53
|
*/
|
56
54
|
pageSize?: number;
|
57
55
|
/**
|
@@ -60,13 +58,13 @@ export declare type StoreQueryOptions = {
|
|
60
58
|
timeFilter?: TimeFilter;
|
61
59
|
} & ProtocolOptions;
|
62
60
|
export interface Store extends PointToPointProtocol {
|
63
|
-
queryOrderedCallback: <T extends
|
64
|
-
queryCallbackOnPromise: <T extends
|
65
|
-
queryGenerator: <T extends
|
61
|
+
queryOrderedCallback: <T extends DecodedMessage>(decoders: Decoder<T>[], callback: (message: T) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
|
62
|
+
queryCallbackOnPromise: <T extends DecodedMessage>(decoders: Decoder<T>[], callback: (message: Promise<T | undefined>) => Promise<void | boolean> | boolean | void, options?: StoreQueryOptions) => Promise<void>;
|
63
|
+
queryGenerator: <T extends DecodedMessage>(decoders: Decoder<T>[], options?: StoreQueryOptions) => AsyncGenerator<Promise<T | undefined>[]>;
|
66
64
|
}
|
67
65
|
export interface Relay extends GossipSub {
|
68
|
-
send: (encoder: Encoder, message:
|
69
|
-
addObserver: <T extends
|
66
|
+
send: (encoder: Encoder, message: Message) => Promise<SendResult>;
|
67
|
+
addObserver: <T extends DecodedMessage>(decoder: Decoder<T>, callback: Callback<T>) => () => void;
|
70
68
|
getMeshPeers: () => string[];
|
71
69
|
}
|
72
70
|
export interface Waku {
|
@@ -108,6 +106,10 @@ export interface RateLimitProof {
|
|
108
106
|
nullifier: Uint8Array;
|
109
107
|
rlnIdentifier: Uint8Array;
|
110
108
|
}
|
109
|
+
/**
|
110
|
+
* Interface matching the protobuf library.
|
111
|
+
* Field types matches the protobuf type over the wire
|
112
|
+
*/
|
111
113
|
export interface ProtoMessage {
|
112
114
|
payload: Uint8Array | undefined;
|
113
115
|
contentTopic: string | undefined;
|
@@ -115,18 +117,26 @@ export interface ProtoMessage {
|
|
115
117
|
timestamp: bigint | undefined;
|
116
118
|
rateLimitProof: RateLimitProof | undefined;
|
117
119
|
}
|
120
|
+
/**
|
121
|
+
* Interface for messages to encode and send.
|
122
|
+
*/
|
118
123
|
export interface Message {
|
124
|
+
payload?: Uint8Array;
|
125
|
+
timestamp?: Date;
|
126
|
+
rateLimitProof?: RateLimitProof;
|
127
|
+
}
|
128
|
+
export interface Encoder {
|
129
|
+
contentTopic: string;
|
130
|
+
toWire: (message: Message) => Promise<Uint8Array | undefined>;
|
131
|
+
toProtoObj: (message: Message) => Promise<ProtoMessage | undefined>;
|
132
|
+
}
|
133
|
+
export interface DecodedMessage {
|
119
134
|
payload: Uint8Array | undefined;
|
120
135
|
contentTopic: string | undefined;
|
121
136
|
timestamp: Date | undefined;
|
122
137
|
rateLimitProof: RateLimitProof | undefined;
|
123
138
|
}
|
124
|
-
export interface
|
125
|
-
contentTopic: string;
|
126
|
-
toWire: (message: Partial<Message>) => Promise<Uint8Array | undefined>;
|
127
|
-
toProtoObj: (message: Partial<Message>) => Promise<ProtoMessage | undefined>;
|
128
|
-
}
|
129
|
-
export interface Decoder<T extends Message> {
|
139
|
+
export interface Decoder<T extends DecodedMessage> {
|
130
140
|
contentTopic: string;
|
131
141
|
fromWireToProtoObj: (bytes: Uint8Array) => Promise<ProtoMessage | undefined>;
|
132
142
|
fromProtoObj: (proto: ProtoMessage) => Promise<T | undefined>;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@waku/interfaces",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.3",
|
4
4
|
"description": "Definition of Waku interfaces",
|
5
5
|
"types": "./dist/index.d.ts",
|
6
6
|
"module": "./dist/index.js",
|
@@ -42,8 +42,7 @@
|
|
42
42
|
"check:spelling": "cspell \"{README.md,src/**/*.ts}\"",
|
43
43
|
"check:tsc": "tsc -p tsconfig.dev.json",
|
44
44
|
"prepublish": "npm run build",
|
45
|
-
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
46
|
-
"release": "semantic-release"
|
45
|
+
"reset-hard": "git clean -dfx -e .idea && git reset --hard && npm i && npm run build"
|
47
46
|
},
|
48
47
|
"engines": {
|
49
48
|
"node": ">=16"
|
@@ -54,15 +53,9 @@
|
|
54
53
|
"@libp2p/interface-peer-id": "^1.0.5",
|
55
54
|
"@libp2p/interface-peer-store": "^1.2.2",
|
56
55
|
"@multiformats/multiaddr": "^11.0.6",
|
57
|
-
"libp2p": "0.
|
56
|
+
"libp2p": "0.39.2"
|
58
57
|
},
|
59
58
|
"devDependencies": {
|
60
|
-
"@semantic-release/changelog": "^6.0.1",
|
61
|
-
"@semantic-release/commit-analyzer": "^9.0.2",
|
62
|
-
"@semantic-release/git": "^10.0.1",
|
63
|
-
"@semantic-release/github": "^8.0.6",
|
64
|
-
"@semantic-release/npm": "^9.0.1",
|
65
|
-
"@semantic-release/release-notes-generator": "^10.0.3",
|
66
59
|
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
67
60
|
"@typescript-eslint/parser": "^5.8.1",
|
68
61
|
"cspell": "^5.14.0",
|
@@ -74,92 +67,8 @@
|
|
74
67
|
"eslint-plugin-prettier": "^4.0.0",
|
75
68
|
"npm-run-all": "^4.1.5",
|
76
69
|
"prettier": "^2.1.1",
|
77
|
-
"semantic-release": "^19.0.5",
|
78
|
-
"semantic-release-monorepo": "^7.0.5",
|
79
70
|
"typescript": "^4.6.3"
|
80
71
|
},
|
81
|
-
"release": {
|
82
|
-
"branches": [
|
83
|
-
"master"
|
84
|
-
],
|
85
|
-
"extends": "semantic-release-monorepo",
|
86
|
-
"plugins": [
|
87
|
-
[
|
88
|
-
"@semantic-release/commit-analyzer",
|
89
|
-
{
|
90
|
-
"preset": "conventionalcommits",
|
91
|
-
"releaseRules": [
|
92
|
-
{
|
93
|
-
"breaking": true,
|
94
|
-
"release": "patch"
|
95
|
-
},
|
96
|
-
{
|
97
|
-
"revert": true,
|
98
|
-
"release": "patch"
|
99
|
-
},
|
100
|
-
{
|
101
|
-
"type": "feat",
|
102
|
-
"release": "patch"
|
103
|
-
},
|
104
|
-
{
|
105
|
-
"type": "fix",
|
106
|
-
"release": "patch"
|
107
|
-
},
|
108
|
-
{
|
109
|
-
"type": "doc",
|
110
|
-
"release": "patch"
|
111
|
-
},
|
112
|
-
{
|
113
|
-
"type": "test",
|
114
|
-
"release": "patch"
|
115
|
-
},
|
116
|
-
{
|
117
|
-
"scope": "deps",
|
118
|
-
"release": "patch"
|
119
|
-
},
|
120
|
-
{
|
121
|
-
"scope": "no-release",
|
122
|
-
"release": false
|
123
|
-
}
|
124
|
-
]
|
125
|
-
}
|
126
|
-
],
|
127
|
-
[
|
128
|
-
"@semantic-release/release-notes-generator",
|
129
|
-
{
|
130
|
-
"preset": "conventionalcommits",
|
131
|
-
"presetConfig": {
|
132
|
-
"types": [
|
133
|
-
{
|
134
|
-
"type": "feat",
|
135
|
-
"section": "Features"
|
136
|
-
},
|
137
|
-
{
|
138
|
-
"type": "fix",
|
139
|
-
"section": "Bug Fixes"
|
140
|
-
},
|
141
|
-
{
|
142
|
-
"type": "chore",
|
143
|
-
"section": "Trivial Changes"
|
144
|
-
},
|
145
|
-
{
|
146
|
-
"type": "doc",
|
147
|
-
"section": "Documentation"
|
148
|
-
},
|
149
|
-
{
|
150
|
-
"type": "test",
|
151
|
-
"section": "Tests"
|
152
|
-
}
|
153
|
-
]
|
154
|
-
}
|
155
|
-
}
|
156
|
-
],
|
157
|
-
"@semantic-release/changelog",
|
158
|
-
"@semantic-release/npm",
|
159
|
-
"@semantic-release/github",
|
160
|
-
"@semantic-release/git"
|
161
|
-
]
|
162
|
-
},
|
163
72
|
"typedoc": {
|
164
73
|
"entryPoint": "./src/index.ts"
|
165
74
|
},
|
package/src/index.ts
CHANGED
@@ -28,7 +28,7 @@ export type ProtocolOptions = {
|
|
28
28
|
export type Callback<T extends Message> = (msg: T) => void | Promise<void>;
|
29
29
|
|
30
30
|
export interface Filter extends PointToPointProtocol {
|
31
|
-
subscribe: <T extends
|
31
|
+
subscribe: <T extends DecodedMessage>(
|
32
32
|
decoders: Decoder<T>[],
|
33
33
|
callback: Callback<T>,
|
34
34
|
opts?: ProtocolOptions
|
@@ -38,7 +38,7 @@ export interface Filter extends PointToPointProtocol {
|
|
38
38
|
export interface LightPush extends PointToPointProtocol {
|
39
39
|
push: (
|
40
40
|
encoder: Encoder,
|
41
|
-
message:
|
41
|
+
message: Message,
|
42
42
|
opts?: ProtocolOptions
|
43
43
|
) => Promise<SendResult>;
|
44
44
|
}
|
@@ -76,27 +76,27 @@ export type StoreQueryOptions = {
|
|
76
76
|
} & ProtocolOptions;
|
77
77
|
|
78
78
|
export interface Store extends PointToPointProtocol {
|
79
|
-
queryOrderedCallback: <T extends
|
79
|
+
queryOrderedCallback: <T extends DecodedMessage>(
|
80
80
|
decoders: Decoder<T>[],
|
81
81
|
callback: (message: T) => Promise<void | boolean> | boolean | void,
|
82
82
|
options?: StoreQueryOptions
|
83
83
|
) => Promise<void>;
|
84
|
-
queryCallbackOnPromise: <T extends
|
84
|
+
queryCallbackOnPromise: <T extends DecodedMessage>(
|
85
85
|
decoders: Decoder<T>[],
|
86
86
|
callback: (
|
87
87
|
message: Promise<T | undefined>
|
88
88
|
) => Promise<void | boolean> | boolean | void,
|
89
89
|
options?: StoreQueryOptions
|
90
90
|
) => Promise<void>;
|
91
|
-
queryGenerator: <T extends
|
91
|
+
queryGenerator: <T extends DecodedMessage>(
|
92
92
|
decoders: Decoder<T>[],
|
93
93
|
options?: StoreQueryOptions
|
94
94
|
) => AsyncGenerator<Promise<T | undefined>[]>;
|
95
95
|
}
|
96
96
|
|
97
97
|
export interface Relay extends GossipSub {
|
98
|
-
send: (encoder: Encoder, message:
|
99
|
-
addObserver: <T extends
|
98
|
+
send: (encoder: Encoder, message: Message) => Promise<SendResult>;
|
99
|
+
addObserver: <T extends DecodedMessage>(
|
100
100
|
decoder: Decoder<T>,
|
101
101
|
callback: Callback<T>
|
102
102
|
) => () => void;
|
@@ -155,6 +155,10 @@ export interface RateLimitProof {
|
|
155
155
|
rlnIdentifier: Uint8Array;
|
156
156
|
}
|
157
157
|
|
158
|
+
/**
|
159
|
+
* Interface matching the protobuf library.
|
160
|
+
* Field types matches the protobuf type over the wire
|
161
|
+
*/
|
158
162
|
export interface ProtoMessage {
|
159
163
|
payload: Uint8Array | undefined;
|
160
164
|
contentTopic: string | undefined;
|
@@ -163,20 +167,29 @@ export interface ProtoMessage {
|
|
163
167
|
rateLimitProof: RateLimitProof | undefined;
|
164
168
|
}
|
165
169
|
|
170
|
+
/**
|
171
|
+
* Interface for messages to encode and send.
|
172
|
+
*/
|
166
173
|
export interface Message {
|
167
|
-
payload
|
168
|
-
|
169
|
-
|
170
|
-
rateLimitProof: RateLimitProof | undefined;
|
174
|
+
payload?: Uint8Array;
|
175
|
+
timestamp?: Date;
|
176
|
+
rateLimitProof?: RateLimitProof;
|
171
177
|
}
|
172
178
|
|
173
179
|
export interface Encoder {
|
174
180
|
contentTopic: string;
|
175
|
-
toWire: (message:
|
176
|
-
toProtoObj: (message:
|
181
|
+
toWire: (message: Message) => Promise<Uint8Array | undefined>;
|
182
|
+
toProtoObj: (message: Message) => Promise<ProtoMessage | undefined>;
|
183
|
+
}
|
184
|
+
|
185
|
+
export interface DecodedMessage {
|
186
|
+
payload: Uint8Array | undefined;
|
187
|
+
contentTopic: string | undefined;
|
188
|
+
timestamp: Date | undefined;
|
189
|
+
rateLimitProof: RateLimitProof | undefined;
|
177
190
|
}
|
178
191
|
|
179
|
-
export interface Decoder<T extends
|
192
|
+
export interface Decoder<T extends DecodedMessage> {
|
180
193
|
contentTopic: string;
|
181
194
|
fromWireToProtoObj: (bytes: Uint8Array) => Promise<ProtoMessage | undefined>;
|
182
195
|
fromProtoObj: (proto: ProtoMessage) => Promise<T | undefined>;
|