@dxos/edge-client 0.8.2-main.fbd8ed0 → 0.8.2-staging.7ac8446
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/chunk-ZWJXA37R.mjs +113 -0
- package/dist/lib/browser/chunk-ZWJXA37R.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +50 -93
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +20 -32
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/chunk-ANV2HBEH.cjs +136 -0
- package/dist/lib/node/chunk-ANV2HBEH.cjs.map +7 -0
- package/dist/lib/node/index.cjs +62 -105
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +21 -32
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs +115 -0
- package/dist/lib/node-esm/chunk-HNVT57AU.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +50 -93
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +20 -32
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/auth.d.ts.map +1 -1
- package/dist/types/src/edge-client.d.ts +2 -7
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-http-client.d.ts +1 -0
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/edge-identity.d.ts.map +1 -1
- package/dist/types/src/edge-ws-connection.d.ts +0 -1
- package/dist/types/src/edge-ws-connection.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.map +1 -1
- package/dist/types/src/testing/test-utils.d.ts +2 -6
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +14 -19
- package/src/edge-client.test.ts +4 -5
- package/src/edge-client.ts +8 -16
- package/src/edge-http-client.ts +2 -2
- package/src/edge-ws-connection.ts +18 -36
- package/src/index.ts +0 -1
- package/src/testing/test-utils.ts +26 -33
- package/dist/lib/browser/chunk-TKYUZ5ZK.mjs +0 -302
- package/dist/lib/browser/chunk-TKYUZ5ZK.mjs.map +0 -7
- package/dist/lib/browser/edge-ws-muxer.mjs +0 -11
- package/dist/lib/browser/edge-ws-muxer.mjs.map +0 -7
- package/dist/lib/node/chunk-ZOL3YSDR.cjs +0 -322
- package/dist/lib/node/chunk-ZOL3YSDR.cjs.map +0 -7
- package/dist/lib/node/edge-ws-muxer.cjs +0 -33
- package/dist/lib/node/edge-ws-muxer.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-25HGRGNZ.mjs +0 -304
- package/dist/lib/node-esm/chunk-25HGRGNZ.mjs.map +0 -7
- package/dist/lib/node-esm/edge-ws-muxer.mjs +0 -12
- package/dist/lib/node-esm/edge-ws-muxer.mjs.map +0 -7
- package/dist/types/src/edge-ws-muxer.d.ts +0 -35
- package/dist/types/src/edge-ws-muxer.d.ts.map +0 -1
- package/dist/types/src/edge-ws-muxer.test.d.ts +0 -2
- package/dist/types/src/edge-ws-muxer.test.d.ts.map +0 -1
- package/src/edge-ws-muxer.test.ts +0 -55
- package/src/edge-ws-muxer.ts +0 -217
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// packages/core/mesh/edge-client/src/protocol.ts
|
|
2
|
+
import { invariant } from "@dxos/invariant";
|
|
3
|
+
import { buf, bufWkt } from "@dxos/protocols/buf";
|
|
4
|
+
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
5
|
+
import { bufferToArray } from "@dxos/util";
|
|
6
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/protocol.ts";
|
|
7
|
+
var getTypename = (typeName) => `type.googleapis.com/${typeName}`;
|
|
8
|
+
var Protocol = class {
|
|
9
|
+
constructor(types) {
|
|
10
|
+
this._typeRegistry = buf.createRegistry(...types);
|
|
11
|
+
}
|
|
12
|
+
get typeRegistry() {
|
|
13
|
+
return this._typeRegistry;
|
|
14
|
+
}
|
|
15
|
+
toJson(message) {
|
|
16
|
+
try {
|
|
17
|
+
return buf.toJson(MessageSchema, message, {
|
|
18
|
+
registry: this.typeRegistry
|
|
19
|
+
});
|
|
20
|
+
} catch (err) {
|
|
21
|
+
return {
|
|
22
|
+
type: this.getPayloadType(message)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Return the payload with the given type.
|
|
28
|
+
*/
|
|
29
|
+
getPayload(message, type) {
|
|
30
|
+
invariant(message.payload, void 0, {
|
|
31
|
+
F: __dxlog_file,
|
|
32
|
+
L: 40,
|
|
33
|
+
S: this,
|
|
34
|
+
A: [
|
|
35
|
+
"message.payload",
|
|
36
|
+
""
|
|
37
|
+
]
|
|
38
|
+
});
|
|
39
|
+
const payloadTypename = this.getPayloadType(message);
|
|
40
|
+
if (type && type.typeName !== payloadTypename) {
|
|
41
|
+
throw new Error(`Unexpected payload type: ${payloadTypename}; expected ${type.typeName}`);
|
|
42
|
+
}
|
|
43
|
+
invariant(bufWkt.anyIs(message.payload, type), `Unexpected payload type: ${payloadTypename}}`, {
|
|
44
|
+
F: __dxlog_file,
|
|
45
|
+
L: 46,
|
|
46
|
+
S: this,
|
|
47
|
+
A: [
|
|
48
|
+
"bufWkt.anyIs(message.payload, type)",
|
|
49
|
+
"`Unexpected payload type: ${payloadTypename}}`"
|
|
50
|
+
]
|
|
51
|
+
});
|
|
52
|
+
const payload = bufWkt.anyUnpack(message.payload, this.typeRegistry);
|
|
53
|
+
invariant(payload, `Empty payload: ${payloadTypename}}`, {
|
|
54
|
+
F: __dxlog_file,
|
|
55
|
+
L: 48,
|
|
56
|
+
S: this,
|
|
57
|
+
A: [
|
|
58
|
+
"payload",
|
|
59
|
+
"`Empty payload: ${payloadTypename}}`"
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
return payload;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the payload type.
|
|
66
|
+
*/
|
|
67
|
+
getPayloadType(message) {
|
|
68
|
+
if (!message.payload) {
|
|
69
|
+
return void 0;
|
|
70
|
+
}
|
|
71
|
+
const [, type] = message.payload.typeUrl.split("/");
|
|
72
|
+
return type;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create a packed message.
|
|
76
|
+
*/
|
|
77
|
+
createMessage(type, { source, target, payload, serviceId }) {
|
|
78
|
+
return buf.create(MessageSchema, {
|
|
79
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
80
|
+
source,
|
|
81
|
+
target,
|
|
82
|
+
serviceId,
|
|
83
|
+
payload: payload ? bufWkt.anyPack(type, buf.create(type, payload)) : void 0
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
var toUint8Array = async (data) => {
|
|
88
|
+
if (data instanceof Buffer) {
|
|
89
|
+
return bufferToArray(data);
|
|
90
|
+
}
|
|
91
|
+
if (data instanceof Blob) {
|
|
92
|
+
return new Uint8Array(await data.arrayBuffer());
|
|
93
|
+
}
|
|
94
|
+
throw new Error(`Unexpected datatype: ${data}`);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// packages/core/mesh/edge-client/src/defs.ts
|
|
98
|
+
import { bufWkt as bufWkt2 } from "@dxos/protocols/buf";
|
|
99
|
+
import { SwarmRequestSchema, SwarmResponseSchema, TextMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
100
|
+
var protocol = new Protocol([
|
|
101
|
+
SwarmRequestSchema,
|
|
102
|
+
SwarmResponseSchema,
|
|
103
|
+
TextMessageSchema,
|
|
104
|
+
bufWkt2.AnySchema
|
|
105
|
+
]);
|
|
106
|
+
|
|
107
|
+
export {
|
|
108
|
+
getTypename,
|
|
109
|
+
Protocol,
|
|
110
|
+
toUint8Array,
|
|
111
|
+
protocol
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=chunk-ZWJXA37R.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/protocol.ts", "../../../src/defs.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { invariant } from '@dxos/invariant';\nimport { buf, bufWkt } from '@dxos/protocols/buf';\nimport { type Message, MessageSchema, type PeerSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\nimport { bufferToArray } from '@dxos/util';\n\nexport type PeerData = buf.MessageInitShape<typeof PeerSchema>;\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\nimport { bufWkt } from '@dxos/protocols/buf';\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, bufWkt.AnySchema]);\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,iBAAiB;AAC1B,SAASC,KAAKC,cAAc;AAC5B,SAAuBC,qBAAsC;AAC7D,SAASC,qBAAqB;;AAIvB,IAAMC,cAAc,CAACC,aAAqB,uBAAuBA,QAAAA;AAKjE,IAAMC,WAAN,MAAMA;EAGXC,YAAYC,OAA0B;AACpC,SAAKC,gBAAgBT,IAAIU,eAAc,GAAIF,KAAAA;EAC7C;EAEA,IAAIG,eAA6B;AAC/B,WAAO,KAAKF;EACd;EAEAG,OAAOC,SAAuB;AAC5B,QAAI;AACF,aAAOb,IAAIY,OAAOV,eAAeW,SAAS;QAAEC,UAAU,KAAKH;MAAa,CAAA;IAC1E,SAASI,KAAK;AACZ,aAAO;QAAEC,MAAM,KAAKC,eAAeJ,OAAAA;MAAS;IAC9C;EACF;;;;EAKAK,WAAyCL,SAAkBG,MAAoC;AAC7FjB,cAAUc,QAAQM,SAAO,QAAA;;;;;;;;;AACzB,UAAMC,kBAAkB,KAAKH,eAAeJ,OAAAA;AAC5C,QAAIG,QAAQA,KAAKX,aAAae,iBAAiB;AAC7C,YAAM,IAAIC,MAAM,4BAA4BD,eAAAA,cAA6BJ,KAAKX,QAAQ,EAAE;IAC1F;AAEAN,cAAUE,OAAOqB,MAAMT,QAAQM,SAASH,IAAAA,GAAO,4BAA4BI,eAAAA,KAAkB;;;;;;;;;AAC7F,UAAMD,UAAUlB,OAAOsB,UAAUV,QAAQM,SAAS,KAAKR,YAAY;AACnEZ,cAAUoB,SAAS,kBAAkBC,eAAAA,KAAkB;;;;;;;;;AACvD,WAAOD;EACT;;;;EAKAF,eAAeJ,SAAsC;AACnD,QAAI,CAACA,QAAQM,SAAS;AACpB,aAAOK;IACT;AAEA,UAAM,CAAA,EAAGR,IAAAA,IAAQH,QAAQM,QAAQM,QAAQC,MAAM,GAAA;AAC/C,WAAOV;EACT;;;;EAKAW,cACEX,MACA,EACEY,QACAC,QACAV,SACAW,UAAS,GAOX;AACA,WAAO9B,IAAI+B,OAAO7B,eAAe;MAC/B8B,YAAW,oBAAIC,KAAAA,GAAOC,YAAW;MACjCN;MACAC;MACAC;MACAX,SAASA,UAAUlB,OAAOkC,QAAQnB,MAAMhB,IAAI+B,OAAOf,MAAMG,OAAAA,CAAAA,IAAYK;IACvE,CAAA;EACF;AACF;AAKO,IAAMY,eAAe,OAAOC,SAAAA;AAEjC,MAAIA,gBAAgBC,QAAQ;AAC1B,WAAOnC,cAAckC,IAAAA;EACvB;AAGA,MAAIA,gBAAgBE,MAAM;AACxB,WAAO,IAAIC,WAAW,MAAOH,KAAcI,YAAW,CAAA;EACxD;AAEA,QAAM,IAAIpB,MAAM,wBAAwBgB,IAAAA,EAAM;AAChD;;;ACrGA,SAASK,UAAAA,eAAc;AACvB,SAASC,oBAAoBC,qBAAqBC,yBAAyB;AAIpE,IAAMC,WAAW,IAAIC,SAAS;EAACC;EAAoBC;EAAqBC;EAAmBC,QAAOC;CAAU;",
|
|
6
|
+
"names": ["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", "bufWkt", "SwarmRequestSchema", "SwarmResponseSchema", "TextMessageSchema", "protocol", "Protocol", "SwarmRequestSchema", "SwarmResponseSchema", "TextMessageSchema", "bufWkt", "AnySchema"]
|
|
7
|
+
}
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
3
|
-
CLOUDFLARE_RPC_MAX_BYTES,
|
|
4
2
|
Protocol,
|
|
5
|
-
WebSocketMuxer,
|
|
6
3
|
getTypename,
|
|
7
4
|
protocol,
|
|
8
5
|
toUint8Array
|
|
9
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZWJXA37R.mjs";
|
|
10
7
|
|
|
11
8
|
// packages/core/mesh/edge-client/src/index.ts
|
|
12
9
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
13
10
|
|
|
14
11
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
15
|
-
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle
|
|
12
|
+
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle } from "@dxos/async";
|
|
16
13
|
import { Resource as Resource2 } from "@dxos/context";
|
|
17
14
|
import { log as log2, logInfo as logInfo2 } from "@dxos/log";
|
|
18
|
-
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
19
15
|
|
|
20
16
|
// packages/core/mesh/edge-client/src/edge-identity.ts
|
|
21
17
|
import { invariant } from "@dxos/invariant";
|
|
@@ -63,7 +59,6 @@ import { scheduleTask, scheduleTaskInterval } from "@dxos/async";
|
|
|
63
59
|
import { Context, Resource } from "@dxos/context";
|
|
64
60
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
65
61
|
import { log, logInfo } from "@dxos/log";
|
|
66
|
-
import { EdgeWebsocketProtocol } from "@dxos/protocols";
|
|
67
62
|
import { buf } from "@dxos/protocols/buf";
|
|
68
63
|
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
69
64
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -75,6 +70,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
75
70
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
76
71
|
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
77
72
|
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
73
|
+
var CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;
|
|
78
74
|
var EdgeWsConnection = class extends Resource {
|
|
79
75
|
constructor(_identity, _connectionInfo, _callbacks) {
|
|
80
76
|
super();
|
|
@@ -92,73 +88,47 @@ var EdgeWsConnection = class extends Resource {
|
|
|
92
88
|
send(message) {
|
|
93
89
|
invariant2(this._ws, void 0, {
|
|
94
90
|
F: __dxlog_file2,
|
|
95
|
-
L:
|
|
91
|
+
L: 54,
|
|
96
92
|
S: this,
|
|
97
93
|
A: [
|
|
98
94
|
"this._ws",
|
|
99
95
|
""
|
|
100
96
|
]
|
|
101
97
|
});
|
|
102
|
-
invariant2(this._wsMuxer, void 0, {
|
|
103
|
-
F: __dxlog_file2,
|
|
104
|
-
L: 53,
|
|
105
|
-
S: this,
|
|
106
|
-
A: [
|
|
107
|
-
"this._wsMuxer",
|
|
108
|
-
""
|
|
109
|
-
]
|
|
110
|
-
});
|
|
111
98
|
log("sending...", {
|
|
112
99
|
peerKey: this._identity.peerKey,
|
|
113
100
|
payload: protocol.getPayloadType(message)
|
|
114
101
|
}, {
|
|
115
102
|
F: __dxlog_file2,
|
|
116
|
-
L:
|
|
103
|
+
L: 55,
|
|
117
104
|
S: this,
|
|
118
105
|
C: (f, a) => f(...a)
|
|
119
106
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}, {
|
|
128
|
-
F: __dxlog_file2,
|
|
129
|
-
L: 58,
|
|
130
|
-
S: this,
|
|
131
|
-
C: (f, a) => f(...a)
|
|
132
|
-
});
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
this._ws.send(binary);
|
|
136
|
-
} else {
|
|
137
|
-
this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
|
|
107
|
+
const encoded = buf.toBinary(MessageSchema, message);
|
|
108
|
+
if (encoded.byteLength >= CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {
|
|
109
|
+
log.error("edge message dropped due to websocket message limit", {
|
|
110
|
+
byteLength: encoded.byteLength,
|
|
111
|
+
serviceId: message.serviceId,
|
|
112
|
+
payload: protocol.getPayloadType(message)
|
|
113
|
+
}, {
|
|
138
114
|
F: __dxlog_file2,
|
|
139
|
-
L:
|
|
115
|
+
L: 58,
|
|
140
116
|
S: this,
|
|
141
117
|
C: (f, a) => f(...a)
|
|
142
|
-
})
|
|
118
|
+
});
|
|
119
|
+
return;
|
|
143
120
|
}
|
|
121
|
+
this._ws.send(encoded);
|
|
144
122
|
}
|
|
145
123
|
async _open() {
|
|
146
|
-
const baseProtocols = [
|
|
147
|
-
...Object.values(EdgeWebsocketProtocol)
|
|
148
|
-
];
|
|
149
124
|
this._ws = new WebSocket(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [
|
|
150
|
-
...baseProtocols,
|
|
151
125
|
this._connectionInfo.protocolHeader
|
|
152
|
-
] : [
|
|
153
|
-
...baseProtocols
|
|
154
|
-
]);
|
|
155
|
-
const muxer = new WebSocketMuxer(this._ws);
|
|
156
|
-
this._wsMuxer = muxer;
|
|
126
|
+
] : []);
|
|
157
127
|
this._ws.onopen = () => {
|
|
158
128
|
if (this.isOpen) {
|
|
159
129
|
log("connected", void 0, {
|
|
160
130
|
F: __dxlog_file2,
|
|
161
|
-
L:
|
|
131
|
+
L: 76,
|
|
162
132
|
S: this,
|
|
163
133
|
C: (f, a) => f(...a)
|
|
164
134
|
});
|
|
@@ -169,7 +139,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
169
139
|
currentIdentity: this._identity
|
|
170
140
|
}, {
|
|
171
141
|
F: __dxlog_file2,
|
|
172
|
-
L:
|
|
142
|
+
L: 80,
|
|
173
143
|
S: this,
|
|
174
144
|
C: (f, a) => f(...a)
|
|
175
145
|
});
|
|
@@ -182,12 +152,11 @@ var EdgeWsConnection = class extends Resource {
|
|
|
182
152
|
reason: event.reason
|
|
183
153
|
}, {
|
|
184
154
|
F: __dxlog_file2,
|
|
185
|
-
L:
|
|
155
|
+
L: 85,
|
|
186
156
|
S: this,
|
|
187
157
|
C: (f, a) => f(...a)
|
|
188
158
|
});
|
|
189
159
|
this._callbacks.onRestartRequired();
|
|
190
|
-
muxer.destroy();
|
|
191
160
|
}
|
|
192
161
|
};
|
|
193
162
|
this._ws.onerror = (event) => {
|
|
@@ -197,7 +166,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
197
166
|
info: event.message
|
|
198
167
|
}, {
|
|
199
168
|
F: __dxlog_file2,
|
|
200
|
-
L:
|
|
169
|
+
L: 91,
|
|
201
170
|
S: this,
|
|
202
171
|
C: (f, a) => f(...a)
|
|
203
172
|
});
|
|
@@ -207,7 +176,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
207
176
|
error: event.error
|
|
208
177
|
}, {
|
|
209
178
|
F: __dxlog_file2,
|
|
210
|
-
L:
|
|
179
|
+
L: 94,
|
|
211
180
|
S: this,
|
|
212
181
|
C: (f, a) => f(...a)
|
|
213
182
|
});
|
|
@@ -219,7 +188,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
219
188
|
event: event.type
|
|
220
189
|
}, {
|
|
221
190
|
F: __dxlog_file2,
|
|
222
|
-
L:
|
|
191
|
+
L: 102,
|
|
223
192
|
S: this,
|
|
224
193
|
C: (f, a) => f(...a)
|
|
225
194
|
});
|
|
@@ -229,18 +198,15 @@ var EdgeWsConnection = class extends Resource {
|
|
|
229
198
|
this._rescheduleHeartbeatTimeout();
|
|
230
199
|
return;
|
|
231
200
|
}
|
|
232
|
-
const
|
|
233
|
-
if (
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
const message = this._ws?.protocol?.includes(EdgeWebsocketProtocol.V0) ? buf.fromBinary(MessageSchema, bytes) : muxer.receiveData(bytes);
|
|
237
|
-
if (message) {
|
|
201
|
+
const data = await toUint8Array(event.data);
|
|
202
|
+
if (this.isOpen) {
|
|
203
|
+
const message = buf.fromBinary(MessageSchema, data);
|
|
238
204
|
log("received", {
|
|
239
205
|
from: message.source,
|
|
240
206
|
payload: protocol.getPayloadType(message)
|
|
241
207
|
}, {
|
|
242
208
|
F: __dxlog_file2,
|
|
243
|
-
L:
|
|
209
|
+
L: 112,
|
|
244
210
|
S: this,
|
|
245
211
|
C: (f, a) => f(...a)
|
|
246
212
|
});
|
|
@@ -254,8 +220,6 @@ var EdgeWsConnection = class extends Resource {
|
|
|
254
220
|
try {
|
|
255
221
|
this._ws?.close();
|
|
256
222
|
this._ws = void 0;
|
|
257
|
-
this._wsMuxer?.destroy();
|
|
258
|
-
this._wsMuxer = void 0;
|
|
259
223
|
} catch (err) {
|
|
260
224
|
if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
|
|
261
225
|
return;
|
|
@@ -264,7 +228,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
264
228
|
err
|
|
265
229
|
}, {
|
|
266
230
|
F: __dxlog_file2,
|
|
267
|
-
L:
|
|
231
|
+
L: 128,
|
|
268
232
|
S: this,
|
|
269
233
|
C: (f, a) => f(...a)
|
|
270
234
|
});
|
|
@@ -273,7 +237,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
273
237
|
_scheduleHeartbeats() {
|
|
274
238
|
invariant2(this._ws, void 0, {
|
|
275
239
|
F: __dxlog_file2,
|
|
276
|
-
L:
|
|
240
|
+
L: 133,
|
|
277
241
|
S: this,
|
|
278
242
|
A: [
|
|
279
243
|
"this._ws",
|
|
@@ -293,13 +257,13 @@ var EdgeWsConnection = class extends Resource {
|
|
|
293
257
|
void this._inactivityTimeoutCtx?.dispose();
|
|
294
258
|
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
295
259
|
F: __dxlog_file2,
|
|
296
|
-
L:
|
|
260
|
+
L: 152
|
|
297
261
|
});
|
|
298
262
|
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
299
263
|
if (this.isOpen) {
|
|
300
264
|
log.warn("restart due to inactivity timeout", void 0, {
|
|
301
265
|
F: __dxlog_file2,
|
|
302
|
-
L:
|
|
266
|
+
L: 157,
|
|
303
267
|
S: this,
|
|
304
268
|
C: (f, a) => f(...a)
|
|
305
269
|
});
|
|
@@ -346,7 +310,6 @@ var EdgeClient = class extends Resource2 {
|
|
|
346
310
|
super();
|
|
347
311
|
this._identity = _identity;
|
|
348
312
|
this._config = _config;
|
|
349
|
-
this.statusChanged = new Event();
|
|
350
313
|
this._persistentLifecycle = new PersistentLifecycle({
|
|
351
314
|
start: async () => this._connect(),
|
|
352
315
|
stop: async (state) => this._disconnect(state)
|
|
@@ -362,13 +325,12 @@ var EdgeClient = class extends Resource2 {
|
|
|
362
325
|
get info() {
|
|
363
326
|
return {
|
|
364
327
|
open: this.isOpen,
|
|
365
|
-
status: this.status,
|
|
366
328
|
identity: this._identity.identityKey,
|
|
367
329
|
device: this._identity.peerKey
|
|
368
330
|
};
|
|
369
331
|
}
|
|
370
|
-
get
|
|
371
|
-
return Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED
|
|
332
|
+
get isConnected() {
|
|
333
|
+
return Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED;
|
|
372
334
|
}
|
|
373
335
|
get identityKey() {
|
|
374
336
|
return this._identity.identityKey;
|
|
@@ -383,13 +345,13 @@ var EdgeClient = class extends Resource2 {
|
|
|
383
345
|
oldIdentity: this._identity
|
|
384
346
|
}, {
|
|
385
347
|
F: __dxlog_file3,
|
|
386
|
-
L:
|
|
348
|
+
L: 94,
|
|
387
349
|
S: this,
|
|
388
350
|
C: (f, a) => f(...a)
|
|
389
351
|
});
|
|
390
352
|
this._identity = identity;
|
|
391
353
|
this._closeCurrentConnection(new EdgeIdentityChangedError());
|
|
392
|
-
|
|
354
|
+
this._persistentLifecycle.scheduleRestart();
|
|
393
355
|
}
|
|
394
356
|
}
|
|
395
357
|
onMessage(listener) {
|
|
@@ -406,7 +368,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
406
368
|
} catch (error) {
|
|
407
369
|
log2.catch(error, void 0, {
|
|
408
370
|
F: __dxlog_file3,
|
|
409
|
-
L:
|
|
371
|
+
L: 116,
|
|
410
372
|
S: this,
|
|
411
373
|
C: (f, a) => f(...a)
|
|
412
374
|
});
|
|
@@ -424,7 +386,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
424
386
|
info: this.info
|
|
425
387
|
}, {
|
|
426
388
|
F: __dxlog_file3,
|
|
427
|
-
L:
|
|
389
|
+
L: 128,
|
|
428
390
|
S: this,
|
|
429
391
|
C: (f, a) => f(...a)
|
|
430
392
|
});
|
|
@@ -433,7 +395,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
433
395
|
err
|
|
434
396
|
}, {
|
|
435
397
|
F: __dxlog_file3,
|
|
436
|
-
L:
|
|
398
|
+
L: 130,
|
|
437
399
|
S: this,
|
|
438
400
|
C: (f, a) => f(...a)
|
|
439
401
|
});
|
|
@@ -447,7 +409,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
447
409
|
peerKey: this._identity.peerKey
|
|
448
410
|
}, {
|
|
449
411
|
F: __dxlog_file3,
|
|
450
|
-
L:
|
|
412
|
+
L: 138,
|
|
451
413
|
S: this,
|
|
452
414
|
C: (f, a) => f(...a)
|
|
453
415
|
});
|
|
@@ -464,7 +426,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
464
426
|
if (this._identity !== identity) {
|
|
465
427
|
log2("identity changed during auth header request", void 0, {
|
|
466
428
|
F: __dxlog_file3,
|
|
467
|
-
L:
|
|
429
|
+
L: 152,
|
|
468
430
|
S: this,
|
|
469
431
|
C: (f, a) => f(...a)
|
|
470
432
|
});
|
|
@@ -477,7 +439,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
477
439
|
protocolHeader
|
|
478
440
|
}, {
|
|
479
441
|
F: __dxlog_file3,
|
|
480
|
-
L:
|
|
442
|
+
L: 158,
|
|
481
443
|
S: this,
|
|
482
444
|
C: (f, a) => f(...a)
|
|
483
445
|
});
|
|
@@ -492,7 +454,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
492
454
|
} else {
|
|
493
455
|
log2.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
494
456
|
F: __dxlog_file3,
|
|
495
|
-
L:
|
|
457
|
+
L: 168,
|
|
496
458
|
S: this,
|
|
497
459
|
C: (f, a) => f(...a)
|
|
498
460
|
});
|
|
@@ -501,11 +463,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
501
463
|
onRestartRequired: () => {
|
|
502
464
|
if (this._isActive(connection)) {
|
|
503
465
|
this._closeCurrentConnection();
|
|
504
|
-
|
|
466
|
+
this._persistentLifecycle.scheduleRestart();
|
|
505
467
|
} else {
|
|
506
468
|
log2.verbose("restart requested by inactive connection", void 0, {
|
|
507
469
|
F: __dxlog_file3,
|
|
508
|
-
L:
|
|
470
|
+
L: 176,
|
|
509
471
|
S: this,
|
|
510
472
|
C: (f, a) => f(...a)
|
|
511
473
|
});
|
|
@@ -521,7 +483,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
521
483
|
type: message.payload?.typeUrl
|
|
522
484
|
}, {
|
|
523
485
|
F: __dxlog_file3,
|
|
524
|
-
L:
|
|
486
|
+
L: 184,
|
|
525
487
|
S: this,
|
|
526
488
|
C: (f, a) => f(...a)
|
|
527
489
|
});
|
|
@@ -540,16 +502,13 @@ var EdgeClient = class extends Resource2 {
|
|
|
540
502
|
}
|
|
541
503
|
async _disconnect(state) {
|
|
542
504
|
await state.close();
|
|
543
|
-
this.statusChanged.emit(this.status);
|
|
544
505
|
}
|
|
545
506
|
_closeCurrentConnection(error = new EdgeConnectionClosedError()) {
|
|
546
507
|
this._currentConnection = void 0;
|
|
547
508
|
this._ready.throw(error);
|
|
548
509
|
this._ready.reset();
|
|
549
|
-
this.statusChanged.emit(this.status);
|
|
550
510
|
}
|
|
551
511
|
_notifyReconnected() {
|
|
552
|
-
this.statusChanged.emit(this.status);
|
|
553
512
|
for (const listener of this._reconnectListeners) {
|
|
554
513
|
try {
|
|
555
514
|
listener();
|
|
@@ -558,7 +517,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
558
517
|
err
|
|
559
518
|
}, {
|
|
560
519
|
F: __dxlog_file3,
|
|
561
|
-
L:
|
|
520
|
+
L: 217,
|
|
562
521
|
S: this,
|
|
563
522
|
C: (f, a) => f(...a)
|
|
564
523
|
});
|
|
@@ -575,7 +534,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
575
534
|
payload: protocol.getPayloadType(message)
|
|
576
535
|
}, {
|
|
577
536
|
F: __dxlog_file3,
|
|
578
|
-
L:
|
|
537
|
+
L: 227,
|
|
579
538
|
S: this,
|
|
580
539
|
C: (f, a) => f(...a)
|
|
581
540
|
});
|
|
@@ -590,7 +549,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
590
549
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
591
550
|
log2("waiting for websocket to become ready", void 0, {
|
|
592
551
|
F: __dxlog_file3,
|
|
593
|
-
L:
|
|
552
|
+
L: 238,
|
|
594
553
|
S: this,
|
|
595
554
|
C: (f, a) => f(...a)
|
|
596
555
|
});
|
|
@@ -620,7 +579,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
620
579
|
statusText: response.statusText
|
|
621
580
|
}, {
|
|
622
581
|
F: __dxlog_file3,
|
|
623
|
-
L:
|
|
582
|
+
L: 263,
|
|
624
583
|
S: this,
|
|
625
584
|
C: (f, a) => f(...a)
|
|
626
585
|
});
|
|
@@ -827,6 +786,7 @@ var EdgeHttpClient = class {
|
|
|
827
786
|
async uploadFunction(pathParts, body, args) {
|
|
828
787
|
const path = [
|
|
829
788
|
"functions",
|
|
789
|
+
pathParts.spaceId,
|
|
830
790
|
...pathParts.functionId ? [
|
|
831
791
|
pathParts.functionId
|
|
832
792
|
] : []
|
|
@@ -1025,14 +985,11 @@ var encodeAuthHeader = (challenge) => {
|
|
|
1025
985
|
return `VerifiablePresentation pb;base64,${encodedChallenge}`;
|
|
1026
986
|
};
|
|
1027
987
|
export {
|
|
1028
|
-
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
1029
|
-
CLOUDFLARE_RPC_MAX_BYTES,
|
|
1030
988
|
EdgeClient,
|
|
1031
989
|
EdgeConnectionClosedError,
|
|
1032
990
|
EdgeHttpClient,
|
|
1033
991
|
EdgeIdentityChangedError,
|
|
1034
992
|
Protocol,
|
|
1035
|
-
WebSocketMuxer,
|
|
1036
993
|
createChainEdgeIdentity,
|
|
1037
994
|
createDeviceEdgeIdentity,
|
|
1038
995
|
createEphemeralEdgeIdentity,
|