eventbus-grpc 0.0.0-stage → 0.38.0
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/events_grpc_dc.js +25 -0
- package/events_pb.js +298 -0
- package/index.js +2 -0
- package/package.json +9 -4
- package/README.md +0 -3
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Generated code: use without restriction (see GENERATED-CODE-LICENSE.md).
|
|
2
|
+
// @generated by protoc-gen-grpc-dc-js. DO NOT EDIT.
|
|
3
|
+
// source: events.proto
|
|
4
|
+
import { PublishRequest, PublishReply, SubscribeRequest, Event } from "./events_pb.js";
|
|
5
|
+
|
|
6
|
+
export class EventBusClient {
|
|
7
|
+
#channel;
|
|
8
|
+
constructor(channel) { this.#channel = channel; }
|
|
9
|
+
async publish(request, options) {
|
|
10
|
+
return this.#channel.unary("/grpcdc.events.v1.EventBus/Publish", request, PublishRequest, PublishReply, options);
|
|
11
|
+
}
|
|
12
|
+
subscribe(request, options) {
|
|
13
|
+
return this.#channel.serverStream("/grpcdc.events.v1.EventBus/Subscribe", request, SubscribeRequest, Event, options);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function createEventBusService(handlers) {
|
|
18
|
+
return {
|
|
19
|
+
name: "grpcdc.events.v1.EventBus",
|
|
20
|
+
methods: {
|
|
21
|
+
Publish: { path: "/grpcdc.events.v1.EventBus/Publish", kind: "unary", requestType: PublishRequest, responseType: PublishReply, handler: handlers.publish },
|
|
22
|
+
Subscribe: { path: "/grpcdc.events.v1.EventBus/Subscribe", kind: "server-streaming", requestType: SubscribeRequest, responseType: Event, handler: handlers.subscribe },
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
package/events_pb.js
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
// Generated code: use without restriction (see GENERATED-CODE-LICENSE.md).
|
|
2
|
+
// @generated by protoc-gen-grpc-dc-js. DO NOT EDIT.
|
|
3
|
+
// source: events.proto
|
|
4
|
+
|
|
5
|
+
function varintBytes(value) {
|
|
6
|
+
let n = BigInt.asUintN(64, BigInt(value));
|
|
7
|
+
const out = [];
|
|
8
|
+
while (n > 0x7fn) {
|
|
9
|
+
out.push(Number((n & 0x7fn) | 0x80n));
|
|
10
|
+
n >>= 7n;
|
|
11
|
+
}
|
|
12
|
+
out.push(Number(n));
|
|
13
|
+
return out;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function zz64(v) {
|
|
17
|
+
const b = BigInt(v);
|
|
18
|
+
return (b << 1n) ^ (b >> 63n);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function unzz64(v) {
|
|
22
|
+
return (v >> 1n) ^ (-(v & 1n));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class Reader {
|
|
26
|
+
constructor(bytes) {
|
|
27
|
+
this.bytes = bytes;
|
|
28
|
+
this.pos = 0;
|
|
29
|
+
}
|
|
30
|
+
get done() {
|
|
31
|
+
return this.pos >= this.bytes.length;
|
|
32
|
+
}
|
|
33
|
+
varint() {
|
|
34
|
+
let result = 0n;
|
|
35
|
+
let shift = 0n;
|
|
36
|
+
for (;;) {
|
|
37
|
+
if (this.pos >= this.bytes.length) throw new Error("truncated varint");
|
|
38
|
+
const byte = this.bytes[this.pos++];
|
|
39
|
+
result |= BigInt(byte & 0x7f) << shift;
|
|
40
|
+
if ((byte & 0x80) === 0) return result;
|
|
41
|
+
shift += 7n;
|
|
42
|
+
if (shift >= 64n) throw new Error("varint too long");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
take(n) {
|
|
46
|
+
const value = this.bytes.slice(this.pos, this.pos + n);
|
|
47
|
+
if (value.length !== n) throw new Error("truncated field");
|
|
48
|
+
this.pos += n;
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
field() {
|
|
52
|
+
if (this.done) return null;
|
|
53
|
+
const start = this.pos;
|
|
54
|
+
const tag = this.varint();
|
|
55
|
+
const field = Number(tag >> 3n);
|
|
56
|
+
const wire = Number(tag & 7n);
|
|
57
|
+
switch (wire) {
|
|
58
|
+
case 0:
|
|
59
|
+
return [field, wire, this.varint(), this.bytes.slice(start, this.pos)];
|
|
60
|
+
case 2: {
|
|
61
|
+
const len = Number(this.varint());
|
|
62
|
+
const v = this.take(len);
|
|
63
|
+
return [field, wire, v, this.bytes.slice(start, this.pos)];
|
|
64
|
+
}
|
|
65
|
+
case 1: {
|
|
66
|
+
const v = this.take(8);
|
|
67
|
+
return [field, wire, v, this.bytes.slice(start, this.pos)];
|
|
68
|
+
}
|
|
69
|
+
case 5: {
|
|
70
|
+
const v = this.take(4);
|
|
71
|
+
return [field, wire, v, this.bytes.slice(start, this.pos)];
|
|
72
|
+
}
|
|
73
|
+
default:
|
|
74
|
+
throw new Error("bad wire type " + wire);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function concatBytes(a, b) {
|
|
80
|
+
const out = new Uint8Array(a.length + b.length);
|
|
81
|
+
out.set(a);
|
|
82
|
+
out.set(b, a.length);
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function putRaw(out, bytes) {
|
|
87
|
+
for (let i = 0; i < bytes.length; i++) out.push(bytes[i]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function putTag(out, num, wire) {
|
|
91
|
+
out.push(...varintBytes((BigInt(num) << 3n) | BigInt(wire)));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function putVarintField(out, num, value) {
|
|
95
|
+
if (value === 0n) return;
|
|
96
|
+
putTag(out, num, 0);
|
|
97
|
+
out.push(...varintBytes(value));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function putBytesField(out, num, payload) {
|
|
101
|
+
putTag(out, num, 2);
|
|
102
|
+
putRaw(out, varintBytes(payload.length));
|
|
103
|
+
putRaw(out, payload);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function putStringField(out, num, value) {
|
|
107
|
+
if (!value) return;
|
|
108
|
+
putBytesField(out, num, new TextEncoder().encode(value));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function putFixedField(out, num, payload) {
|
|
112
|
+
putTag(out, num, payload.length === 8 ? 1 : 5);
|
|
113
|
+
out.push(...payload);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function fixedBytes(value, size, write) {
|
|
117
|
+
const bytes = new Uint8Array(size);
|
|
118
|
+
write(new DataView(bytes.buffer), value);
|
|
119
|
+
return bytes;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function readFixed(bytes, read) {
|
|
123
|
+
return read(new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const Tag = { TAG_UNSPECIFIED: 0, TOPIC: 1, SOURCE: 2, KIND: 3 };
|
|
127
|
+
|
|
128
|
+
export class TagValue {
|
|
129
|
+
constructor({ tag = 0, stringValue = "", intValue = 0n, doubleValue = 0, boolValue = false, enumValue = 0 } = {}) {
|
|
130
|
+
this.tag = tag;
|
|
131
|
+
this.stringValue = stringValue;
|
|
132
|
+
this.intValue = intValue;
|
|
133
|
+
this.doubleValue = doubleValue;
|
|
134
|
+
this.boolValue = boolValue;
|
|
135
|
+
this.enumValue = enumValue;
|
|
136
|
+
this.unknownFields = new Uint8Array(0);
|
|
137
|
+
}
|
|
138
|
+
static encode(msg) {
|
|
139
|
+
const out = [];
|
|
140
|
+
putVarintField(out, 1, BigInt(msg.tag));
|
|
141
|
+
if (!(msg.intValue !== 0n || msg.doubleValue !== 0 || msg.boolValue || msg.enumValue !== 0)) {
|
|
142
|
+
putStringField(out, 2, msg.stringValue);
|
|
143
|
+
}
|
|
144
|
+
if (!(msg.doubleValue !== 0 || msg.boolValue || msg.enumValue !== 0)) {
|
|
145
|
+
putVarintField(out, 3, BigInt(msg.intValue));
|
|
146
|
+
}
|
|
147
|
+
if (!(msg.boolValue || msg.enumValue !== 0)) {
|
|
148
|
+
if (msg.doubleValue) putFixedField(out, 4, fixedBytes(msg.doubleValue, 8, (dv, x) => dv.setFloat64(0, x, true)));
|
|
149
|
+
}
|
|
150
|
+
if (!(msg.enumValue !== 0)) {
|
|
151
|
+
putVarintField(out, 5, (msg.boolValue ? 1n : 0n));
|
|
152
|
+
}
|
|
153
|
+
putVarintField(out, 6, BigInt(msg.enumValue));
|
|
154
|
+
putRaw(out, msg.unknownFields);
|
|
155
|
+
return new Uint8Array(out);
|
|
156
|
+
}
|
|
157
|
+
static decode(bytes) {
|
|
158
|
+
const msg = new TagValue();
|
|
159
|
+
const reader = new Reader(bytes);
|
|
160
|
+
let f;
|
|
161
|
+
while ((f = reader.field()) !== null) {
|
|
162
|
+
const [num, wire, value, raw] = f;
|
|
163
|
+
switch (num) {
|
|
164
|
+
case 1: msg.tag = Number(BigInt.asIntN(32, value)); break;
|
|
165
|
+
case 2: msg.intValue = 0n; msg.doubleValue = 0; msg.boolValue = false; msg.enumValue = 0; msg.stringValue = new TextDecoder().decode(value); break;
|
|
166
|
+
case 3: msg.stringValue = ""; msg.doubleValue = 0; msg.boolValue = false; msg.enumValue = 0; msg.intValue = BigInt.asIntN(64, value); break;
|
|
167
|
+
case 4: msg.stringValue = ""; msg.intValue = 0n; msg.boolValue = false; msg.enumValue = 0; msg.doubleValue = readFixed(value, (dv) => dv.getFloat64(0, true)); break;
|
|
168
|
+
case 5: msg.stringValue = ""; msg.intValue = 0n; msg.doubleValue = 0; msg.enumValue = 0; msg.boolValue = value !== 0n; break;
|
|
169
|
+
case 6: msg.stringValue = ""; msg.intValue = 0n; msg.doubleValue = 0; msg.boolValue = false; msg.enumValue = Number(BigInt.asIntN(32, value)); break;
|
|
170
|
+
default: msg.unknownFields = concatBytes(msg.unknownFields, raw); break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return msg;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export class PublishRequest {
|
|
178
|
+
constructor({ tags = [], payload = new Uint8Array(0), publisherId = "" } = {}) {
|
|
179
|
+
this.tags = tags;
|
|
180
|
+
this.payload = payload;
|
|
181
|
+
this.publisherId = publisherId;
|
|
182
|
+
this.unknownFields = new Uint8Array(0);
|
|
183
|
+
}
|
|
184
|
+
static encode(msg) {
|
|
185
|
+
const out = [];
|
|
186
|
+
if (msg.tags) for (const v of msg.tags) putBytesField(out, 1, TagValue.encode(v));
|
|
187
|
+
if (msg.payload && msg.payload.length) putBytesField(out, 2, msg.payload);
|
|
188
|
+
putStringField(out, 3, msg.publisherId);
|
|
189
|
+
putRaw(out, msg.unknownFields);
|
|
190
|
+
return new Uint8Array(out);
|
|
191
|
+
}
|
|
192
|
+
static decode(bytes) {
|
|
193
|
+
const msg = new PublishRequest();
|
|
194
|
+
const reader = new Reader(bytes);
|
|
195
|
+
let f;
|
|
196
|
+
while ((f = reader.field()) !== null) {
|
|
197
|
+
const [num, wire, value, raw] = f;
|
|
198
|
+
switch (num) {
|
|
199
|
+
case 1: msg.tags.push(TagValue.decode(value)); break;
|
|
200
|
+
case 2: msg.payload = value; break;
|
|
201
|
+
case 3: msg.publisherId = new TextDecoder().decode(value); break;
|
|
202
|
+
default: msg.unknownFields = concatBytes(msg.unknownFields, raw); break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return msg;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export class PublishReply {
|
|
210
|
+
constructor({ seq = 0n } = {}) {
|
|
211
|
+
this.seq = seq;
|
|
212
|
+
this.unknownFields = new Uint8Array(0);
|
|
213
|
+
}
|
|
214
|
+
static encode(msg) {
|
|
215
|
+
const out = [];
|
|
216
|
+
putVarintField(out, 1, BigInt(msg.seq));
|
|
217
|
+
putRaw(out, msg.unknownFields);
|
|
218
|
+
return new Uint8Array(out);
|
|
219
|
+
}
|
|
220
|
+
static decode(bytes) {
|
|
221
|
+
const msg = new PublishReply();
|
|
222
|
+
const reader = new Reader(bytes);
|
|
223
|
+
let f;
|
|
224
|
+
while ((f = reader.field()) !== null) {
|
|
225
|
+
const [num, wire, value, raw] = f;
|
|
226
|
+
switch (num) {
|
|
227
|
+
case 1: msg.seq = BigInt.asUintN(64, value); break;
|
|
228
|
+
default: msg.unknownFields = concatBytes(msg.unknownFields, raw); break;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return msg;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export class SubscribeRequest {
|
|
236
|
+
constructor({ filter = [] } = {}) {
|
|
237
|
+
this.filter = filter;
|
|
238
|
+
this.unknownFields = new Uint8Array(0);
|
|
239
|
+
}
|
|
240
|
+
static encode(msg) {
|
|
241
|
+
const out = [];
|
|
242
|
+
if (msg.filter) for (const v of msg.filter) putBytesField(out, 1, TagValue.encode(v));
|
|
243
|
+
putRaw(out, msg.unknownFields);
|
|
244
|
+
return new Uint8Array(out);
|
|
245
|
+
}
|
|
246
|
+
static decode(bytes) {
|
|
247
|
+
const msg = new SubscribeRequest();
|
|
248
|
+
const reader = new Reader(bytes);
|
|
249
|
+
let f;
|
|
250
|
+
while ((f = reader.field()) !== null) {
|
|
251
|
+
const [num, wire, value, raw] = f;
|
|
252
|
+
switch (num) {
|
|
253
|
+
case 1: msg.filter.push(TagValue.decode(value)); break;
|
|
254
|
+
default: msg.unknownFields = concatBytes(msg.unknownFields, raw); break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return msg;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export class Event {
|
|
262
|
+
constructor({ tags = [], payload = new Uint8Array(0), seq = 0n, publisherId = "", timestampUnixMs = 0n } = {}) {
|
|
263
|
+
this.tags = tags;
|
|
264
|
+
this.payload = payload;
|
|
265
|
+
this.seq = seq;
|
|
266
|
+
this.publisherId = publisherId;
|
|
267
|
+
this.timestampUnixMs = timestampUnixMs;
|
|
268
|
+
this.unknownFields = new Uint8Array(0);
|
|
269
|
+
}
|
|
270
|
+
static encode(msg) {
|
|
271
|
+
const out = [];
|
|
272
|
+
if (msg.tags) for (const v of msg.tags) putBytesField(out, 1, TagValue.encode(v));
|
|
273
|
+
if (msg.payload && msg.payload.length) putBytesField(out, 2, msg.payload);
|
|
274
|
+
putVarintField(out, 3, BigInt(msg.seq));
|
|
275
|
+
putStringField(out, 4, msg.publisherId);
|
|
276
|
+
putVarintField(out, 5, BigInt(msg.timestampUnixMs));
|
|
277
|
+
putRaw(out, msg.unknownFields);
|
|
278
|
+
return new Uint8Array(out);
|
|
279
|
+
}
|
|
280
|
+
static decode(bytes) {
|
|
281
|
+
const msg = new Event();
|
|
282
|
+
const reader = new Reader(bytes);
|
|
283
|
+
let f;
|
|
284
|
+
while ((f = reader.field()) !== null) {
|
|
285
|
+
const [num, wire, value, raw] = f;
|
|
286
|
+
switch (num) {
|
|
287
|
+
case 1: msg.tags.push(TagValue.decode(value)); break;
|
|
288
|
+
case 2: msg.payload = value; break;
|
|
289
|
+
case 3: msg.seq = BigInt.asUintN(64, value); break;
|
|
290
|
+
case 4: msg.publisherId = new TextDecoder().decode(value); break;
|
|
291
|
+
case 5: msg.timestampUnixMs = BigInt.asIntN(64, value); break;
|
|
292
|
+
default: msg.unknownFields = concatBytes(msg.unknownFields, raw); break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
return msg;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eventbus-grpc",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.38.0",
|
|
4
|
+
"description": "Event bus over gRPC — generated grpcdc.events.v1 publish/subscribe clients over WebRTC DataChannels, via the grpc-dc runtime (JavaScript, browser + Node)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"files": ["index.js", "events_pb.js", "events_grpc_dc.js"],
|
|
8
|
+
"dependencies": {"grpc-dc": "^0.38.0"},
|
|
9
|
+
"license": "Apache-2.0",
|
|
10
|
+
"repository": {"type": "git", "url": "git+https://github.com/browser-grpc/grpc-over-datachannels.git"}
|
|
11
|
+
}
|
package/README.md
DELETED