@dxos/edge-client 0.6.12-main.ed7cda7 → 0.6.12-staging.0b4bb48
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/lib/browser/index.mjs +157 -57
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +154 -56
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/defs.d.ts.map +1 -1
- package/dist/types/src/edge-client.d.ts +2 -3
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +1 -4
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/protocol.d.ts +2 -2
- package/dist/types/src/protocol.d.ts.map +1 -1
- package/dist/types/src/test-utils.d.ts +11 -0
- package/dist/types/src/test-utils.d.ts.map +1 -0
- package/package.json +14 -26
- package/src/defs.ts +3 -2
- package/src/edge-client.test.ts +11 -11
- package/src/edge-client.ts +8 -17
- package/src/errors.ts +2 -8
- package/src/index.ts +0 -1
- package/src/persistent-lifecycle.test.ts +2 -2
- package/src/protocol.test.ts +2 -1
- package/src/protocol.ts +2 -2
- package/src/test-utils.ts +49 -0
- package/src/websocket.test.ts +4 -5
- package/dist/lib/browser/chunk-ZWJXA37R.mjs +0 -113
- package/dist/lib/browser/chunk-ZWJXA37R.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -122
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node/chunk-ANV2HBEH.cjs +0 -136
- package/dist/lib/node/chunk-ANV2HBEH.cjs.map +0 -7
- package/dist/lib/node/testing/index.cjs +0 -152
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs +0 -115
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -378
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -123
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/test-utils.d.ts +0 -20
- package/dist/types/src/testing/test-utils.d.ts.map +0 -1
- package/src/testing/index.ts +0 -5
- package/src/testing/test-utils.ts +0 -111
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Protocol,
|
|
3
|
-
getTypename,
|
|
4
|
-
protocol,
|
|
5
|
-
toUint8Array
|
|
6
|
-
} from "./chunk-ZWJXA37R.mjs";
|
|
7
|
-
|
|
8
1
|
// packages/core/mesh/edge-client/src/index.ts
|
|
9
2
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
10
3
|
|
|
@@ -12,19 +5,123 @@ export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
|
12
5
|
import WebSocket from "isomorphic-ws";
|
|
13
6
|
import { Trigger, Event, scheduleTaskInterval, scheduleTask, TriggerState } from "@dxos/async";
|
|
14
7
|
import { Context, LifecycleState as LifecycleState2, Resource as Resource2 } from "@dxos/context";
|
|
8
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
15
9
|
import { log as log2 } from "@dxos/log";
|
|
16
|
-
import { buf } from "@dxos/protocols/buf";
|
|
17
|
-
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
10
|
+
import { buf as buf2 } from "@dxos/protocols/buf";
|
|
11
|
+
import { MessageSchema as MessageSchema2 } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
18
12
|
|
|
19
|
-
// packages/core/mesh/edge-client/src/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
// packages/core/mesh/edge-client/src/defs.ts
|
|
14
|
+
import { AnySchema } from "@bufbuild/protobuf/wkt";
|
|
15
|
+
import { SwarmRequestSchema, SwarmResponseSchema, TextMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
16
|
+
|
|
17
|
+
// packages/core/mesh/edge-client/src/protocol.ts
|
|
18
|
+
import { invariant } from "@dxos/invariant";
|
|
19
|
+
import { buf, bufWkt } from "@dxos/protocols/buf";
|
|
20
|
+
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
21
|
+
import { bufferToArray } from "@dxos/util";
|
|
22
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/protocol.ts";
|
|
23
|
+
var getTypename = (typeName) => `type.googleapis.com/${typeName}`;
|
|
24
|
+
var Protocol = class {
|
|
25
|
+
constructor(types) {
|
|
26
|
+
this._typeRegistry = buf.createRegistry(...types);
|
|
27
|
+
}
|
|
28
|
+
get typeRegistry() {
|
|
29
|
+
return this._typeRegistry;
|
|
30
|
+
}
|
|
31
|
+
toJson(message) {
|
|
32
|
+
try {
|
|
33
|
+
return buf.toJson(MessageSchema, message, {
|
|
34
|
+
registry: this.typeRegistry
|
|
35
|
+
});
|
|
36
|
+
} catch (err) {
|
|
37
|
+
return {
|
|
38
|
+
type: this.getPayloadType(message)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Return the payload with the given type.
|
|
44
|
+
*/
|
|
45
|
+
getPayload(message, type) {
|
|
46
|
+
invariant(message.payload, void 0, {
|
|
47
|
+
F: __dxlog_file,
|
|
48
|
+
L: 40,
|
|
49
|
+
S: this,
|
|
50
|
+
A: [
|
|
51
|
+
"message.payload",
|
|
52
|
+
""
|
|
53
|
+
]
|
|
54
|
+
});
|
|
55
|
+
const payloadTypename = this.getPayloadType(message);
|
|
56
|
+
if (type && type.typeName !== payloadTypename) {
|
|
57
|
+
throw new Error(`Unexpected payload type: ${payloadTypename}; expected ${type.typeName}`);
|
|
58
|
+
}
|
|
59
|
+
invariant(bufWkt.anyIs(message.payload, type), `Unexpected payload type: ${payloadTypename}}`, {
|
|
60
|
+
F: __dxlog_file,
|
|
61
|
+
L: 46,
|
|
62
|
+
S: this,
|
|
63
|
+
A: [
|
|
64
|
+
"bufWkt.anyIs(message.payload, type)",
|
|
65
|
+
"`Unexpected payload type: ${payloadTypename}}`"
|
|
66
|
+
]
|
|
67
|
+
});
|
|
68
|
+
const payload = bufWkt.anyUnpack(message.payload, this.typeRegistry);
|
|
69
|
+
invariant(payload, `Empty payload: ${payloadTypename}}`, {
|
|
70
|
+
F: __dxlog_file,
|
|
71
|
+
L: 48,
|
|
72
|
+
S: this,
|
|
73
|
+
A: [
|
|
74
|
+
"payload",
|
|
75
|
+
"`Empty payload: ${payloadTypename}}`"
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
return payload;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get the payload type.
|
|
82
|
+
*/
|
|
83
|
+
getPayloadType(message) {
|
|
84
|
+
if (!message.payload) {
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
const [, type] = message.payload.typeUrl.split("/");
|
|
88
|
+
return type;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create a packed message.
|
|
92
|
+
*/
|
|
93
|
+
createMessage(type, { source, target, payload, serviceId }) {
|
|
94
|
+
return buf.create(MessageSchema, {
|
|
95
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
96
|
+
source,
|
|
97
|
+
target,
|
|
98
|
+
serviceId,
|
|
99
|
+
payload: payload ? bufWkt.anyPack(type, buf.create(type, payload)) : void 0
|
|
100
|
+
});
|
|
23
101
|
}
|
|
24
102
|
};
|
|
25
|
-
var
|
|
103
|
+
var toUint8Array = async (data) => {
|
|
104
|
+
if (data instanceof Buffer) {
|
|
105
|
+
return bufferToArray(data);
|
|
106
|
+
}
|
|
107
|
+
if (data instanceof Blob) {
|
|
108
|
+
return new Uint8Array(await data.arrayBuffer());
|
|
109
|
+
}
|
|
110
|
+
throw new Error(`Unexpected datatype: ${data}`);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// packages/core/mesh/edge-client/src/defs.ts
|
|
114
|
+
var protocol = new Protocol([
|
|
115
|
+
SwarmRequestSchema,
|
|
116
|
+
SwarmResponseSchema,
|
|
117
|
+
TextMessageSchema,
|
|
118
|
+
AnySchema
|
|
119
|
+
]);
|
|
120
|
+
|
|
121
|
+
// packages/core/mesh/edge-client/src/errors.ts
|
|
122
|
+
var WebsocketClosedError = class extends Error {
|
|
26
123
|
constructor() {
|
|
27
|
-
super("
|
|
124
|
+
super("WebSocket connection closed");
|
|
28
125
|
}
|
|
29
126
|
};
|
|
30
127
|
|
|
@@ -39,7 +136,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
39
136
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
40
137
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
41
138
|
}
|
|
42
|
-
var
|
|
139
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/persistent-lifecycle.ts";
|
|
43
140
|
var INIT_RESTART_DELAY = 100;
|
|
44
141
|
var DEFAULT_MAX_RESTART_DELAY = 5e3;
|
|
45
142
|
var PersistentLifecycle = class extends Resource {
|
|
@@ -60,7 +157,7 @@ var PersistentLifecycle = class extends Resource {
|
|
|
60
157
|
log.warn("Restart failed", {
|
|
61
158
|
err
|
|
62
159
|
}, {
|
|
63
|
-
F:
|
|
160
|
+
F: __dxlog_file2,
|
|
64
161
|
L: 64,
|
|
65
162
|
S: this,
|
|
66
163
|
C: (f, a) => f(...a)
|
|
@@ -72,7 +169,7 @@ var PersistentLifecycle = class extends Resource {
|
|
|
72
169
|
log.warn("Start failed", {
|
|
73
170
|
err
|
|
74
171
|
}, {
|
|
75
|
-
F:
|
|
172
|
+
F: __dxlog_file2,
|
|
76
173
|
L: 69,
|
|
77
174
|
S: this,
|
|
78
175
|
C: (f, a) => f(...a)
|
|
@@ -89,7 +186,7 @@ var PersistentLifecycle = class extends Resource {
|
|
|
89
186
|
log(`restarting in ${this._restartAfter}ms`, {
|
|
90
187
|
state: this._lifecycleState
|
|
91
188
|
}, {
|
|
92
|
-
F:
|
|
189
|
+
F: __dxlog_file2,
|
|
93
190
|
L: 81,
|
|
94
191
|
S: this,
|
|
95
192
|
C: (f, a) => f(...a)
|
|
@@ -122,7 +219,7 @@ _ts_decorate([
|
|
|
122
219
|
], PersistentLifecycle.prototype, "scheduleRestart", null);
|
|
123
220
|
|
|
124
221
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
125
|
-
var
|
|
222
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
126
223
|
var DEFAULT_TIMEOUT = 1e4;
|
|
127
224
|
var SIGNAL_KEEPALIVE_INTERVAL = 5e3;
|
|
128
225
|
var EdgeClient = class extends Resource2 {
|
|
@@ -132,7 +229,6 @@ var EdgeClient = class extends Resource2 {
|
|
|
132
229
|
this._peerKey = _peerKey;
|
|
133
230
|
this._config = _config;
|
|
134
231
|
this.reconnect = new Event();
|
|
135
|
-
this.connected = new Event();
|
|
136
232
|
this._persistentLifecycle = new PersistentLifecycle({
|
|
137
233
|
start: async () => this._openWebSocket(),
|
|
138
234
|
stop: async () => this._closeWebSocket(),
|
|
@@ -143,6 +239,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
143
239
|
this._ws = void 0;
|
|
144
240
|
this._keepaliveCtx = void 0;
|
|
145
241
|
this._heartBeatContext = void 0;
|
|
242
|
+
this._protocol = this._config.protocol ?? protocol;
|
|
146
243
|
}
|
|
147
244
|
// TODO(burdon): Attach logging.
|
|
148
245
|
get info() {
|
|
@@ -174,8 +271,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
174
271
|
log2("opening...", {
|
|
175
272
|
info: this.info
|
|
176
273
|
}, {
|
|
177
|
-
F:
|
|
178
|
-
L:
|
|
274
|
+
F: __dxlog_file3,
|
|
275
|
+
L: 101,
|
|
179
276
|
S: this,
|
|
180
277
|
C: (f, a) => f(...a)
|
|
181
278
|
});
|
|
@@ -183,8 +280,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
183
280
|
log2.warn("Error while opening connection", {
|
|
184
281
|
err
|
|
185
282
|
}, {
|
|
186
|
-
F:
|
|
187
|
-
L:
|
|
283
|
+
F: __dxlog_file3,
|
|
284
|
+
L: 103,
|
|
188
285
|
S: this,
|
|
189
286
|
C: (f, a) => f(...a)
|
|
190
287
|
});
|
|
@@ -197,8 +294,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
197
294
|
log2("closing...", {
|
|
198
295
|
peerKey: this._peerKey
|
|
199
296
|
}, {
|
|
200
|
-
F:
|
|
201
|
-
L:
|
|
297
|
+
F: __dxlog_file3,
|
|
298
|
+
L: 111,
|
|
202
299
|
S: this,
|
|
203
300
|
C: (f, a) => f(...a)
|
|
204
301
|
});
|
|
@@ -209,17 +306,16 @@ var EdgeClient = class extends Resource2 {
|
|
|
209
306
|
this._ws = new WebSocket(url);
|
|
210
307
|
this._ws.onopen = () => {
|
|
211
308
|
log2("opened", this.info, {
|
|
212
|
-
F:
|
|
213
|
-
L:
|
|
309
|
+
F: __dxlog_file3,
|
|
310
|
+
L: 120,
|
|
214
311
|
S: this,
|
|
215
312
|
C: (f, a) => f(...a)
|
|
216
313
|
});
|
|
217
314
|
this._ready.wake();
|
|
218
|
-
this.connected.emit();
|
|
219
315
|
};
|
|
220
316
|
this._ws.onclose = () => {
|
|
221
317
|
log2("closed", this.info, {
|
|
222
|
-
F:
|
|
318
|
+
F: __dxlog_file3,
|
|
223
319
|
L: 124,
|
|
224
320
|
S: this,
|
|
225
321
|
C: (f, a) => f(...a)
|
|
@@ -231,7 +327,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
231
327
|
error: event.error,
|
|
232
328
|
info: event.message
|
|
233
329
|
}, {
|
|
234
|
-
F:
|
|
330
|
+
F: __dxlog_file3,
|
|
235
331
|
L: 128,
|
|
236
332
|
S: this,
|
|
237
333
|
C: (f, a) => f(...a)
|
|
@@ -244,12 +340,12 @@ var EdgeClient = class extends Resource2 {
|
|
|
244
340
|
return;
|
|
245
341
|
}
|
|
246
342
|
const data = await toUint8Array(event.data);
|
|
247
|
-
const message =
|
|
343
|
+
const message = buf2.fromBinary(MessageSchema2, data);
|
|
248
344
|
log2("received", {
|
|
249
345
|
peerKey: this._peerKey,
|
|
250
346
|
payload: protocol.getPayloadType(message)
|
|
251
347
|
}, {
|
|
252
|
-
F:
|
|
348
|
+
F: __dxlog_file3,
|
|
253
349
|
L: 141,
|
|
254
350
|
S: this,
|
|
255
351
|
C: (f, a) => f(...a)
|
|
@@ -263,7 +359,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
263
359
|
err,
|
|
264
360
|
payload: protocol.getPayloadType(message)
|
|
265
361
|
}, {
|
|
266
|
-
F:
|
|
362
|
+
F: __dxlog_file3,
|
|
267
363
|
L: 147,
|
|
268
364
|
S: this,
|
|
269
365
|
C: (f, a) => f(...a)
|
|
@@ -276,7 +372,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
276
372
|
timeout: this._config.timeout ?? DEFAULT_TIMEOUT
|
|
277
373
|
});
|
|
278
374
|
this._keepaliveCtx = new Context(void 0, {
|
|
279
|
-
F:
|
|
375
|
+
F: __dxlog_file3,
|
|
280
376
|
L: 154
|
|
281
377
|
});
|
|
282
378
|
scheduleTaskInterval(this._keepaliveCtx, async () => {
|
|
@@ -290,7 +386,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
290
386
|
return;
|
|
291
387
|
}
|
|
292
388
|
try {
|
|
293
|
-
this._ready.throw(
|
|
389
|
+
this._ready.throw(new WebsocketClosedError());
|
|
294
390
|
this._ready.reset();
|
|
295
391
|
void this._keepaliveCtx?.dispose();
|
|
296
392
|
this._keepaliveCtx = void 0;
|
|
@@ -311,7 +407,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
311
407
|
log2.warn("Error closing websocket", {
|
|
312
408
|
err
|
|
313
409
|
}, {
|
|
314
|
-
F:
|
|
410
|
+
F: __dxlog_file3,
|
|
315
411
|
L: 190,
|
|
316
412
|
S: this,
|
|
317
413
|
C: (f, a) => f(...a)
|
|
@@ -324,32 +420,38 @@ var EdgeClient = class extends Resource2 {
|
|
|
324
420
|
*/
|
|
325
421
|
async send(message) {
|
|
326
422
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
327
|
-
log2("waiting for websocket to become ready", void 0, {
|
|
328
|
-
F: __dxlog_file2,
|
|
329
|
-
L: 200,
|
|
330
|
-
S: this,
|
|
331
|
-
C: (f, a) => f(...a)
|
|
332
|
-
});
|
|
333
423
|
await this._ready.wait({
|
|
334
424
|
timeout: this._config.timeout ?? DEFAULT_TIMEOUT
|
|
335
425
|
});
|
|
336
426
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
427
|
+
invariant2(this._ws, void 0, {
|
|
428
|
+
F: __dxlog_file3,
|
|
429
|
+
L: 202,
|
|
430
|
+
S: this,
|
|
431
|
+
A: [
|
|
432
|
+
"this._ws",
|
|
433
|
+
""
|
|
434
|
+
]
|
|
435
|
+
});
|
|
436
|
+
invariant2(!message.source || message.source.peerKey === this._peerKey, void 0, {
|
|
437
|
+
F: __dxlog_file3,
|
|
438
|
+
L: 203,
|
|
439
|
+
S: this,
|
|
440
|
+
A: [
|
|
441
|
+
"!message.source || message.source.peerKey === this._peerKey",
|
|
442
|
+
""
|
|
443
|
+
]
|
|
444
|
+
});
|
|
343
445
|
log2("sending...", {
|
|
344
446
|
peerKey: this._peerKey,
|
|
345
447
|
payload: protocol.getPayloadType(message)
|
|
346
448
|
}, {
|
|
347
|
-
F:
|
|
348
|
-
L:
|
|
449
|
+
F: __dxlog_file3,
|
|
450
|
+
L: 204,
|
|
349
451
|
S: this,
|
|
350
452
|
C: (f, a) => f(...a)
|
|
351
453
|
});
|
|
352
|
-
this._ws.send(
|
|
454
|
+
this._ws.send(buf2.toBinary(MessageSchema2, message));
|
|
353
455
|
}
|
|
354
456
|
_onHeartbeat() {
|
|
355
457
|
if (this._lifecycleState !== LifecycleState2.OPEN) {
|
|
@@ -357,8 +459,8 @@ var EdgeClient = class extends Resource2 {
|
|
|
357
459
|
}
|
|
358
460
|
void this._heartBeatContext?.dispose();
|
|
359
461
|
this._heartBeatContext = new Context(void 0, {
|
|
360
|
-
F:
|
|
361
|
-
L:
|
|
462
|
+
F: __dxlog_file3,
|
|
463
|
+
L: 213
|
|
362
464
|
});
|
|
363
465
|
scheduleTask(this._heartBeatContext, () => {
|
|
364
466
|
this._persistentLifecycle.scheduleRestart();
|
|
@@ -367,8 +469,6 @@ var EdgeClient = class extends Resource2 {
|
|
|
367
469
|
};
|
|
368
470
|
export {
|
|
369
471
|
EdgeClient,
|
|
370
|
-
EdgeConnectionClosedError,
|
|
371
|
-
EdgeIdentityChangedError,
|
|
372
472
|
Protocol,
|
|
373
473
|
getTypename,
|
|
374
474
|
protocol,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/index.ts", "../../../src/edge-client.ts", "../../../src/errors.ts", "../../../src/persistent-lifecycle.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nexport * from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nexport * from './edge-client';\nexport * from './defs';\nexport * from './protocol';\nexport * from './errors';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport WebSocket from 'isomorphic-ws';\n\nimport { Trigger, Event, scheduleTaskInterval, scheduleTask, TriggerState } from '@dxos/async';\nimport { Context, LifecycleState, Resource, type Lifecycle } from '@dxos/context';\nimport { log } from '@dxos/log';\nimport { buf } from '@dxos/protocols/buf';\nimport { type Message, MessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nimport { protocol } from './defs';\nimport { EdgeConnectionClosedError, EdgeIdentityChangedError } from './errors';\nimport { PersistentLifecycle } from './persistent-lifecycle';\nimport { type Protocol, toUint8Array } from './protocol';\n\nconst DEFAULT_TIMEOUT = 10_000;\nconst SIGNAL_KEEPALIVE_INTERVAL = 5_000;\n\nexport type MessageListener = (message: Message) => void | Promise<void>;\n\nexport interface EdgeConnection extends Required<Lifecycle> {\n connected: Event;\n reconnect: Event;\n\n get info(): any;\n get identityKey(): string;\n get peerKey(): string;\n get isOpen(): boolean;\n setIdentity(params: { peerKey: string; identityKey: string }): void;\n addListener(listener: MessageListener): () => void;\n send(message: Message): Promise<void>;\n}\n\nexport type MessengerConfig = {\n socketEndpoint: string;\n timeout?: number;\n protocol?: Protocol;\n};\n\n/**\n * Messenger client.\n */\nexport class EdgeClient extends Resource implements EdgeConnection {\n public readonly reconnect = new Event();\n public readonly connected = new Event();\n private readonly _persistentLifecycle = new PersistentLifecycle({\n start: async () => this._openWebSocket(),\n stop: async () => this._closeWebSocket(),\n onRestart: async () => this.reconnect.emit(),\n });\n\n private readonly _listeners = new Set<MessageListener>();\n private _ready = new Trigger();\n private _ws?: WebSocket = undefined;\n private _keepaliveCtx?: Context = undefined;\n private _heartBeatContext?: Context = undefined;\n\n constructor(\n private _identityKey: string,\n private _peerKey: string,\n private readonly _config: MessengerConfig,\n ) {\n super();\n }\n\n // TODO(burdon): Attach logging.\n public get info() {\n return {\n open: this.isOpen,\n identity: this._identityKey,\n device: this._peerKey,\n };\n }\n\n get identityKey() {\n return this._identityKey;\n }\n\n get peerKey() {\n return this._peerKey;\n }\n\n setIdentity({ peerKey, identityKey }: { peerKey: string; identityKey: string }) {\n this._peerKey = peerKey;\n this._identityKey = identityKey;\n this._persistentLifecycle.scheduleRestart();\n }\n\n public addListener(listener: MessageListener): () => void {\n this._listeners.add(listener);\n return () => this._listeners.delete(listener);\n }\n\n /**\n * Open connection to messaging service.\n */\n protected override async _open() {\n log('opening...', { info: this.info });\n this._persistentLifecycle.open().catch((err) => {\n log.warn('Error while opening connection', { err });\n });\n }\n\n /**\n * Close connection and free resources.\n */\n protected override async _close() {\n log('closing...', { peerKey: this._peerKey });\n await this._persistentLifecycle.close();\n }\n\n private async _openWebSocket() {\n const url = new URL(`/ws/${this._identityKey}/${this._peerKey}`, this._config.socketEndpoint);\n this._ws = new WebSocket(url);\n\n this._ws.onopen = () => {\n log('opened', this.info);\n this._ready.wake();\n this.connected.emit();\n };\n this._ws.onclose = () => {\n log('closed', this.info);\n this._persistentLifecycle.scheduleRestart();\n };\n this._ws.onerror = (event) => {\n log.warn('EdgeClient socket error', { error: event.error, info: event.message });\n this._persistentLifecycle.scheduleRestart();\n };\n /**\n * https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data\n */\n this._ws.onmessage = async (event) => {\n if (event.data === '__pong__') {\n this._onHeartbeat();\n return;\n }\n const data = await toUint8Array(event.data);\n const message = buf.fromBinary(MessageSchema, data);\n log('received', { peerKey: this._peerKey, payload: protocol.getPayloadType(message) });\n if (message) {\n for (const listener of this._listeners) {\n try {\n await listener(message);\n } catch (err) {\n log.error('processing', { err, payload: protocol.getPayloadType(message) });\n }\n }\n }\n };\n\n await this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT });\n this._keepaliveCtx = new Context();\n scheduleTaskInterval(\n this._keepaliveCtx,\n async () => {\n // TODO(mykola): use RFC6455 ping/pong once implemented in the browser?\n // Cloudflare's worker responds to this `without interrupting hibernation`. https://developers.cloudflare.com/durable-objects/api/websockets/#setwebsocketautoresponse\n this._ws?.send('__ping__');\n },\n SIGNAL_KEEPALIVE_INTERVAL,\n );\n this._ws.send('__ping__');\n this._onHeartbeat();\n }\n\n private async _closeWebSocket() {\n if (!this._ws) {\n return;\n }\n try {\n this._ready.throw(this.isOpen ? new EdgeIdentityChangedError() : new EdgeConnectionClosedError());\n this._ready.reset();\n void this._keepaliveCtx?.dispose();\n this._keepaliveCtx = undefined;\n void this._heartBeatContext?.dispose();\n this._heartBeatContext = undefined;\n\n // NOTE: Remove event handlers to avoid scheduling restart.\n this._ws.onopen = () => {};\n this._ws.onclose = () => {};\n this._ws.onerror = () => {};\n this._ws.close();\n this._ws = undefined;\n } catch (err) {\n if (err instanceof Error && err.message.includes('WebSocket is closed before the connection is established.')) {\n return;\n }\n log.warn('Error closing websocket', { err });\n }\n }\n\n /**\n * Send message.\n * NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.\n */\n public async send(message: Message): Promise<void> {\n if (this._ready.state !== TriggerState.RESOLVED) {\n log('waiting for websocket to become ready');\n await this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT });\n }\n if (!this._ws) {\n throw new EdgeConnectionClosedError();\n }\n if (\n message.source &&\n (message.source.peerKey !== this._peerKey || message.source.identityKey !== this.identityKey)\n ) {\n throw new EdgeIdentityChangedError();\n }\n\n log('sending...', { peerKey: this._peerKey, payload: protocol.getPayloadType(message) });\n this._ws.send(buf.toBinary(MessageSchema, message));\n }\n\n private _onHeartbeat() {\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n void this._heartBeatContext?.dispose();\n this._heartBeatContext = new Context();\n scheduleTask(\n this._heartBeatContext,\n () => {\n this._persistentLifecycle.scheduleRestart();\n },\n 2 * SIGNAL_KEEPALIVE_INTERVAL,\n );\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport class EdgeConnectionClosedError extends Error {\n constructor() {\n super('Edge connection closed.');\n }\n}\n\nexport class EdgeIdentityChangedError extends Error {\n constructor() {\n super('Edge identity changed.');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { DeferredTask, sleep, synchronized } from '@dxos/async';\nimport { cancelWithContext, LifecycleState, Resource } from '@dxos/context';\nimport { warnAfterTimeout } from '@dxos/debug';\nimport { log } from '@dxos/log';\n\nconst INIT_RESTART_DELAY = 100;\nconst DEFAULT_MAX_RESTART_DELAY = 5000;\n\nexport type PersistentLifecycleParams = {\n /**\n * Create connection.\n * If promise resolves successfully, connection is considered established.\n */\n start: () => Promise<void>;\n\n /**\n * Reset connection to initial state.\n */\n stop: () => Promise<void>;\n\n /**\n * Called after successful start.\n */\n onRestart?: () => Promise<void>;\n\n /**\n * Maximum delay between restartion attempts.\n * Default: 5000ms\n */\n maxRestartDelay?: number;\n};\n\n/**\n * Handles restarts (e.g. persists connection).\n * Restarts are scheduled with exponential backoff.\n */\nexport class PersistentLifecycle extends Resource {\n private readonly _start: () => Promise<void>;\n private readonly _stop: () => Promise<void>;\n private readonly _onRestart?: () => Promise<void>;\n private readonly _maxRestartDelay: number;\n\n private _restartTask?: DeferredTask = undefined;\n private _restartAfter = 0;\n\n constructor({ start, stop, onRestart, maxRestartDelay = DEFAULT_MAX_RESTART_DELAY }: PersistentLifecycleParams) {\n super();\n this._start = start;\n this._stop = stop;\n this._onRestart = onRestart;\n this._maxRestartDelay = maxRestartDelay;\n }\n\n @synchronized\n protected override async _open() {\n this._restartTask = new DeferredTask(this._ctx, async () => {\n try {\n await this._restart();\n } catch (err) {\n log.warn('Restart failed', { err });\n this._restartTask?.schedule();\n }\n });\n await this._start().catch((err) => {\n log.warn('Start failed', { err });\n this._restartTask?.schedule();\n });\n }\n\n protected override async _close() {\n await this._restartTask?.join();\n await this._stop();\n this._restartTask = undefined;\n }\n\n private async _restart() {\n log(`restarting in ${this._restartAfter}ms`, { state: this._lifecycleState });\n await this._stop();\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n await cancelWithContext(this._ctx!, sleep(this._restartAfter));\n this._restartAfter = Math.min(Math.max(this._restartAfter * 2, INIT_RESTART_DELAY), this._maxRestartDelay);\n\n // May fail if the connection is not established.\n await warnAfterTimeout(5_000, 'Connection establishment takes too long', () => this._start());\n\n this._restartAfter = 0;\n await this._onRestart?.();\n }\n\n /**\n * Scheduling restart should be done from outside.\n */\n @synchronized\n scheduleRestart() {\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n this._restartTask!.schedule();\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["WebSocket", "Trigger", "Event", "scheduleTaskInterval", "scheduleTask", "TriggerState", "Context", "LifecycleState", "Resource", "log", "buf", "MessageSchema", "
|
|
3
|
+
"sources": ["../../../src/index.ts", "../../../src/edge-client.ts", "../../../src/defs.ts", "../../../src/protocol.ts", "../../../src/errors.ts", "../../../src/persistent-lifecycle.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nexport * from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nexport * from './edge-client';\nexport * from './defs';\nexport * from './protocol';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport WebSocket from 'isomorphic-ws';\n\nimport { Trigger, Event, scheduleTaskInterval, scheduleTask, TriggerState } from '@dxos/async';\nimport { Context, LifecycleState, Resource, type Lifecycle } from '@dxos/context';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { buf } from '@dxos/protocols/buf';\nimport { type Message, MessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nimport { protocol } from './defs';\nimport { WebsocketClosedError } from './errors';\nimport { PersistentLifecycle } from './persistent-lifecycle';\nimport { type Protocol, toUint8Array } from './protocol';\n\nconst DEFAULT_TIMEOUT = 10_000;\nconst SIGNAL_KEEPALIVE_INTERVAL = 5_000;\n\nexport type MessageListener = (message: Message) => void | Promise<void>;\n\nexport interface EdgeConnection extends Required<Lifecycle> {\n reconnect: Event;\n\n get info(): any;\n get identityKey(): string;\n get peerKey(): string;\n get isOpen(): boolean;\n setIdentity(params: { peerKey: string; identityKey: string }): void;\n addListener(listener: MessageListener): () => void;\n send(message: Message): Promise<void>;\n}\n\nexport type MessengerConfig = {\n socketEndpoint: string;\n timeout?: number;\n protocol?: Protocol;\n};\n\n/**\n * Messenger client.\n */\nexport class EdgeClient extends Resource implements EdgeConnection {\n public reconnect = new Event();\n private readonly _persistentLifecycle = new PersistentLifecycle({\n start: async () => this._openWebSocket(),\n stop: async () => this._closeWebSocket(),\n onRestart: async () => this.reconnect.emit(),\n });\n\n private readonly _listeners = new Set<MessageListener>();\n private readonly _protocol: Protocol;\n private _ready = new Trigger();\n private _ws?: WebSocket = undefined;\n private _keepaliveCtx?: Context = undefined;\n private _heartBeatContext?: Context = undefined;\n\n constructor(\n private _identityKey: string,\n private _peerKey: string,\n private readonly _config: MessengerConfig,\n ) {\n super();\n this._protocol = this._config.protocol ?? protocol;\n }\n\n // TODO(burdon): Attach logging.\n public get info() {\n return {\n open: this.isOpen,\n identity: this._identityKey,\n device: this._peerKey,\n };\n }\n\n get identityKey() {\n return this._identityKey;\n }\n\n get peerKey() {\n return this._peerKey;\n }\n\n setIdentity({ peerKey, identityKey }: { peerKey: string; identityKey: string }) {\n this._peerKey = peerKey;\n this._identityKey = identityKey;\n this._persistentLifecycle.scheduleRestart();\n }\n\n public addListener(listener: MessageListener): () => void {\n this._listeners.add(listener);\n return () => this._listeners.delete(listener);\n }\n\n /**\n * Open connection to messaging service.\n */\n protected override async _open() {\n log('opening...', { info: this.info });\n this._persistentLifecycle.open().catch((err) => {\n log.warn('Error while opening connection', { err });\n });\n }\n\n /**\n * Close connection and free resources.\n */\n protected override async _close() {\n log('closing...', { peerKey: this._peerKey });\n await this._persistentLifecycle.close();\n }\n\n private async _openWebSocket() {\n const url = new URL(`/ws/${this._identityKey}/${this._peerKey}`, this._config.socketEndpoint);\n this._ws = new WebSocket(url);\n\n this._ws.onopen = () => {\n log('opened', this.info);\n this._ready.wake();\n };\n this._ws.onclose = () => {\n log('closed', this.info);\n this._persistentLifecycle.scheduleRestart();\n };\n this._ws.onerror = (event) => {\n log.warn('EdgeClient socket error', { error: event.error, info: event.message });\n this._persistentLifecycle.scheduleRestart();\n };\n /**\n * https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data\n */\n this._ws.onmessage = async (event) => {\n if (event.data === '__pong__') {\n this._onHeartbeat();\n return;\n }\n const data = await toUint8Array(event.data);\n const message = buf.fromBinary(MessageSchema, data);\n log('received', { peerKey: this._peerKey, payload: protocol.getPayloadType(message) });\n if (message) {\n for (const listener of this._listeners) {\n try {\n await listener(message);\n } catch (err) {\n log.error('processing', { err, payload: protocol.getPayloadType(message) });\n }\n }\n }\n };\n\n await this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT });\n this._keepaliveCtx = new Context();\n scheduleTaskInterval(\n this._keepaliveCtx,\n async () => {\n // TODO(mykola): use RFC6455 ping/pong once implemented in the browser?\n // Cloudflare's worker responds to this `without interrupting hibernation`. https://developers.cloudflare.com/durable-objects/api/websockets/#setwebsocketautoresponse\n this._ws?.send('__ping__');\n },\n SIGNAL_KEEPALIVE_INTERVAL,\n );\n this._ws.send('__ping__');\n this._onHeartbeat();\n }\n\n private async _closeWebSocket() {\n if (!this._ws) {\n return;\n }\n try {\n this._ready.throw(new WebsocketClosedError());\n this._ready.reset();\n void this._keepaliveCtx?.dispose();\n this._keepaliveCtx = undefined;\n void this._heartBeatContext?.dispose();\n this._heartBeatContext = undefined;\n\n // NOTE: Remove event handlers to avoid scheduling restart.\n this._ws.onopen = () => {};\n this._ws.onclose = () => {};\n this._ws.onerror = () => {};\n this._ws.close();\n this._ws = undefined;\n } catch (err) {\n if (err instanceof Error && err.message.includes('WebSocket is closed before the connection is established.')) {\n return;\n }\n log.warn('Error closing websocket', { err });\n }\n }\n\n /**\n * Send message.\n * NOTE: The message is guaranteed to be delivered but the service must respond with a message to confirm processing.\n */\n public async send(message: Message): Promise<void> {\n if (this._ready.state !== TriggerState.RESOLVED) {\n await this._ready.wait({ timeout: this._config.timeout ?? DEFAULT_TIMEOUT });\n }\n invariant(this._ws);\n invariant(!message.source || message.source.peerKey === this._peerKey);\n log('sending...', { peerKey: this._peerKey, payload: protocol.getPayloadType(message) });\n this._ws.send(buf.toBinary(MessageSchema, message));\n }\n\n private _onHeartbeat() {\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n void this._heartBeatContext?.dispose();\n this._heartBeatContext = new Context();\n scheduleTask(\n this._heartBeatContext,\n () => {\n this._persistentLifecycle.scheduleRestart();\n },\n 2 * SIGNAL_KEEPALIVE_INTERVAL,\n );\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { AnySchema } from '@bufbuild/protobuf/wkt';\n\nimport { SwarmRequestSchema, SwarmResponseSchema, TextMessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nimport { Protocol } from './protocol';\n\nexport const protocol = new Protocol([SwarmRequestSchema, SwarmResponseSchema, TextMessageSchema, AnySchema]);\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { buf, bufWkt } from '@dxos/protocols/buf';\nimport { type Message, MessageSchema, type Peer as PeerProto } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\nimport { bufferToArray } from '@dxos/util';\n\nexport type PeerData = Partial<PeerProto>;\n\nexport const getTypename = (typeName: string) => `type.googleapis.com/${typeName}`;\n\n/**\n * NOTE: The type registry should be extended with all message types.\n */\nexport class Protocol {\n private readonly _typeRegistry: buf.Registry;\n\n constructor(types: buf.DescMessage[]) {\n this._typeRegistry = buf.createRegistry(...types);\n }\n\n get typeRegistry(): buf.Registry {\n return this._typeRegistry;\n }\n\n toJson(message: Message): any {\n try {\n return buf.toJson(MessageSchema, message, { registry: this.typeRegistry });\n } catch (err) {\n return { type: this.getPayloadType(message) };\n }\n }\n\n /**\n * Return the payload with the given type.\n */\n getPayload<Desc extends buf.DescMessage>(message: Message, type: Desc): buf.MessageShape<Desc> {\n invariant(message.payload);\n const payloadTypename = this.getPayloadType(message);\n if (type && type.typeName !== payloadTypename) {\n throw new Error(`Unexpected payload type: ${payloadTypename}; expected ${type.typeName}`);\n }\n\n invariant(bufWkt.anyIs(message.payload, type), `Unexpected payload type: ${payloadTypename}}`);\n const payload = bufWkt.anyUnpack(message.payload, this.typeRegistry) as buf.MessageShape<Desc>;\n invariant(payload, `Empty payload: ${payloadTypename}}`);\n return payload;\n }\n\n /**\n * Get the payload type.\n */\n getPayloadType(message: Message): string | undefined {\n if (!message.payload) {\n return undefined;\n }\n\n const [, type] = message.payload.typeUrl.split('/');\n return type;\n }\n\n /**\n * Create a packed message.\n */\n createMessage<Desc extends buf.DescMessage>(\n type: Desc,\n {\n source,\n target,\n payload,\n serviceId,\n }: {\n source?: PeerData;\n target?: PeerData[];\n payload?: buf.MessageInitShape<Desc>;\n serviceId?: string;\n },\n ) {\n return buf.create(MessageSchema, {\n timestamp: new Date().toISOString(),\n source,\n target,\n serviceId,\n payload: payload ? bufWkt.anyPack(type, buf.create(type, payload)) : undefined,\n });\n }\n}\n\n/**\n * Convert websocket data to Uint8Array.\n */\nexport const toUint8Array = async (data: any): Promise<Uint8Array> => {\n // Node.\n if (data instanceof Buffer) {\n return bufferToArray(data);\n }\n\n // Browser.\n if (data instanceof Blob) {\n return new Uint8Array(await (data as Blob).arrayBuffer());\n }\n\n throw new Error(`Unexpected datatype: ${data}`);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport class WebsocketClosedError extends Error {\n constructor() {\n super('WebSocket connection closed');\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { DeferredTask, sleep, synchronized } from '@dxos/async';\nimport { cancelWithContext, LifecycleState, Resource } from '@dxos/context';\nimport { warnAfterTimeout } from '@dxos/debug';\nimport { log } from '@dxos/log';\n\nconst INIT_RESTART_DELAY = 100;\nconst DEFAULT_MAX_RESTART_DELAY = 5000;\n\nexport type PersistentLifecycleParams = {\n /**\n * Create connection.\n * If promise resolves successfully, connection is considered established.\n */\n start: () => Promise<void>;\n\n /**\n * Reset connection to initial state.\n */\n stop: () => Promise<void>;\n\n /**\n * Called after successful start.\n */\n onRestart?: () => Promise<void>;\n\n /**\n * Maximum delay between restartion attempts.\n * Default: 5000ms\n */\n maxRestartDelay?: number;\n};\n\n/**\n * Handles restarts (e.g. persists connection).\n * Restarts are scheduled with exponential backoff.\n */\nexport class PersistentLifecycle extends Resource {\n private readonly _start: () => Promise<void>;\n private readonly _stop: () => Promise<void>;\n private readonly _onRestart?: () => Promise<void>;\n private readonly _maxRestartDelay: number;\n\n private _restartTask?: DeferredTask = undefined;\n private _restartAfter = 0;\n\n constructor({ start, stop, onRestart, maxRestartDelay = DEFAULT_MAX_RESTART_DELAY }: PersistentLifecycleParams) {\n super();\n this._start = start;\n this._stop = stop;\n this._onRestart = onRestart;\n this._maxRestartDelay = maxRestartDelay;\n }\n\n @synchronized\n protected override async _open() {\n this._restartTask = new DeferredTask(this._ctx, async () => {\n try {\n await this._restart();\n } catch (err) {\n log.warn('Restart failed', { err });\n this._restartTask?.schedule();\n }\n });\n await this._start().catch((err) => {\n log.warn('Start failed', { err });\n this._restartTask?.schedule();\n });\n }\n\n protected override async _close() {\n await this._restartTask?.join();\n await this._stop();\n this._restartTask = undefined;\n }\n\n private async _restart() {\n log(`restarting in ${this._restartAfter}ms`, { state: this._lifecycleState });\n await this._stop();\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n await cancelWithContext(this._ctx!, sleep(this._restartAfter));\n this._restartAfter = Math.min(Math.max(this._restartAfter * 2, INIT_RESTART_DELAY), this._maxRestartDelay);\n\n // May fail if the connection is not established.\n await warnAfterTimeout(5_000, 'Connection establishment takes too long', () => this._start());\n\n this._restartAfter = 0;\n await this._onRestart?.();\n }\n\n /**\n * Scheduling restart should be done from outside.\n */\n @synchronized\n scheduleRestart() {\n if (this._lifecycleState !== LifecycleState.OPEN) {\n return;\n }\n this._restartTask!.schedule();\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,cAAc;;;ACAd,OAAOA,eAAe;AAEtB,SAASC,SAASC,OAAOC,sBAAsBC,cAAcC,oBAAoB;AACjF,SAASC,SAASC,kBAAAA,iBAAgBC,YAAAA,iBA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B,gBAAeP,OAAAA,CAAAA;EAC5C;EAEQG,eAAe;AACrB,QAAI,KAAKwB,oBAAoBC,gBAAeC,MAAM;AAChD;IACF;AACA,SAAK,KAAK9D,mBAAmBmD,QAAAA;AAC7B,SAAKnD,oBAAoB,IAAI6C,QAAAA,QAAAA;;;;AAC7BkB,iBACE,KAAK/D,mBACL,MAAA;AACE,WAAKf,qBAAqB0B,gBAAe;IAC3C,GACA,IAAInC,yBAAAA;EAER;AACF;",
|
|
6
|
+
"names": ["WebSocket", "Trigger", "Event", "scheduleTaskInterval", "scheduleTask", "TriggerState", "Context", "LifecycleState", "Resource", "invariant", "log", "buf", "MessageSchema", "AnySchema", "SwarmRequestSchema", "SwarmResponseSchema", "TextMessageSchema", "invariant", "buf", "bufWkt", "MessageSchema", "bufferToArray", "getTypename", "typeName", "Protocol", "constructor", "types", "_typeRegistry", "createRegistry", "typeRegistry", "toJson", "message", "registry", "err", "type", "getPayloadType", "getPayload", "payload", "payloadTypename", "Error", "anyIs", "anyUnpack", "undefined", "typeUrl", "split", "createMessage", "source", "target", "serviceId", "create", "timestamp", "Date", "toISOString", "anyPack", "toUint8Array", "data", "Buffer", "Blob", "Uint8Array", "arrayBuffer", "protocol", "Protocol", "SwarmRequestSchema", "SwarmResponseSchema", "TextMessageSchema", "AnySchema", "WebsocketClosedError", "Error", "constructor", "DeferredTask", "sleep", "synchronized", "cancelWithContext", "LifecycleState", "Resource", "warnAfterTimeout", "log", "INIT_RESTART_DELAY", "DEFAULT_MAX_RESTART_DELAY", "PersistentLifecycle", "constructor", "start", "stop", "onRestart", "maxRestartDelay", "_restartTask", "undefined", "_restartAfter", "_start", "_stop", "_onRestart", "_maxRestartDelay", "_open", "_ctx", "_restart", "err", "warn", "schedule", "catch", "_close", "join", "state", "_lifecycleState", "OPEN", "Math", "min", "max", "scheduleRestart", "DEFAULT_TIMEOUT", "SIGNAL_KEEPALIVE_INTERVAL", "EdgeClient", "Resource", "constructor", "_identityKey", "_peerKey", "_config", "reconnect", "Event", "_persistentLifecycle", "PersistentLifecycle", "start", "_openWebSocket", "stop", "_closeWebSocket", "onRestart", "emit", "_listeners", "Set", "_ready", "Trigger", "_ws", "undefined", "_keepaliveCtx", "_heartBeatContext", "_protocol", "protocol", "info", "open", "isOpen", "identity", "device", "identityKey", "peerKey", "setIdentity", "scheduleRestart", "addListener", "listener", "add", "delete", "_open", "log", "catch", "err", "warn", "_close", "close", "url", "URL", "socketEndpoint", "WebSocket", "onopen", "wake", "onclose", "onerror", "event", "error", "message", "onmessage", "data", "_onHeartbeat", "toUint8Array", "buf", "fromBinary", "MessageSchema", "payload", "getPayloadType", "wait", "timeout", "Context", "scheduleTaskInterval", "send", "throw", "WebsocketClosedError", "reset", "dispose", "Error", "includes", "state", "TriggerState", "RESOLVED", "invariant", "source", "toBinary", "_lifecycleState", "LifecycleState", "OPEN", "scheduleTask"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/core/mesh/edge-client/src/protocol.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/core/mesh/edge-client/src/protocol.ts":{"bytes":10314,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"packages/core/mesh/edge-client/src/defs.ts":{"bytes":1578,"imports":[{"path":"@bufbuild/protobuf/wkt","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"packages/core/mesh/edge-client/src/protocol.ts","kind":"import-statement","original":"./protocol"}],"format":"esm"},"packages/core/mesh/edge-client/src/errors.ts":{"bytes":846,"imports":[],"format":"esm"},"packages/core/mesh/edge-client/src/persistent-lifecycle.ts":{"bytes":10868,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"packages/core/mesh/edge-client/src/edge-client.ts":{"bytes":26527,"imports":[{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"packages/core/mesh/edge-client/src/defs.ts","kind":"import-statement","original":"./defs"},{"path":"packages/core/mesh/edge-client/src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"packages/core/mesh/edge-client/src/persistent-lifecycle.ts","kind":"import-statement","original":"./persistent-lifecycle"},{"path":"packages/core/mesh/edge-client/src/protocol.ts","kind":"import-statement","original":"./protocol"}],"format":"esm"},"packages/core/mesh/edge-client/src/index.ts":{"bytes":849,"imports":[{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"packages/core/mesh/edge-client/src/edge-client.ts","kind":"import-statement","original":"./edge-client"},{"path":"packages/core/mesh/edge-client/src/defs.ts","kind":"import-statement","original":"./defs"},{"path":"packages/core/mesh/edge-client/src/protocol.ts","kind":"import-statement","original":"./protocol"}],"format":"esm"}},"outputs":{"packages/core/mesh/edge-client/dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":23169},"packages/core/mesh/edge-client/dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@bufbuild/protobuf/wkt","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["EdgeClient","Protocol","getTypename","protocol","toUint8Array"],"entryPoint":"packages/core/mesh/edge-client/src/index.ts","inputs":{"packages/core/mesh/edge-client/src/index.ts":{"bytesInOutput":60},"packages/core/mesh/edge-client/src/edge-client.ts":{"bytesInOutput":6962},"packages/core/mesh/edge-client/src/defs.ts":{"bytesInOutput":285},"packages/core/mesh/edge-client/src/protocol.ts":{"bytesInOutput":2600},"packages/core/mesh/edge-client/src/errors.ts":{"bytesInOutput":116},"packages/core/mesh/edge-client/src/persistent-lifecycle.ts":{"bytesInOutput":3019}},"bytes":13569}}}
|