@dxos/edge-client 0.7.5-main.e9bb01b → 0.7.5-staging.2ff1350
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 +162 -206
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +147 -189
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +162 -206
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-http-client.d.ts +6 -1
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/package.json +15 -14
- package/src/edge-client.ts +1 -2
- package/src/edge-http-client.ts +88 -4
- package/src/edge-ws-connection.ts +6 -4
- package/dist/types/src/persistent-lifecycle.d.ts +0 -44
- package/dist/types/src/persistent-lifecycle.d.ts.map +0 -1
- package/dist/types/src/persistent-lifecycle.test.d.ts +0 -2
- package/dist/types/src/persistent-lifecycle.test.d.ts.map +0 -1
- package/src/persistent-lifecycle.test.ts +0 -71
- package/src/persistent-lifecycle.ts +0 -121
|
@@ -10,9 +10,9 @@ import {
|
|
|
10
10
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
11
11
|
|
|
12
12
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
13
|
-
import { Trigger, scheduleMicroTask, TriggerState } from "@dxos/async";
|
|
14
|
-
import { Resource as
|
|
15
|
-
import { log as
|
|
13
|
+
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle } from "@dxos/async";
|
|
14
|
+
import { Resource as Resource2 } from "@dxos/context";
|
|
15
|
+
import { log as log2, logInfo as logInfo2 } from "@dxos/log";
|
|
16
16
|
|
|
17
17
|
// packages/core/mesh/edge-client/src/edge-identity.ts
|
|
18
18
|
import { invariant } from "@dxos/invariant";
|
|
@@ -69,7 +69,8 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
69
69
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
70
70
|
}
|
|
71
71
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
72
|
-
var SIGNAL_KEEPALIVE_INTERVAL =
|
|
72
|
+
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
73
|
+
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
73
74
|
var CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;
|
|
74
75
|
var EdgeWsConnection = class extends Resource {
|
|
75
76
|
constructor(_identity, _connectionInfo, _callbacks) {
|
|
@@ -88,7 +89,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
88
89
|
send(message) {
|
|
89
90
|
invariant2(this._ws, void 0, {
|
|
90
91
|
F: __dxlog_file2,
|
|
91
|
-
L:
|
|
92
|
+
L: 54,
|
|
92
93
|
S: this,
|
|
93
94
|
A: [
|
|
94
95
|
"this._ws",
|
|
@@ -100,7 +101,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
100
101
|
payload: protocol.getPayloadType(message)
|
|
101
102
|
}, {
|
|
102
103
|
F: __dxlog_file2,
|
|
103
|
-
L:
|
|
104
|
+
L: 55,
|
|
104
105
|
S: this,
|
|
105
106
|
C: (f, a) => f(...a)
|
|
106
107
|
});
|
|
@@ -112,7 +113,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
112
113
|
payload: protocol.getPayloadType(message)
|
|
113
114
|
}, {
|
|
114
115
|
F: __dxlog_file2,
|
|
115
|
-
L:
|
|
116
|
+
L: 58,
|
|
116
117
|
S: this,
|
|
117
118
|
C: (f, a) => f(...a)
|
|
118
119
|
});
|
|
@@ -128,7 +129,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
128
129
|
if (this.isOpen) {
|
|
129
130
|
log("connected", void 0, {
|
|
130
131
|
F: __dxlog_file2,
|
|
131
|
-
L:
|
|
132
|
+
L: 76,
|
|
132
133
|
S: this,
|
|
133
134
|
C: (f, a) => f(...a)
|
|
134
135
|
});
|
|
@@ -139,17 +140,20 @@ var EdgeWsConnection = class extends Resource {
|
|
|
139
140
|
currentIdentity: this._identity
|
|
140
141
|
}, {
|
|
141
142
|
F: __dxlog_file2,
|
|
142
|
-
L:
|
|
143
|
+
L: 80,
|
|
143
144
|
S: this,
|
|
144
145
|
C: (f, a) => f(...a)
|
|
145
146
|
});
|
|
146
147
|
}
|
|
147
148
|
};
|
|
148
|
-
this._ws.onclose = () => {
|
|
149
|
+
this._ws.onclose = (event) => {
|
|
149
150
|
if (this.isOpen) {
|
|
150
|
-
log("disconnected while being open",
|
|
151
|
+
log.warn("disconnected while being open", {
|
|
152
|
+
code: event.code,
|
|
153
|
+
reason: event.reason
|
|
154
|
+
}, {
|
|
151
155
|
F: __dxlog_file2,
|
|
152
|
-
L:
|
|
156
|
+
L: 85,
|
|
153
157
|
S: this,
|
|
154
158
|
C: (f, a) => f(...a)
|
|
155
159
|
});
|
|
@@ -163,7 +167,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
163
167
|
info: event.message
|
|
164
168
|
}, {
|
|
165
169
|
F: __dxlog_file2,
|
|
166
|
-
L:
|
|
170
|
+
L: 91,
|
|
167
171
|
S: this,
|
|
168
172
|
C: (f, a) => f(...a)
|
|
169
173
|
});
|
|
@@ -173,7 +177,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
173
177
|
error: event.error
|
|
174
178
|
}, {
|
|
175
179
|
F: __dxlog_file2,
|
|
176
|
-
L:
|
|
180
|
+
L: 94,
|
|
177
181
|
S: this,
|
|
178
182
|
C: (f, a) => f(...a)
|
|
179
183
|
});
|
|
@@ -185,7 +189,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
185
189
|
event: event.type
|
|
186
190
|
}, {
|
|
187
191
|
F: __dxlog_file2,
|
|
188
|
-
L:
|
|
192
|
+
L: 102,
|
|
189
193
|
S: this,
|
|
190
194
|
C: (f, a) => f(...a)
|
|
191
195
|
});
|
|
@@ -203,7 +207,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
203
207
|
payload: protocol.getPayloadType(message)
|
|
204
208
|
}, {
|
|
205
209
|
F: __dxlog_file2,
|
|
206
|
-
L:
|
|
210
|
+
L: 112,
|
|
207
211
|
S: this,
|
|
208
212
|
C: (f, a) => f(...a)
|
|
209
213
|
});
|
|
@@ -225,7 +229,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
225
229
|
err
|
|
226
230
|
}, {
|
|
227
231
|
F: __dxlog_file2,
|
|
228
|
-
L:
|
|
232
|
+
L: 128,
|
|
229
233
|
S: this,
|
|
230
234
|
C: (f, a) => f(...a)
|
|
231
235
|
});
|
|
@@ -234,7 +238,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
234
238
|
_scheduleHeartbeats() {
|
|
235
239
|
invariant2(this._ws, void 0, {
|
|
236
240
|
F: __dxlog_file2,
|
|
237
|
-
L:
|
|
241
|
+
L: 133,
|
|
238
242
|
S: this,
|
|
239
243
|
A: [
|
|
240
244
|
"this._ws",
|
|
@@ -254,13 +258,19 @@ var EdgeWsConnection = class extends Resource {
|
|
|
254
258
|
void this._inactivityTimeoutCtx?.dispose();
|
|
255
259
|
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
256
260
|
F: __dxlog_file2,
|
|
257
|
-
L:
|
|
261
|
+
L: 152
|
|
258
262
|
});
|
|
259
263
|
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
260
264
|
if (this.isOpen) {
|
|
265
|
+
log.warn("restart due to inactivity timeout", void 0, {
|
|
266
|
+
F: __dxlog_file2,
|
|
267
|
+
L: 157,
|
|
268
|
+
S: this,
|
|
269
|
+
C: (f, a) => f(...a)
|
|
270
|
+
});
|
|
261
271
|
this._callbacks.onRestartRequired();
|
|
262
272
|
}
|
|
263
|
-
},
|
|
273
|
+
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
264
274
|
}
|
|
265
275
|
};
|
|
266
276
|
_ts_decorate([
|
|
@@ -279,118 +289,6 @@ var EdgeIdentityChangedError = class extends Error {
|
|
|
279
289
|
}
|
|
280
290
|
};
|
|
281
291
|
|
|
282
|
-
// packages/core/mesh/edge-client/src/persistent-lifecycle.ts
|
|
283
|
-
import { DeferredTask, sleep, synchronized } from "@dxos/async";
|
|
284
|
-
import { cancelWithContext, LifecycleState, Resource as Resource2 } from "@dxos/context";
|
|
285
|
-
import { warnAfterTimeout } from "@dxos/debug";
|
|
286
|
-
import { log as log2 } from "@dxos/log";
|
|
287
|
-
function _ts_decorate2(decorators, target, key, desc) {
|
|
288
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
289
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
290
|
-
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;
|
|
291
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
292
|
-
}
|
|
293
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/persistent-lifecycle.ts";
|
|
294
|
-
var INIT_RESTART_DELAY = 100;
|
|
295
|
-
var DEFAULT_MAX_RESTART_DELAY = 5e3;
|
|
296
|
-
var PersistentLifecycle = class extends Resource2 {
|
|
297
|
-
constructor({ start, stop, onRestart, maxRestartDelay = DEFAULT_MAX_RESTART_DELAY }) {
|
|
298
|
-
super();
|
|
299
|
-
this._currentContext = void 0;
|
|
300
|
-
this._restartTask = void 0;
|
|
301
|
-
this._restartAfter = 0;
|
|
302
|
-
this._start = start;
|
|
303
|
-
this._stop = stop;
|
|
304
|
-
this._onRestart = onRestart;
|
|
305
|
-
this._maxRestartDelay = maxRestartDelay;
|
|
306
|
-
}
|
|
307
|
-
async _open() {
|
|
308
|
-
this._restartTask = new DeferredTask(this._ctx, async () => {
|
|
309
|
-
try {
|
|
310
|
-
await this._restart();
|
|
311
|
-
} catch (err) {
|
|
312
|
-
log2.warn("Restart failed", {
|
|
313
|
-
err
|
|
314
|
-
}, {
|
|
315
|
-
F: __dxlog_file3,
|
|
316
|
-
L: 65,
|
|
317
|
-
S: this,
|
|
318
|
-
C: (f, a) => f(...a)
|
|
319
|
-
});
|
|
320
|
-
this._restartTask?.schedule();
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
this._currentContext = await this._start().catch((err) => {
|
|
324
|
-
log2.warn("Start failed", {
|
|
325
|
-
err
|
|
326
|
-
}, {
|
|
327
|
-
F: __dxlog_file3,
|
|
328
|
-
L: 70,
|
|
329
|
-
S: this,
|
|
330
|
-
C: (f, a) => f(...a)
|
|
331
|
-
});
|
|
332
|
-
this._restartTask?.schedule();
|
|
333
|
-
return void 0;
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
async _close() {
|
|
337
|
-
await this._restartTask?.join();
|
|
338
|
-
await this._stopCurrentContext();
|
|
339
|
-
this._restartTask = void 0;
|
|
340
|
-
}
|
|
341
|
-
async _restart() {
|
|
342
|
-
log2(`restarting in ${this._restartAfter}ms`, {
|
|
343
|
-
state: this._lifecycleState
|
|
344
|
-
}, {
|
|
345
|
-
F: __dxlog_file3,
|
|
346
|
-
L: 83,
|
|
347
|
-
S: this,
|
|
348
|
-
C: (f, a) => f(...a)
|
|
349
|
-
});
|
|
350
|
-
await this._stopCurrentContext();
|
|
351
|
-
if (this._lifecycleState !== LifecycleState.OPEN) {
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
await cancelWithContext(this._ctx, sleep(this._restartAfter));
|
|
355
|
-
this._restartAfter = Math.min(Math.max(this._restartAfter * 2, INIT_RESTART_DELAY), this._maxRestartDelay);
|
|
356
|
-
await warnAfterTimeout(5e3, "Connection establishment takes too long", async () => {
|
|
357
|
-
this._currentContext = await this._start();
|
|
358
|
-
});
|
|
359
|
-
this._restartAfter = 0;
|
|
360
|
-
await this._onRestart?.();
|
|
361
|
-
}
|
|
362
|
-
async _stopCurrentContext() {
|
|
363
|
-
if (this._currentContext) {
|
|
364
|
-
try {
|
|
365
|
-
await this._stop(this._currentContext);
|
|
366
|
-
} catch (err) {
|
|
367
|
-
log2.catch(err, void 0, {
|
|
368
|
-
F: __dxlog_file3,
|
|
369
|
-
L: 105,
|
|
370
|
-
S: this,
|
|
371
|
-
C: (f, a) => f(...a)
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
this._currentContext = void 0;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
/**
|
|
378
|
-
* Scheduling restart should be done from outside.
|
|
379
|
-
*/
|
|
380
|
-
scheduleRestart() {
|
|
381
|
-
if (this._lifecycleState !== LifecycleState.OPEN) {
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
this._restartTask.schedule();
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
_ts_decorate2([
|
|
388
|
-
synchronized
|
|
389
|
-
], PersistentLifecycle.prototype, "_open", null);
|
|
390
|
-
_ts_decorate2([
|
|
391
|
-
synchronized
|
|
392
|
-
], PersistentLifecycle.prototype, "scheduleRestart", null);
|
|
393
|
-
|
|
394
292
|
// packages/core/mesh/edge-client/src/utils.ts
|
|
395
293
|
var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
396
294
|
const isSecure = baseUrl.startsWith("https") || baseUrl.startsWith("wss");
|
|
@@ -400,15 +298,15 @@ var getEdgeUrlWithProtocol = (baseUrl, protocol2) => {
|
|
|
400
298
|
};
|
|
401
299
|
|
|
402
300
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
403
|
-
function
|
|
301
|
+
function _ts_decorate2(decorators, target, key, desc) {
|
|
404
302
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
405
303
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
406
304
|
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;
|
|
407
305
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
408
306
|
}
|
|
409
|
-
var
|
|
307
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
410
308
|
var DEFAULT_TIMEOUT = 1e4;
|
|
411
|
-
var EdgeClient = class extends
|
|
309
|
+
var EdgeClient = class extends Resource2 {
|
|
412
310
|
constructor(_identity, _config) {
|
|
413
311
|
super();
|
|
414
312
|
this._identity = _identity;
|
|
@@ -443,12 +341,12 @@ var EdgeClient = class extends Resource3 {
|
|
|
443
341
|
}
|
|
444
342
|
setIdentity(identity) {
|
|
445
343
|
if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {
|
|
446
|
-
|
|
344
|
+
log2("Edge identity changed", {
|
|
447
345
|
identity,
|
|
448
346
|
oldIdentity: this._identity
|
|
449
347
|
}, {
|
|
450
|
-
F:
|
|
451
|
-
L:
|
|
348
|
+
F: __dxlog_file3,
|
|
349
|
+
L: 94,
|
|
452
350
|
S: this,
|
|
453
351
|
C: (f, a) => f(...a)
|
|
454
352
|
});
|
|
@@ -469,9 +367,9 @@ var EdgeClient = class extends Resource3 {
|
|
|
469
367
|
try {
|
|
470
368
|
listener();
|
|
471
369
|
} catch (error) {
|
|
472
|
-
|
|
473
|
-
F:
|
|
474
|
-
L:
|
|
370
|
+
log2.catch(error, void 0, {
|
|
371
|
+
F: __dxlog_file3,
|
|
372
|
+
L: 116,
|
|
475
373
|
S: this,
|
|
476
374
|
C: (f, a) => f(...a)
|
|
477
375
|
});
|
|
@@ -485,20 +383,20 @@ var EdgeClient = class extends Resource3 {
|
|
|
485
383
|
* Open connection to messaging service.
|
|
486
384
|
*/
|
|
487
385
|
async _open() {
|
|
488
|
-
|
|
386
|
+
log2("opening...", {
|
|
489
387
|
info: this.info
|
|
490
388
|
}, {
|
|
491
|
-
F:
|
|
492
|
-
L:
|
|
389
|
+
F: __dxlog_file3,
|
|
390
|
+
L: 128,
|
|
493
391
|
S: this,
|
|
494
392
|
C: (f, a) => f(...a)
|
|
495
393
|
});
|
|
496
394
|
this._persistentLifecycle.open().catch((err) => {
|
|
497
|
-
|
|
395
|
+
log2.warn("Error while opening connection", {
|
|
498
396
|
err
|
|
499
397
|
}, {
|
|
500
|
-
F:
|
|
501
|
-
L:
|
|
398
|
+
F: __dxlog_file3,
|
|
399
|
+
L: 130,
|
|
502
400
|
S: this,
|
|
503
401
|
C: (f, a) => f(...a)
|
|
504
402
|
});
|
|
@@ -508,11 +406,11 @@ var EdgeClient = class extends Resource3 {
|
|
|
508
406
|
* Close connection and free resources.
|
|
509
407
|
*/
|
|
510
408
|
async _close() {
|
|
511
|
-
|
|
409
|
+
log2("closing...", {
|
|
512
410
|
peerKey: this._identity.peerKey
|
|
513
411
|
}, {
|
|
514
|
-
F:
|
|
515
|
-
L:
|
|
412
|
+
F: __dxlog_file3,
|
|
413
|
+
L: 138,
|
|
516
414
|
S: this,
|
|
517
415
|
C: (f, a) => f(...a)
|
|
518
416
|
});
|
|
@@ -527,9 +425,9 @@ var EdgeClient = class extends Resource3 {
|
|
|
527
425
|
const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
|
|
528
426
|
const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
|
|
529
427
|
if (this._identity !== identity) {
|
|
530
|
-
|
|
531
|
-
F:
|
|
532
|
-
L:
|
|
428
|
+
log2("identity changed during auth header request", void 0, {
|
|
429
|
+
F: __dxlog_file3,
|
|
430
|
+
L: 152,
|
|
533
431
|
S: this,
|
|
534
432
|
C: (f, a) => f(...a)
|
|
535
433
|
});
|
|
@@ -537,12 +435,12 @@ var EdgeClient = class extends Resource3 {
|
|
|
537
435
|
}
|
|
538
436
|
const restartRequired = new Trigger();
|
|
539
437
|
const url = new URL(path, this._baseWsUrl);
|
|
540
|
-
|
|
438
|
+
log2("Opening websocket", {
|
|
541
439
|
url: url.toString(),
|
|
542
440
|
protocolHeader
|
|
543
441
|
}, {
|
|
544
|
-
F:
|
|
545
|
-
L:
|
|
442
|
+
F: __dxlog_file3,
|
|
443
|
+
L: 158,
|
|
546
444
|
S: this,
|
|
547
445
|
C: (f, a) => f(...a)
|
|
548
446
|
});
|
|
@@ -555,9 +453,9 @@ var EdgeClient = class extends Resource3 {
|
|
|
555
453
|
this._ready.wake();
|
|
556
454
|
this._notifyReconnected();
|
|
557
455
|
} else {
|
|
558
|
-
|
|
559
|
-
F:
|
|
560
|
-
L:
|
|
456
|
+
log2.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
457
|
+
F: __dxlog_file3,
|
|
458
|
+
L: 168,
|
|
561
459
|
S: this,
|
|
562
460
|
C: (f, a) => f(...a)
|
|
563
461
|
});
|
|
@@ -568,9 +466,9 @@ var EdgeClient = class extends Resource3 {
|
|
|
568
466
|
this._closeCurrentConnection();
|
|
569
467
|
this._persistentLifecycle.scheduleRestart();
|
|
570
468
|
} else {
|
|
571
|
-
|
|
572
|
-
F:
|
|
573
|
-
L:
|
|
469
|
+
log2.verbose("restart requested by inactive connection", void 0, {
|
|
470
|
+
F: __dxlog_file3,
|
|
471
|
+
L: 176,
|
|
574
472
|
S: this,
|
|
575
473
|
C: (f, a) => f(...a)
|
|
576
474
|
});
|
|
@@ -581,12 +479,12 @@ var EdgeClient = class extends Resource3 {
|
|
|
581
479
|
if (this._isActive(connection)) {
|
|
582
480
|
this._notifyMessageReceived(message);
|
|
583
481
|
} else {
|
|
584
|
-
|
|
482
|
+
log2.verbose("ignored a message on inactive connection", {
|
|
585
483
|
from: message.source,
|
|
586
484
|
type: message.payload?.typeUrl
|
|
587
485
|
}, {
|
|
588
|
-
F:
|
|
589
|
-
L:
|
|
486
|
+
F: __dxlog_file3,
|
|
487
|
+
L: 184,
|
|
590
488
|
S: this,
|
|
591
489
|
C: (f, a) => f(...a)
|
|
592
490
|
});
|
|
@@ -616,11 +514,11 @@ var EdgeClient = class extends Resource3 {
|
|
|
616
514
|
try {
|
|
617
515
|
listener();
|
|
618
516
|
} catch (err) {
|
|
619
|
-
|
|
517
|
+
log2.error("ws reconnect listener failed", {
|
|
620
518
|
err
|
|
621
519
|
}, {
|
|
622
|
-
F:
|
|
623
|
-
L:
|
|
520
|
+
F: __dxlog_file3,
|
|
521
|
+
L: 217,
|
|
624
522
|
S: this,
|
|
625
523
|
C: (f, a) => f(...a)
|
|
626
524
|
});
|
|
@@ -632,12 +530,12 @@ var EdgeClient = class extends Resource3 {
|
|
|
632
530
|
try {
|
|
633
531
|
listener(message);
|
|
634
532
|
} catch (err) {
|
|
635
|
-
|
|
533
|
+
log2.error("ws incoming message processing failed", {
|
|
636
534
|
err,
|
|
637
535
|
payload: protocol.getPayloadType(message)
|
|
638
536
|
}, {
|
|
639
|
-
F:
|
|
640
|
-
L:
|
|
537
|
+
F: __dxlog_file3,
|
|
538
|
+
L: 227,
|
|
641
539
|
S: this,
|
|
642
540
|
C: (f, a) => f(...a)
|
|
643
541
|
});
|
|
@@ -650,9 +548,9 @@ var EdgeClient = class extends Resource3 {
|
|
|
650
548
|
*/
|
|
651
549
|
async send(message) {
|
|
652
550
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
653
|
-
|
|
654
|
-
F:
|
|
655
|
-
L:
|
|
551
|
+
log2("waiting for websocket to become ready", void 0, {
|
|
552
|
+
F: __dxlog_file3,
|
|
553
|
+
L: 238,
|
|
656
554
|
S: this,
|
|
657
555
|
C: (f, a) => f(...a)
|
|
658
556
|
});
|
|
@@ -677,12 +575,12 @@ var EdgeClient = class extends Resource3 {
|
|
|
677
575
|
if (response.status === 401) {
|
|
678
576
|
return encodePresentationWsAuthHeader(await handleAuthChallenge(response, this._identity));
|
|
679
577
|
} else {
|
|
680
|
-
|
|
578
|
+
log2.warn("no auth challenge from edge", {
|
|
681
579
|
status: response.status,
|
|
682
580
|
statusText: response.statusText
|
|
683
581
|
}, {
|
|
684
|
-
F:
|
|
685
|
-
L:
|
|
582
|
+
F: __dxlog_file3,
|
|
583
|
+
L: 263,
|
|
686
584
|
S: this,
|
|
687
585
|
C: (f, a) => f(...a)
|
|
688
586
|
});
|
|
@@ -690,7 +588,7 @@ var EdgeClient = class extends Resource3 {
|
|
|
690
588
|
}
|
|
691
589
|
}
|
|
692
590
|
};
|
|
693
|
-
|
|
591
|
+
_ts_decorate2([
|
|
694
592
|
logInfo2
|
|
695
593
|
], EdgeClient.prototype, "info", null);
|
|
696
594
|
var encodePresentationWsAuthHeader = (encodedPresentation) => {
|
|
@@ -703,7 +601,7 @@ import { createCredential, signPresentation } from "@dxos/credentials";
|
|
|
703
601
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
704
602
|
import { Keyring } from "@dxos/keyring";
|
|
705
603
|
import { PublicKey } from "@dxos/keys";
|
|
706
|
-
var
|
|
604
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
|
|
707
605
|
var createDeviceEdgeIdentity = async (signer, key) => {
|
|
708
606
|
return {
|
|
709
607
|
identityKey: key.toHex(),
|
|
@@ -748,7 +646,7 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
|
|
|
748
646
|
peerKey: peerKey.toHex(),
|
|
749
647
|
presentCredentials: async ({ challenge }) => {
|
|
750
648
|
invariant3(chain, void 0, {
|
|
751
|
-
F:
|
|
649
|
+
F: __dxlog_file4,
|
|
752
650
|
L: 75,
|
|
753
651
|
S: void 0,
|
|
754
652
|
A: [
|
|
@@ -810,26 +708,29 @@ var createStubEdgeIdentity = () => {
|
|
|
810
708
|
};
|
|
811
709
|
|
|
812
710
|
// packages/core/mesh/edge-client/src/edge-http-client.ts
|
|
813
|
-
import { sleep
|
|
711
|
+
import { sleep } from "@dxos/async";
|
|
814
712
|
import { Context as Context2 } from "@dxos/context";
|
|
815
|
-
import { log as
|
|
713
|
+
import { log as log3 } from "@dxos/log";
|
|
816
714
|
import { EdgeCallFailedError, EdgeAuthChallengeError } from "@dxos/protocols";
|
|
817
|
-
var
|
|
715
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-http-client.ts";
|
|
818
716
|
var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
819
717
|
var DEFAULT_RETRY_JITTER = 500;
|
|
820
718
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
821
719
|
var EdgeHttpClient = class {
|
|
822
720
|
constructor(baseUrl) {
|
|
823
721
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
824
|
-
|
|
722
|
+
log3("created", {
|
|
825
723
|
url: this._baseUrl
|
|
826
724
|
}, {
|
|
827
|
-
F:
|
|
828
|
-
L:
|
|
725
|
+
F: __dxlog_file5,
|
|
726
|
+
L: 49,
|
|
829
727
|
S: this,
|
|
830
728
|
C: (f, a) => f(...a)
|
|
831
729
|
});
|
|
832
730
|
}
|
|
731
|
+
get baseUrl() {
|
|
732
|
+
return this._baseUrl;
|
|
733
|
+
}
|
|
833
734
|
setIdentity(identity) {
|
|
834
735
|
if (this._edgeIdentity?.identityKey !== identity.identityKey || this._edgeIdentity?.peerKey !== identity.peerKey) {
|
|
835
736
|
this._edgeIdentity = identity;
|
|
@@ -876,6 +777,13 @@ var EdgeHttpClient = class {
|
|
|
876
777
|
method: "POST"
|
|
877
778
|
});
|
|
878
779
|
}
|
|
780
|
+
async executeWorkflow(spaceId, graphId, input, args) {
|
|
781
|
+
return this._call(`/workflows/${spaceId}/${graphId}`, {
|
|
782
|
+
...args,
|
|
783
|
+
body: input,
|
|
784
|
+
method: "POST"
|
|
785
|
+
});
|
|
786
|
+
}
|
|
879
787
|
async uploadFunction(pathParts, body, args) {
|
|
880
788
|
const path = [
|
|
881
789
|
"functions",
|
|
@@ -890,20 +798,68 @@ var EdgeHttpClient = class {
|
|
|
890
798
|
method: "PUT"
|
|
891
799
|
});
|
|
892
800
|
}
|
|
801
|
+
async queryQueue(subspaceTag, spaceId, query, args) {
|
|
802
|
+
const { queueId } = query;
|
|
803
|
+
const queryParams = new URLSearchParams();
|
|
804
|
+
if (query.after != null) {
|
|
805
|
+
queryParams.set("after", query.after);
|
|
806
|
+
}
|
|
807
|
+
if (query.before != null) {
|
|
808
|
+
queryParams.set("before", query.before);
|
|
809
|
+
}
|
|
810
|
+
if (query.limit != null) {
|
|
811
|
+
queryParams.set("limit", query.limit.toString());
|
|
812
|
+
}
|
|
813
|
+
if (query.reverse != null) {
|
|
814
|
+
queryParams.set("reverse", query.reverse.toString());
|
|
815
|
+
}
|
|
816
|
+
if (query.objectIds != null) {
|
|
817
|
+
queryParams.set("objectIds", query.objectIds.join(","));
|
|
818
|
+
}
|
|
819
|
+
return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query?${queryParams.toString()}`, {
|
|
820
|
+
...args,
|
|
821
|
+
method: "GET"
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
async insertIntoQueue(subspaceTag, spaceId, queueId, objects, args) {
|
|
825
|
+
return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, {
|
|
826
|
+
...args,
|
|
827
|
+
body: {
|
|
828
|
+
objects
|
|
829
|
+
},
|
|
830
|
+
method: "POST"
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
async deleteFromQueue(subspaceTag, spaceId, queueId, objectIds, args) {
|
|
834
|
+
return this._call(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}`, {
|
|
835
|
+
...args,
|
|
836
|
+
query: {
|
|
837
|
+
ids: objectIds.join(",")
|
|
838
|
+
},
|
|
839
|
+
method: "DELETE"
|
|
840
|
+
});
|
|
841
|
+
}
|
|
893
842
|
async _call(path, args) {
|
|
894
843
|
const requestContext = args.context ?? new Context2(void 0, {
|
|
895
|
-
F:
|
|
896
|
-
L:
|
|
844
|
+
F: __dxlog_file5,
|
|
845
|
+
L: 177
|
|
897
846
|
});
|
|
898
847
|
const shouldRetry = createRetryHandler(args);
|
|
899
|
-
|
|
900
|
-
|
|
848
|
+
let url = `${this._baseUrl}${path.startsWith("/") ? path.slice(1) : path}`;
|
|
849
|
+
if (args.query) {
|
|
850
|
+
const queryParams = new URLSearchParams();
|
|
851
|
+
for (const [key, value] of Object.entries(args.query)) {
|
|
852
|
+
queryParams.set(key, value.toString());
|
|
853
|
+
}
|
|
854
|
+
url += `?${queryParams.toString()}`;
|
|
855
|
+
}
|
|
856
|
+
log3("call", {
|
|
901
857
|
method: args.method,
|
|
902
858
|
path,
|
|
903
859
|
request: args.body
|
|
904
860
|
}, {
|
|
905
|
-
F:
|
|
906
|
-
L:
|
|
861
|
+
F: __dxlog_file5,
|
|
862
|
+
L: 189,
|
|
907
863
|
S: this,
|
|
908
864
|
C: (f, a) => f(...a)
|
|
909
865
|
});
|
|
@@ -921,12 +877,12 @@ var EdgeHttpClient = class {
|
|
|
921
877
|
if (body.success) {
|
|
922
878
|
return body.data;
|
|
923
879
|
}
|
|
924
|
-
|
|
880
|
+
log3("unsuccessful edge response", {
|
|
925
881
|
path,
|
|
926
882
|
body
|
|
927
883
|
}, {
|
|
928
|
-
F:
|
|
929
|
-
L:
|
|
884
|
+
F: __dxlog_file5,
|
|
885
|
+
L: 208,
|
|
930
886
|
S: this,
|
|
931
887
|
C: (f, a) => f(...a)
|
|
932
888
|
});
|
|
@@ -946,12 +902,12 @@ var EdgeHttpClient = class {
|
|
|
946
902
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
947
903
|
}
|
|
948
904
|
if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
949
|
-
|
|
905
|
+
log3("retrying edge request", {
|
|
950
906
|
path,
|
|
951
907
|
processingError
|
|
952
908
|
}, {
|
|
953
|
-
F:
|
|
954
|
-
L:
|
|
909
|
+
F: __dxlog_file5,
|
|
910
|
+
L: 227,
|
|
955
911
|
S: this,
|
|
956
912
|
C: (f, a) => f(...a)
|
|
957
913
|
});
|
|
@@ -962,9 +918,9 @@ var EdgeHttpClient = class {
|
|
|
962
918
|
}
|
|
963
919
|
async _handleUnauthorized(response) {
|
|
964
920
|
if (!this._edgeIdentity) {
|
|
965
|
-
|
|
966
|
-
F:
|
|
967
|
-
L:
|
|
921
|
+
log3.warn("edge unauthorized response received before identity was set", void 0, {
|
|
922
|
+
F: __dxlog_file5,
|
|
923
|
+
L: 236,
|
|
968
924
|
S: this,
|
|
969
925
|
C: (f, a) => f(...a)
|
|
970
926
|
});
|
|
@@ -972,9 +928,9 @@ var EdgeHttpClient = class {
|
|
|
972
928
|
}
|
|
973
929
|
const challenge = await handleAuthChallenge(response, this._edgeIdentity);
|
|
974
930
|
this._authHeader = encodeAuthHeader(challenge);
|
|
975
|
-
|
|
976
|
-
F:
|
|
977
|
-
L:
|
|
931
|
+
log3("auth header updated", void 0, {
|
|
932
|
+
F: __dxlog_file5,
|
|
933
|
+
L: 241,
|
|
978
934
|
S: this,
|
|
979
935
|
C: (f, a) => f(...a)
|
|
980
936
|
});
|
|
@@ -994,10 +950,10 @@ var createRetryHandler = (args) => {
|
|
|
994
950
|
return false;
|
|
995
951
|
}
|
|
996
952
|
if (retryAfter) {
|
|
997
|
-
await
|
|
953
|
+
await sleep(retryAfter);
|
|
998
954
|
} else {
|
|
999
955
|
const timeout = baseTimeout + Math.random() * jitter;
|
|
1000
|
-
await
|
|
956
|
+
await sleep(timeout);
|
|
1001
957
|
}
|
|
1002
958
|
return true;
|
|
1003
959
|
};
|