@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,115 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// packages/core/mesh/edge-client/src/protocol.ts
|
|
4
|
+
import { invariant } from "@dxos/invariant";
|
|
5
|
+
import { buf, bufWkt } from "@dxos/protocols/buf";
|
|
6
|
+
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
7
|
+
import { bufferToArray } from "@dxos/util";
|
|
8
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/protocol.ts";
|
|
9
|
+
var getTypename = (typeName) => `type.googleapis.com/${typeName}`;
|
|
10
|
+
var Protocol = class {
|
|
11
|
+
constructor(types) {
|
|
12
|
+
this._typeRegistry = buf.createRegistry(...types);
|
|
13
|
+
}
|
|
14
|
+
get typeRegistry() {
|
|
15
|
+
return this._typeRegistry;
|
|
16
|
+
}
|
|
17
|
+
toJson(message) {
|
|
18
|
+
try {
|
|
19
|
+
return buf.toJson(MessageSchema, message, {
|
|
20
|
+
registry: this.typeRegistry
|
|
21
|
+
});
|
|
22
|
+
} catch (err) {
|
|
23
|
+
return {
|
|
24
|
+
type: this.getPayloadType(message)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Return the payload with the given type.
|
|
30
|
+
*/
|
|
31
|
+
getPayload(message, type) {
|
|
32
|
+
invariant(message.payload, void 0, {
|
|
33
|
+
F: __dxlog_file,
|
|
34
|
+
L: 40,
|
|
35
|
+
S: this,
|
|
36
|
+
A: [
|
|
37
|
+
"message.payload",
|
|
38
|
+
""
|
|
39
|
+
]
|
|
40
|
+
});
|
|
41
|
+
const payloadTypename = this.getPayloadType(message);
|
|
42
|
+
if (type && type.typeName !== payloadTypename) {
|
|
43
|
+
throw new Error(`Unexpected payload type: ${payloadTypename}; expected ${type.typeName}`);
|
|
44
|
+
}
|
|
45
|
+
invariant(bufWkt.anyIs(message.payload, type), `Unexpected payload type: ${payloadTypename}}`, {
|
|
46
|
+
F: __dxlog_file,
|
|
47
|
+
L: 46,
|
|
48
|
+
S: this,
|
|
49
|
+
A: [
|
|
50
|
+
"bufWkt.anyIs(message.payload, type)",
|
|
51
|
+
"`Unexpected payload type: ${payloadTypename}}`"
|
|
52
|
+
]
|
|
53
|
+
});
|
|
54
|
+
const payload = bufWkt.anyUnpack(message.payload, this.typeRegistry);
|
|
55
|
+
invariant(payload, `Empty payload: ${payloadTypename}}`, {
|
|
56
|
+
F: __dxlog_file,
|
|
57
|
+
L: 48,
|
|
58
|
+
S: this,
|
|
59
|
+
A: [
|
|
60
|
+
"payload",
|
|
61
|
+
"`Empty payload: ${payloadTypename}}`"
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
return payload;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get the payload type.
|
|
68
|
+
*/
|
|
69
|
+
getPayloadType(message) {
|
|
70
|
+
if (!message.payload) {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
const [, type] = message.payload.typeUrl.split("/");
|
|
74
|
+
return type;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Create a packed message.
|
|
78
|
+
*/
|
|
79
|
+
createMessage(type, { source, target, payload, serviceId }) {
|
|
80
|
+
return buf.create(MessageSchema, {
|
|
81
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
82
|
+
source,
|
|
83
|
+
target,
|
|
84
|
+
serviceId,
|
|
85
|
+
payload: payload ? bufWkt.anyPack(type, buf.create(type, payload)) : void 0
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var toUint8Array = async (data) => {
|
|
90
|
+
if (data instanceof Buffer) {
|
|
91
|
+
return bufferToArray(data);
|
|
92
|
+
}
|
|
93
|
+
if (data instanceof Blob) {
|
|
94
|
+
return new Uint8Array(await data.arrayBuffer());
|
|
95
|
+
}
|
|
96
|
+
throw new Error(`Unexpected datatype: ${data}`);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// packages/core/mesh/edge-client/src/defs.ts
|
|
100
|
+
import { bufWkt as bufWkt2 } from "@dxos/protocols/buf";
|
|
101
|
+
import { SwarmRequestSchema, SwarmResponseSchema, TextMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
102
|
+
var protocol = new Protocol([
|
|
103
|
+
SwarmRequestSchema,
|
|
104
|
+
SwarmResponseSchema,
|
|
105
|
+
TextMessageSchema,
|
|
106
|
+
bufWkt2.AnySchema
|
|
107
|
+
]);
|
|
108
|
+
|
|
109
|
+
export {
|
|
110
|
+
getTypename,
|
|
111
|
+
Protocol,
|
|
112
|
+
toUint8Array,
|
|
113
|
+
protocol
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=chunk-HNVT57AU.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,22 +1,18 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
4
|
-
CLOUDFLARE_RPC_MAX_BYTES,
|
|
5
3
|
Protocol,
|
|
6
|
-
WebSocketMuxer,
|
|
7
4
|
getTypename,
|
|
8
5
|
protocol,
|
|
9
6
|
toUint8Array
|
|
10
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-HNVT57AU.mjs";
|
|
11
8
|
|
|
12
9
|
// packages/core/mesh/edge-client/src/index.ts
|
|
13
10
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
14
11
|
|
|
15
12
|
// packages/core/mesh/edge-client/src/edge-client.ts
|
|
16
|
-
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle
|
|
13
|
+
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle } from "@dxos/async";
|
|
17
14
|
import { Resource as Resource2 } from "@dxos/context";
|
|
18
15
|
import { log as log2, logInfo as logInfo2 } from "@dxos/log";
|
|
19
|
-
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
20
16
|
|
|
21
17
|
// packages/core/mesh/edge-client/src/edge-identity.ts
|
|
22
18
|
import { invariant } from "@dxos/invariant";
|
|
@@ -64,7 +60,6 @@ import { scheduleTask, scheduleTaskInterval } from "@dxos/async";
|
|
|
64
60
|
import { Context, Resource } from "@dxos/context";
|
|
65
61
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
66
62
|
import { log, logInfo } from "@dxos/log";
|
|
67
|
-
import { EdgeWebsocketProtocol } from "@dxos/protocols";
|
|
68
63
|
import { buf } from "@dxos/protocols/buf";
|
|
69
64
|
import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
70
65
|
function _ts_decorate(decorators, target, key, desc) {
|
|
@@ -76,6 +71,7 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
76
71
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
|
|
77
72
|
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
78
73
|
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
74
|
+
var CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;
|
|
79
75
|
var EdgeWsConnection = class extends Resource {
|
|
80
76
|
constructor(_identity, _connectionInfo, _callbacks) {
|
|
81
77
|
super();
|
|
@@ -93,73 +89,47 @@ var EdgeWsConnection = class extends Resource {
|
|
|
93
89
|
send(message) {
|
|
94
90
|
invariant2(this._ws, void 0, {
|
|
95
91
|
F: __dxlog_file2,
|
|
96
|
-
L:
|
|
92
|
+
L: 54,
|
|
97
93
|
S: this,
|
|
98
94
|
A: [
|
|
99
95
|
"this._ws",
|
|
100
96
|
""
|
|
101
97
|
]
|
|
102
98
|
});
|
|
103
|
-
invariant2(this._wsMuxer, void 0, {
|
|
104
|
-
F: __dxlog_file2,
|
|
105
|
-
L: 53,
|
|
106
|
-
S: this,
|
|
107
|
-
A: [
|
|
108
|
-
"this._wsMuxer",
|
|
109
|
-
""
|
|
110
|
-
]
|
|
111
|
-
});
|
|
112
99
|
log("sending...", {
|
|
113
100
|
peerKey: this._identity.peerKey,
|
|
114
101
|
payload: protocol.getPayloadType(message)
|
|
115
102
|
}, {
|
|
116
103
|
F: __dxlog_file2,
|
|
117
|
-
L:
|
|
104
|
+
L: 55,
|
|
118
105
|
S: this,
|
|
119
106
|
C: (f, a) => f(...a)
|
|
120
107
|
});
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}, {
|
|
129
|
-
F: __dxlog_file2,
|
|
130
|
-
L: 58,
|
|
131
|
-
S: this,
|
|
132
|
-
C: (f, a) => f(...a)
|
|
133
|
-
});
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
this._ws.send(binary);
|
|
137
|
-
} else {
|
|
138
|
-
this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
|
|
108
|
+
const encoded = buf.toBinary(MessageSchema, message);
|
|
109
|
+
if (encoded.byteLength >= CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {
|
|
110
|
+
log.error("edge message dropped due to websocket message limit", {
|
|
111
|
+
byteLength: encoded.byteLength,
|
|
112
|
+
serviceId: message.serviceId,
|
|
113
|
+
payload: protocol.getPayloadType(message)
|
|
114
|
+
}, {
|
|
139
115
|
F: __dxlog_file2,
|
|
140
|
-
L:
|
|
116
|
+
L: 58,
|
|
141
117
|
S: this,
|
|
142
118
|
C: (f, a) => f(...a)
|
|
143
|
-
})
|
|
119
|
+
});
|
|
120
|
+
return;
|
|
144
121
|
}
|
|
122
|
+
this._ws.send(encoded);
|
|
145
123
|
}
|
|
146
124
|
async _open() {
|
|
147
|
-
const baseProtocols = [
|
|
148
|
-
...Object.values(EdgeWebsocketProtocol)
|
|
149
|
-
];
|
|
150
125
|
this._ws = new WebSocket(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [
|
|
151
|
-
...baseProtocols,
|
|
152
126
|
this._connectionInfo.protocolHeader
|
|
153
|
-
] : [
|
|
154
|
-
...baseProtocols
|
|
155
|
-
]);
|
|
156
|
-
const muxer = new WebSocketMuxer(this._ws);
|
|
157
|
-
this._wsMuxer = muxer;
|
|
127
|
+
] : []);
|
|
158
128
|
this._ws.onopen = () => {
|
|
159
129
|
if (this.isOpen) {
|
|
160
130
|
log("connected", void 0, {
|
|
161
131
|
F: __dxlog_file2,
|
|
162
|
-
L:
|
|
132
|
+
L: 76,
|
|
163
133
|
S: this,
|
|
164
134
|
C: (f, a) => f(...a)
|
|
165
135
|
});
|
|
@@ -170,7 +140,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
170
140
|
currentIdentity: this._identity
|
|
171
141
|
}, {
|
|
172
142
|
F: __dxlog_file2,
|
|
173
|
-
L:
|
|
143
|
+
L: 80,
|
|
174
144
|
S: this,
|
|
175
145
|
C: (f, a) => f(...a)
|
|
176
146
|
});
|
|
@@ -183,12 +153,11 @@ var EdgeWsConnection = class extends Resource {
|
|
|
183
153
|
reason: event.reason
|
|
184
154
|
}, {
|
|
185
155
|
F: __dxlog_file2,
|
|
186
|
-
L:
|
|
156
|
+
L: 85,
|
|
187
157
|
S: this,
|
|
188
158
|
C: (f, a) => f(...a)
|
|
189
159
|
});
|
|
190
160
|
this._callbacks.onRestartRequired();
|
|
191
|
-
muxer.destroy();
|
|
192
161
|
}
|
|
193
162
|
};
|
|
194
163
|
this._ws.onerror = (event) => {
|
|
@@ -198,7 +167,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
198
167
|
info: event.message
|
|
199
168
|
}, {
|
|
200
169
|
F: __dxlog_file2,
|
|
201
|
-
L:
|
|
170
|
+
L: 91,
|
|
202
171
|
S: this,
|
|
203
172
|
C: (f, a) => f(...a)
|
|
204
173
|
});
|
|
@@ -208,7 +177,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
208
177
|
error: event.error
|
|
209
178
|
}, {
|
|
210
179
|
F: __dxlog_file2,
|
|
211
|
-
L:
|
|
180
|
+
L: 94,
|
|
212
181
|
S: this,
|
|
213
182
|
C: (f, a) => f(...a)
|
|
214
183
|
});
|
|
@@ -220,7 +189,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
220
189
|
event: event.type
|
|
221
190
|
}, {
|
|
222
191
|
F: __dxlog_file2,
|
|
223
|
-
L:
|
|
192
|
+
L: 102,
|
|
224
193
|
S: this,
|
|
225
194
|
C: (f, a) => f(...a)
|
|
226
195
|
});
|
|
@@ -230,18 +199,15 @@ var EdgeWsConnection = class extends Resource {
|
|
|
230
199
|
this._rescheduleHeartbeatTimeout();
|
|
231
200
|
return;
|
|
232
201
|
}
|
|
233
|
-
const
|
|
234
|
-
if (
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
const message = this._ws?.protocol?.includes(EdgeWebsocketProtocol.V0) ? buf.fromBinary(MessageSchema, bytes) : muxer.receiveData(bytes);
|
|
238
|
-
if (message) {
|
|
202
|
+
const data = await toUint8Array(event.data);
|
|
203
|
+
if (this.isOpen) {
|
|
204
|
+
const message = buf.fromBinary(MessageSchema, data);
|
|
239
205
|
log("received", {
|
|
240
206
|
from: message.source,
|
|
241
207
|
payload: protocol.getPayloadType(message)
|
|
242
208
|
}, {
|
|
243
209
|
F: __dxlog_file2,
|
|
244
|
-
L:
|
|
210
|
+
L: 112,
|
|
245
211
|
S: this,
|
|
246
212
|
C: (f, a) => f(...a)
|
|
247
213
|
});
|
|
@@ -255,8 +221,6 @@ var EdgeWsConnection = class extends Resource {
|
|
|
255
221
|
try {
|
|
256
222
|
this._ws?.close();
|
|
257
223
|
this._ws = void 0;
|
|
258
|
-
this._wsMuxer?.destroy();
|
|
259
|
-
this._wsMuxer = void 0;
|
|
260
224
|
} catch (err) {
|
|
261
225
|
if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
|
|
262
226
|
return;
|
|
@@ -265,7 +229,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
265
229
|
err
|
|
266
230
|
}, {
|
|
267
231
|
F: __dxlog_file2,
|
|
268
|
-
L:
|
|
232
|
+
L: 128,
|
|
269
233
|
S: this,
|
|
270
234
|
C: (f, a) => f(...a)
|
|
271
235
|
});
|
|
@@ -274,7 +238,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
274
238
|
_scheduleHeartbeats() {
|
|
275
239
|
invariant2(this._ws, void 0, {
|
|
276
240
|
F: __dxlog_file2,
|
|
277
|
-
L:
|
|
241
|
+
L: 133,
|
|
278
242
|
S: this,
|
|
279
243
|
A: [
|
|
280
244
|
"this._ws",
|
|
@@ -294,13 +258,13 @@ var EdgeWsConnection = class extends Resource {
|
|
|
294
258
|
void this._inactivityTimeoutCtx?.dispose();
|
|
295
259
|
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
296
260
|
F: __dxlog_file2,
|
|
297
|
-
L:
|
|
261
|
+
L: 152
|
|
298
262
|
});
|
|
299
263
|
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
300
264
|
if (this.isOpen) {
|
|
301
265
|
log.warn("restart due to inactivity timeout", void 0, {
|
|
302
266
|
F: __dxlog_file2,
|
|
303
|
-
L:
|
|
267
|
+
L: 157,
|
|
304
268
|
S: this,
|
|
305
269
|
C: (f, a) => f(...a)
|
|
306
270
|
});
|
|
@@ -347,7 +311,6 @@ var EdgeClient = class extends Resource2 {
|
|
|
347
311
|
super();
|
|
348
312
|
this._identity = _identity;
|
|
349
313
|
this._config = _config;
|
|
350
|
-
this.statusChanged = new Event();
|
|
351
314
|
this._persistentLifecycle = new PersistentLifecycle({
|
|
352
315
|
start: async () => this._connect(),
|
|
353
316
|
stop: async (state) => this._disconnect(state)
|
|
@@ -363,13 +326,12 @@ var EdgeClient = class extends Resource2 {
|
|
|
363
326
|
get info() {
|
|
364
327
|
return {
|
|
365
328
|
open: this.isOpen,
|
|
366
|
-
status: this.status,
|
|
367
329
|
identity: this._identity.identityKey,
|
|
368
330
|
device: this._identity.peerKey
|
|
369
331
|
};
|
|
370
332
|
}
|
|
371
|
-
get
|
|
372
|
-
return Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED
|
|
333
|
+
get isConnected() {
|
|
334
|
+
return Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED;
|
|
373
335
|
}
|
|
374
336
|
get identityKey() {
|
|
375
337
|
return this._identity.identityKey;
|
|
@@ -384,13 +346,13 @@ var EdgeClient = class extends Resource2 {
|
|
|
384
346
|
oldIdentity: this._identity
|
|
385
347
|
}, {
|
|
386
348
|
F: __dxlog_file3,
|
|
387
|
-
L:
|
|
349
|
+
L: 94,
|
|
388
350
|
S: this,
|
|
389
351
|
C: (f, a) => f(...a)
|
|
390
352
|
});
|
|
391
353
|
this._identity = identity;
|
|
392
354
|
this._closeCurrentConnection(new EdgeIdentityChangedError());
|
|
393
|
-
|
|
355
|
+
this._persistentLifecycle.scheduleRestart();
|
|
394
356
|
}
|
|
395
357
|
}
|
|
396
358
|
onMessage(listener) {
|
|
@@ -407,7 +369,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
407
369
|
} catch (error) {
|
|
408
370
|
log2.catch(error, void 0, {
|
|
409
371
|
F: __dxlog_file3,
|
|
410
|
-
L:
|
|
372
|
+
L: 116,
|
|
411
373
|
S: this,
|
|
412
374
|
C: (f, a) => f(...a)
|
|
413
375
|
});
|
|
@@ -425,7 +387,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
425
387
|
info: this.info
|
|
426
388
|
}, {
|
|
427
389
|
F: __dxlog_file3,
|
|
428
|
-
L:
|
|
390
|
+
L: 128,
|
|
429
391
|
S: this,
|
|
430
392
|
C: (f, a) => f(...a)
|
|
431
393
|
});
|
|
@@ -434,7 +396,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
434
396
|
err
|
|
435
397
|
}, {
|
|
436
398
|
F: __dxlog_file3,
|
|
437
|
-
L:
|
|
399
|
+
L: 130,
|
|
438
400
|
S: this,
|
|
439
401
|
C: (f, a) => f(...a)
|
|
440
402
|
});
|
|
@@ -448,7 +410,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
448
410
|
peerKey: this._identity.peerKey
|
|
449
411
|
}, {
|
|
450
412
|
F: __dxlog_file3,
|
|
451
|
-
L:
|
|
413
|
+
L: 138,
|
|
452
414
|
S: this,
|
|
453
415
|
C: (f, a) => f(...a)
|
|
454
416
|
});
|
|
@@ -465,7 +427,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
465
427
|
if (this._identity !== identity) {
|
|
466
428
|
log2("identity changed during auth header request", void 0, {
|
|
467
429
|
F: __dxlog_file3,
|
|
468
|
-
L:
|
|
430
|
+
L: 152,
|
|
469
431
|
S: this,
|
|
470
432
|
C: (f, a) => f(...a)
|
|
471
433
|
});
|
|
@@ -478,7 +440,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
478
440
|
protocolHeader
|
|
479
441
|
}, {
|
|
480
442
|
F: __dxlog_file3,
|
|
481
|
-
L:
|
|
443
|
+
L: 158,
|
|
482
444
|
S: this,
|
|
483
445
|
C: (f, a) => f(...a)
|
|
484
446
|
});
|
|
@@ -493,7 +455,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
493
455
|
} else {
|
|
494
456
|
log2.verbose("connected callback ignored, because connection is not active", void 0, {
|
|
495
457
|
F: __dxlog_file3,
|
|
496
|
-
L:
|
|
458
|
+
L: 168,
|
|
497
459
|
S: this,
|
|
498
460
|
C: (f, a) => f(...a)
|
|
499
461
|
});
|
|
@@ -502,11 +464,11 @@ var EdgeClient = class extends Resource2 {
|
|
|
502
464
|
onRestartRequired: () => {
|
|
503
465
|
if (this._isActive(connection)) {
|
|
504
466
|
this._closeCurrentConnection();
|
|
505
|
-
|
|
467
|
+
this._persistentLifecycle.scheduleRestart();
|
|
506
468
|
} else {
|
|
507
469
|
log2.verbose("restart requested by inactive connection", void 0, {
|
|
508
470
|
F: __dxlog_file3,
|
|
509
|
-
L:
|
|
471
|
+
L: 176,
|
|
510
472
|
S: this,
|
|
511
473
|
C: (f, a) => f(...a)
|
|
512
474
|
});
|
|
@@ -522,7 +484,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
522
484
|
type: message.payload?.typeUrl
|
|
523
485
|
}, {
|
|
524
486
|
F: __dxlog_file3,
|
|
525
|
-
L:
|
|
487
|
+
L: 184,
|
|
526
488
|
S: this,
|
|
527
489
|
C: (f, a) => f(...a)
|
|
528
490
|
});
|
|
@@ -541,16 +503,13 @@ var EdgeClient = class extends Resource2 {
|
|
|
541
503
|
}
|
|
542
504
|
async _disconnect(state) {
|
|
543
505
|
await state.close();
|
|
544
|
-
this.statusChanged.emit(this.status);
|
|
545
506
|
}
|
|
546
507
|
_closeCurrentConnection(error = new EdgeConnectionClosedError()) {
|
|
547
508
|
this._currentConnection = void 0;
|
|
548
509
|
this._ready.throw(error);
|
|
549
510
|
this._ready.reset();
|
|
550
|
-
this.statusChanged.emit(this.status);
|
|
551
511
|
}
|
|
552
512
|
_notifyReconnected() {
|
|
553
|
-
this.statusChanged.emit(this.status);
|
|
554
513
|
for (const listener of this._reconnectListeners) {
|
|
555
514
|
try {
|
|
556
515
|
listener();
|
|
@@ -559,7 +518,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
559
518
|
err
|
|
560
519
|
}, {
|
|
561
520
|
F: __dxlog_file3,
|
|
562
|
-
L:
|
|
521
|
+
L: 217,
|
|
563
522
|
S: this,
|
|
564
523
|
C: (f, a) => f(...a)
|
|
565
524
|
});
|
|
@@ -576,7 +535,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
576
535
|
payload: protocol.getPayloadType(message)
|
|
577
536
|
}, {
|
|
578
537
|
F: __dxlog_file3,
|
|
579
|
-
L:
|
|
538
|
+
L: 227,
|
|
580
539
|
S: this,
|
|
581
540
|
C: (f, a) => f(...a)
|
|
582
541
|
});
|
|
@@ -591,7 +550,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
591
550
|
if (this._ready.state !== TriggerState.RESOLVED) {
|
|
592
551
|
log2("waiting for websocket to become ready", void 0, {
|
|
593
552
|
F: __dxlog_file3,
|
|
594
|
-
L:
|
|
553
|
+
L: 238,
|
|
595
554
|
S: this,
|
|
596
555
|
C: (f, a) => f(...a)
|
|
597
556
|
});
|
|
@@ -621,7 +580,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
621
580
|
statusText: response.statusText
|
|
622
581
|
}, {
|
|
623
582
|
F: __dxlog_file3,
|
|
624
|
-
L:
|
|
583
|
+
L: 263,
|
|
625
584
|
S: this,
|
|
626
585
|
C: (f, a) => f(...a)
|
|
627
586
|
});
|
|
@@ -828,6 +787,7 @@ var EdgeHttpClient = class {
|
|
|
828
787
|
async uploadFunction(pathParts, body, args) {
|
|
829
788
|
const path = [
|
|
830
789
|
"functions",
|
|
790
|
+
pathParts.spaceId,
|
|
831
791
|
...pathParts.functionId ? [
|
|
832
792
|
pathParts.functionId
|
|
833
793
|
] : []
|
|
@@ -1026,14 +986,11 @@ var encodeAuthHeader = (challenge) => {
|
|
|
1026
986
|
return `VerifiablePresentation pb;base64,${encodedChallenge}`;
|
|
1027
987
|
};
|
|
1028
988
|
export {
|
|
1029
|
-
CLOUDFLARE_MESSAGE_MAX_BYTES,
|
|
1030
|
-
CLOUDFLARE_RPC_MAX_BYTES,
|
|
1031
989
|
EdgeClient,
|
|
1032
990
|
EdgeConnectionClosedError,
|
|
1033
991
|
EdgeHttpClient,
|
|
1034
992
|
EdgeIdentityChangedError,
|
|
1035
993
|
Protocol,
|
|
1036
|
-
WebSocketMuxer,
|
|
1037
994
|
createChainEdgeIdentity,
|
|
1038
995
|
createDeviceEdgeIdentity,
|
|
1039
996
|
createEphemeralEdgeIdentity,
|