@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.
Files changed (61) hide show
  1. package/dist/lib/browser/chunk-ZWJXA37R.mjs +113 -0
  2. package/dist/lib/browser/chunk-ZWJXA37R.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +50 -93
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +20 -32
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/chunk-ANV2HBEH.cjs +136 -0
  9. package/dist/lib/node/chunk-ANV2HBEH.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +62 -105
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +21 -32
  14. package/dist/lib/node/testing/index.cjs.map +3 -3
  15. package/dist/lib/node-esm/chunk-HNVT57AU.mjs +115 -0
  16. package/dist/lib/node-esm/chunk-HNVT57AU.mjs.map +7 -0
  17. package/dist/lib/node-esm/index.mjs +50 -93
  18. package/dist/lib/node-esm/index.mjs.map +3 -3
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/lib/node-esm/testing/index.mjs +20 -32
  21. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  22. package/dist/types/src/auth.d.ts.map +1 -1
  23. package/dist/types/src/edge-client.d.ts +2 -7
  24. package/dist/types/src/edge-client.d.ts.map +1 -1
  25. package/dist/types/src/edge-http-client.d.ts +1 -0
  26. package/dist/types/src/edge-http-client.d.ts.map +1 -1
  27. package/dist/types/src/edge-identity.d.ts.map +1 -1
  28. package/dist/types/src/edge-ws-connection.d.ts +0 -1
  29. package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
  30. package/dist/types/src/index.d.ts +0 -1
  31. package/dist/types/src/index.d.ts.map +1 -1
  32. package/dist/types/src/protocol.d.ts.map +1 -1
  33. package/dist/types/src/testing/test-utils.d.ts +2 -6
  34. package/dist/types/src/testing/test-utils.d.ts.map +1 -1
  35. package/dist/types/src/utils.d.ts.map +1 -1
  36. package/dist/types/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +14 -19
  38. package/src/edge-client.test.ts +4 -5
  39. package/src/edge-client.ts +8 -16
  40. package/src/edge-http-client.ts +2 -2
  41. package/src/edge-ws-connection.ts +18 -36
  42. package/src/index.ts +0 -1
  43. package/src/testing/test-utils.ts +26 -33
  44. package/dist/lib/browser/chunk-TKYUZ5ZK.mjs +0 -302
  45. package/dist/lib/browser/chunk-TKYUZ5ZK.mjs.map +0 -7
  46. package/dist/lib/browser/edge-ws-muxer.mjs +0 -11
  47. package/dist/lib/browser/edge-ws-muxer.mjs.map +0 -7
  48. package/dist/lib/node/chunk-ZOL3YSDR.cjs +0 -322
  49. package/dist/lib/node/chunk-ZOL3YSDR.cjs.map +0 -7
  50. package/dist/lib/node/edge-ws-muxer.cjs +0 -33
  51. package/dist/lib/node/edge-ws-muxer.cjs.map +0 -7
  52. package/dist/lib/node-esm/chunk-25HGRGNZ.mjs +0 -304
  53. package/dist/lib/node-esm/chunk-25HGRGNZ.mjs.map +0 -7
  54. package/dist/lib/node-esm/edge-ws-muxer.mjs +0 -12
  55. package/dist/lib/node-esm/edge-ws-muxer.mjs.map +0 -7
  56. package/dist/types/src/edge-ws-muxer.d.ts +0 -35
  57. package/dist/types/src/edge-ws-muxer.d.ts.map +0 -1
  58. package/dist/types/src/edge-ws-muxer.test.d.ts +0 -2
  59. package/dist/types/src/edge-ws-muxer.test.d.ts.map +0 -1
  60. package/src/edge-ws-muxer.test.ts +0 -55
  61. package/src/edge-ws-muxer.ts +0 -217
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var chunk_ANV2HBEH_exports = {};
20
+ __export(chunk_ANV2HBEH_exports, {
21
+ Protocol: () => Protocol,
22
+ getTypename: () => getTypename,
23
+ protocol: () => protocol,
24
+ toUint8Array: () => toUint8Array
25
+ });
26
+ module.exports = __toCommonJS(chunk_ANV2HBEH_exports);
27
+ var import_invariant = require("@dxos/invariant");
28
+ var import_buf = require("@dxos/protocols/buf");
29
+ var import_messenger_pb = require("@dxos/protocols/buf/dxos/edge/messenger_pb");
30
+ var import_util = require("@dxos/util");
31
+ var import_buf2 = require("@dxos/protocols/buf");
32
+ var import_messenger_pb2 = require("@dxos/protocols/buf/dxos/edge/messenger_pb");
33
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/protocol.ts";
34
+ var getTypename = (typeName) => `type.googleapis.com/${typeName}`;
35
+ var Protocol = class {
36
+ constructor(types) {
37
+ this._typeRegistry = import_buf.buf.createRegistry(...types);
38
+ }
39
+ get typeRegistry() {
40
+ return this._typeRegistry;
41
+ }
42
+ toJson(message) {
43
+ try {
44
+ return import_buf.buf.toJson(import_messenger_pb.MessageSchema, message, {
45
+ registry: this.typeRegistry
46
+ });
47
+ } catch (err) {
48
+ return {
49
+ type: this.getPayloadType(message)
50
+ };
51
+ }
52
+ }
53
+ /**
54
+ * Return the payload with the given type.
55
+ */
56
+ getPayload(message, type) {
57
+ (0, import_invariant.invariant)(message.payload, void 0, {
58
+ F: __dxlog_file,
59
+ L: 40,
60
+ S: this,
61
+ A: [
62
+ "message.payload",
63
+ ""
64
+ ]
65
+ });
66
+ const payloadTypename = this.getPayloadType(message);
67
+ if (type && type.typeName !== payloadTypename) {
68
+ throw new Error(`Unexpected payload type: ${payloadTypename}; expected ${type.typeName}`);
69
+ }
70
+ (0, import_invariant.invariant)(import_buf.bufWkt.anyIs(message.payload, type), `Unexpected payload type: ${payloadTypename}}`, {
71
+ F: __dxlog_file,
72
+ L: 46,
73
+ S: this,
74
+ A: [
75
+ "bufWkt.anyIs(message.payload, type)",
76
+ "`Unexpected payload type: ${payloadTypename}}`"
77
+ ]
78
+ });
79
+ const payload = import_buf.bufWkt.anyUnpack(message.payload, this.typeRegistry);
80
+ (0, import_invariant.invariant)(payload, `Empty payload: ${payloadTypename}}`, {
81
+ F: __dxlog_file,
82
+ L: 48,
83
+ S: this,
84
+ A: [
85
+ "payload",
86
+ "`Empty payload: ${payloadTypename}}`"
87
+ ]
88
+ });
89
+ return payload;
90
+ }
91
+ /**
92
+ * Get the payload type.
93
+ */
94
+ getPayloadType(message) {
95
+ if (!message.payload) {
96
+ return void 0;
97
+ }
98
+ const [, type] = message.payload.typeUrl.split("/");
99
+ return type;
100
+ }
101
+ /**
102
+ * Create a packed message.
103
+ */
104
+ createMessage(type, { source, target, payload, serviceId }) {
105
+ return import_buf.buf.create(import_messenger_pb.MessageSchema, {
106
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
107
+ source,
108
+ target,
109
+ serviceId,
110
+ payload: payload ? import_buf.bufWkt.anyPack(type, import_buf.buf.create(type, payload)) : void 0
111
+ });
112
+ }
113
+ };
114
+ var toUint8Array = async (data) => {
115
+ if (data instanceof Buffer) {
116
+ return (0, import_util.bufferToArray)(data);
117
+ }
118
+ if (data instanceof Blob) {
119
+ return new Uint8Array(await data.arrayBuffer());
120
+ }
121
+ throw new Error(`Unexpected datatype: ${data}`);
122
+ };
123
+ var protocol = new Protocol([
124
+ import_messenger_pb2.SwarmRequestSchema,
125
+ import_messenger_pb2.SwarmResponseSchema,
126
+ import_messenger_pb2.TextMessageSchema,
127
+ import_buf2.bufWkt.AnySchema
128
+ ]);
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ Protocol,
132
+ getTypename,
133
+ protocol,
134
+ toUint8Array
135
+ });
136
+ //# sourceMappingURL=chunk-ANV2HBEH.cjs.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,uBAA0B;AAC1B,iBAA4B;AAC5B,0BAA6D;AAC7D,kBAA8B;ACH9B,IAAAA,cAAuB;AACvB,IAAAC,uBAA2E;;ADMpE,IAAMC,cAAc,CAACC,aAAqB,uBAAuBA,QAAAA;AAKjE,IAAMC,WAAN,MAAMA;EAGXC,YAAYC,OAA0B;AACpC,SAAKC,gBAAgBC,eAAIC,eAAc,GAAIH,KAAAA;EAC7C;EAEA,IAAII,eAA6B;AAC/B,WAAO,KAAKH;EACd;EAEAI,OAAOC,SAAuB;AAC5B,QAAI;AACF,aAAOJ,eAAIG,OAAOE,mCAAeD,SAAS;QAAEE,UAAU,KAAKJ;MAAa,CAAA;IAC1E,SAASK,KAAK;AACZ,aAAO;QAAEC,MAAM,KAAKC,eAAeL,OAAAA;MAAS;IAC9C;EACF;;;;EAKAM,WAAyCN,SAAkBI,MAAoC;AAC7FG,oCAAUP,QAAQQ,SAAO,QAAA;;;;;;;;;AACzB,UAAMC,kBAAkB,KAAKJ,eAAeL,OAAAA;AAC5C,QAAII,QAAQA,KAAKb,aAAakB,iBAAiB;AAC7C,YAAM,IAAIC,MAAM,4BAA4BD,eAAAA,cAA6BL,KAAKb,QAAQ,EAAE;IAC1F;AAEAgB,oCAAUI,kBAAOC,MAAMZ,QAAQQ,SAASJ,IAAAA,GAAO,4BAA4BK,eAAAA,KAAkB;;;;;;;;;AAC7F,UAAMD,UAAUG,kBAAOE,UAAUb,QAAQQ,SAAS,KAAKV,YAAY;AACnES,oCAAUC,SAAS,kBAAkBC,eAAAA,KAAkB;;;;;;;;;AACvD,WAAOD;EACT;;;;EAKAH,eAAeL,SAAsC;AACnD,QAAI,CAACA,QAAQQ,SAAS;AACpB,aAAOM;IACT;AAEA,UAAM,CAAA,EAAGV,IAAAA,IAAQJ,QAAQQ,QAAQO,QAAQC,MAAM,GAAA;AAC/C,WAAOZ;EACT;;;;EAKAa,cACEb,MACA,EACEc,QACAC,QACAX,SACAY,UAAS,GAOX;AACA,WAAOxB,eAAIyB,OAAOpB,mCAAe;MAC/BqB,YAAW,oBAAIC,KAAAA,GAAOC,YAAW;MACjCN;MACAC;MACAC;MACAZ,SAASA,UAAUG,kBAAOc,QAAQrB,MAAMR,eAAIyB,OAAOjB,MAAMI,OAAAA,CAAAA,IAAYM;IACvE,CAAA;EACF;AACF;AAKO,IAAMY,eAAe,OAAOC,SAAAA;AAEjC,MAAIA,gBAAgBC,QAAQ;AAC1B,eAAOC,2BAAcF,IAAAA;EACvB;AAGA,MAAIA,gBAAgBG,MAAM;AACxB,WAAO,IAAIC,WAAW,MAAOJ,KAAcK,YAAW,CAAA;EACxD;AAEA,QAAM,IAAItB,MAAM,wBAAwBiB,IAAAA,EAAM;AAChD;AChGO,IAAMM,WAAW,IAAIzC,SAAS;EAAC0C;EAAoBC;EAAqBC;EAAmBzB,YAAAA,OAAO0B;CAAU;",
6
+ "names": ["import_buf", "import_messenger_pb", "getTypename", "typeName", "Protocol", "constructor", "types", "_typeRegistry", "buf", "createRegistry", "typeRegistry", "toJson", "message", "MessageSchema", "registry", "err", "type", "getPayloadType", "getPayload", "invariant", "payload", "payloadTypename", "Error", "bufWkt", "anyIs", "anyUnpack", "undefined", "typeUrl", "split", "createMessage", "source", "target", "serviceId", "create", "timestamp", "Date", "toISOString", "anyPack", "toUint8Array", "data", "Buffer", "bufferToArray", "Blob", "Uint8Array", "arrayBuffer", "protocol", "SwarmRequestSchema", "SwarmResponseSchema", "TextMessageSchema", "AnySchema"]
7
+ }
@@ -29,31 +29,27 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
30
  var node_exports = {};
31
31
  __export(node_exports, {
32
- CLOUDFLARE_MESSAGE_MAX_BYTES: () => import_chunk_ZOL3YSDR.CLOUDFLARE_MESSAGE_MAX_BYTES,
33
- CLOUDFLARE_RPC_MAX_BYTES: () => import_chunk_ZOL3YSDR.CLOUDFLARE_RPC_MAX_BYTES,
34
32
  EdgeClient: () => EdgeClient,
35
33
  EdgeConnectionClosedError: () => EdgeConnectionClosedError,
36
34
  EdgeHttpClient: () => EdgeHttpClient,
37
35
  EdgeIdentityChangedError: () => EdgeIdentityChangedError,
38
- Protocol: () => import_chunk_ZOL3YSDR.Protocol,
39
- WebSocketMuxer: () => import_chunk_ZOL3YSDR.WebSocketMuxer,
36
+ Protocol: () => import_chunk_ANV2HBEH.Protocol,
40
37
  createChainEdgeIdentity: () => createChainEdgeIdentity,
41
38
  createDeviceEdgeIdentity: () => createDeviceEdgeIdentity,
42
39
  createEphemeralEdgeIdentity: () => createEphemeralEdgeIdentity,
43
40
  createStubEdgeIdentity: () => createStubEdgeIdentity,
44
41
  createTestHaloEdgeIdentity: () => createTestHaloEdgeIdentity,
45
- getTypename: () => import_chunk_ZOL3YSDR.getTypename,
42
+ getTypename: () => import_chunk_ANV2HBEH.getTypename,
46
43
  handleAuthChallenge: () => handleAuthChallenge,
47
- protocol: () => import_chunk_ZOL3YSDR.protocol,
48
- toUint8Array: () => import_chunk_ZOL3YSDR.toUint8Array
44
+ protocol: () => import_chunk_ANV2HBEH.protocol,
45
+ toUint8Array: () => import_chunk_ANV2HBEH.toUint8Array
49
46
  });
50
47
  module.exports = __toCommonJS(node_exports);
51
- var import_chunk_ZOL3YSDR = require("./chunk-ZOL3YSDR.cjs");
48
+ var import_chunk_ANV2HBEH = require("./chunk-ANV2HBEH.cjs");
52
49
  __reExport(node_exports, require("@dxos/protocols/buf/dxos/edge/messenger_pb"), module.exports);
53
50
  var import_async = require("@dxos/async");
54
51
  var import_context = require("@dxos/context");
55
52
  var import_log = require("@dxos/log");
56
- var import_services = require("@dxos/protocols/proto/dxos/client/services");
57
53
  var import_invariant = require("@dxos/invariant");
58
54
  var import_proto = require("@dxos/protocols/proto");
59
55
  var import_isomorphic_ws = __toESM(require("isomorphic-ws"));
@@ -61,7 +57,6 @@ var import_async2 = require("@dxos/async");
61
57
  var import_context2 = require("@dxos/context");
62
58
  var import_invariant2 = require("@dxos/invariant");
63
59
  var import_log2 = require("@dxos/log");
64
- var import_protocols = require("@dxos/protocols");
65
60
  var import_buf = require("@dxos/protocols/buf");
66
61
  var import_messenger_pb = require("@dxos/protocols/buf/dxos/edge/messenger_pb");
67
62
  var import_credentials = require("@dxos/credentials");
@@ -71,7 +66,7 @@ var import_keys = require("@dxos/keys");
71
66
  var import_async3 = require("@dxos/async");
72
67
  var import_context3 = require("@dxos/context");
73
68
  var import_log3 = require("@dxos/log");
74
- var import_protocols2 = require("@dxos/protocols");
69
+ var import_protocols = require("@dxos/protocols");
75
70
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-identity.ts";
76
71
  var handleAuthChallenge = async (failedResponse, identity) => {
77
72
  (0, import_invariant.invariant)(failedResponse.status === 401, void 0, {
@@ -117,6 +112,7 @@ function _ts_decorate(decorators, target, key, desc) {
117
112
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-connection.ts";
118
113
  var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
119
114
  var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
115
+ var CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;
120
116
  var EdgeWsConnection = class extends import_context2.Resource {
121
117
  constructor(_identity, _connectionInfo, _callbacks) {
122
118
  super();
@@ -134,73 +130,47 @@ var EdgeWsConnection = class extends import_context2.Resource {
134
130
  send(message) {
135
131
  (0, import_invariant2.invariant)(this._ws, void 0, {
136
132
  F: __dxlog_file2,
137
- L: 52,
133
+ L: 54,
138
134
  S: this,
139
135
  A: [
140
136
  "this._ws",
141
137
  ""
142
138
  ]
143
139
  });
144
- (0, import_invariant2.invariant)(this._wsMuxer, void 0, {
145
- F: __dxlog_file2,
146
- L: 53,
147
- S: this,
148
- A: [
149
- "this._wsMuxer",
150
- ""
151
- ]
152
- });
153
140
  (0, import_log2.log)("sending...", {
154
141
  peerKey: this._identity.peerKey,
155
- payload: import_chunk_ZOL3YSDR.protocol.getPayloadType(message)
142
+ payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
156
143
  }, {
157
144
  F: __dxlog_file2,
158
- L: 54,
145
+ L: 55,
159
146
  S: this,
160
147
  C: (f, a) => f(...a)
161
148
  });
162
- if (this._ws?.protocol.includes(import_protocols.EdgeWebsocketProtocol.V0)) {
163
- const binary = import_buf.buf.toBinary(import_messenger_pb.MessageSchema, message);
164
- if (binary.length > import_chunk_ZOL3YSDR.CLOUDFLARE_MESSAGE_MAX_BYTES) {
165
- import_log2.log.error("Message dropped because it was too large (>1MB).", {
166
- byteLength: binary.byteLength,
167
- serviceId: message.serviceId,
168
- payload: import_chunk_ZOL3YSDR.protocol.getPayloadType(message)
169
- }, {
170
- F: __dxlog_file2,
171
- L: 58,
172
- S: this,
173
- C: (f, a) => f(...a)
174
- });
175
- return;
176
- }
177
- this._ws.send(binary);
178
- } else {
179
- this._wsMuxer.send(message).catch((e) => import_log2.log.catch(e, void 0, {
149
+ const encoded = import_buf.buf.toBinary(import_messenger_pb.MessageSchema, message);
150
+ if (encoded.byteLength >= CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {
151
+ import_log2.log.error("edge message dropped due to websocket message limit", {
152
+ byteLength: encoded.byteLength,
153
+ serviceId: message.serviceId,
154
+ payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
155
+ }, {
180
156
  F: __dxlog_file2,
181
- L: 67,
157
+ L: 58,
182
158
  S: this,
183
159
  C: (f, a) => f(...a)
184
- }));
160
+ });
161
+ return;
185
162
  }
163
+ this._ws.send(encoded);
186
164
  }
187
165
  async _open() {
188
- const baseProtocols = [
189
- ...Object.values(import_protocols.EdgeWebsocketProtocol)
190
- ];
191
166
  this._ws = new import_isomorphic_ws.default(this._connectionInfo.url.toString(), this._connectionInfo.protocolHeader ? [
192
- ...baseProtocols,
193
167
  this._connectionInfo.protocolHeader
194
- ] : [
195
- ...baseProtocols
196
- ]);
197
- const muxer = new import_chunk_ZOL3YSDR.WebSocketMuxer(this._ws);
198
- this._wsMuxer = muxer;
168
+ ] : []);
199
169
  this._ws.onopen = () => {
200
170
  if (this.isOpen) {
201
171
  (0, import_log2.log)("connected", void 0, {
202
172
  F: __dxlog_file2,
203
- L: 84,
173
+ L: 76,
204
174
  S: this,
205
175
  C: (f, a) => f(...a)
206
176
  });
@@ -211,7 +181,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
211
181
  currentIdentity: this._identity
212
182
  }, {
213
183
  F: __dxlog_file2,
214
- L: 88,
184
+ L: 80,
215
185
  S: this,
216
186
  C: (f, a) => f(...a)
217
187
  });
@@ -224,12 +194,11 @@ var EdgeWsConnection = class extends import_context2.Resource {
224
194
  reason: event.reason
225
195
  }, {
226
196
  F: __dxlog_file2,
227
- L: 93,
197
+ L: 85,
228
198
  S: this,
229
199
  C: (f, a) => f(...a)
230
200
  });
231
201
  this._callbacks.onRestartRequired();
232
- muxer.destroy();
233
202
  }
234
203
  };
235
204
  this._ws.onerror = (event) => {
@@ -239,7 +208,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
239
208
  info: event.message
240
209
  }, {
241
210
  F: __dxlog_file2,
242
- L: 100,
211
+ L: 91,
243
212
  S: this,
244
213
  C: (f, a) => f(...a)
245
214
  });
@@ -249,7 +218,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
249
218
  error: event.error
250
219
  }, {
251
220
  F: __dxlog_file2,
252
- L: 103,
221
+ L: 94,
253
222
  S: this,
254
223
  C: (f, a) => f(...a)
255
224
  });
@@ -261,7 +230,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
261
230
  event: event.type
262
231
  }, {
263
232
  F: __dxlog_file2,
264
- L: 111,
233
+ L: 102,
265
234
  S: this,
266
235
  C: (f, a) => f(...a)
267
236
  });
@@ -271,18 +240,15 @@ var EdgeWsConnection = class extends import_context2.Resource {
271
240
  this._rescheduleHeartbeatTimeout();
272
241
  return;
273
242
  }
274
- const bytes = await (0, import_chunk_ZOL3YSDR.toUint8Array)(event.data);
275
- if (!this.isOpen) {
276
- return;
277
- }
278
- const message = this._ws?.protocol?.includes(import_protocols.EdgeWebsocketProtocol.V0) ? import_buf.buf.fromBinary(import_messenger_pb.MessageSchema, bytes) : muxer.receiveData(bytes);
279
- if (message) {
243
+ const data = await (0, import_chunk_ANV2HBEH.toUint8Array)(event.data);
244
+ if (this.isOpen) {
245
+ const message = import_buf.buf.fromBinary(import_messenger_pb.MessageSchema, data);
280
246
  (0, import_log2.log)("received", {
281
247
  from: message.source,
282
- payload: import_chunk_ZOL3YSDR.protocol.getPayloadType(message)
248
+ payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
283
249
  }, {
284
250
  F: __dxlog_file2,
285
- L: 128,
251
+ L: 112,
286
252
  S: this,
287
253
  C: (f, a) => f(...a)
288
254
  });
@@ -296,8 +262,6 @@ var EdgeWsConnection = class extends import_context2.Resource {
296
262
  try {
297
263
  this._ws?.close();
298
264
  this._ws = void 0;
299
- this._wsMuxer?.destroy();
300
- this._wsMuxer = void 0;
301
265
  } catch (err) {
302
266
  if (err instanceof Error && err.message.includes("WebSocket is closed before the connection is established.")) {
303
267
  return;
@@ -306,7 +270,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
306
270
  err
307
271
  }, {
308
272
  F: __dxlog_file2,
309
- L: 146,
273
+ L: 128,
310
274
  S: this,
311
275
  C: (f, a) => f(...a)
312
276
  });
@@ -315,7 +279,7 @@ var EdgeWsConnection = class extends import_context2.Resource {
315
279
  _scheduleHeartbeats() {
316
280
  (0, import_invariant2.invariant)(this._ws, void 0, {
317
281
  F: __dxlog_file2,
318
- L: 151,
282
+ L: 133,
319
283
  S: this,
320
284
  A: [
321
285
  "this._ws",
@@ -335,13 +299,13 @@ var EdgeWsConnection = class extends import_context2.Resource {
335
299
  void this._inactivityTimeoutCtx?.dispose();
336
300
  this._inactivityTimeoutCtx = new import_context2.Context(void 0, {
337
301
  F: __dxlog_file2,
338
- L: 170
302
+ L: 152
339
303
  });
340
304
  (0, import_async2.scheduleTask)(this._inactivityTimeoutCtx, () => {
341
305
  if (this.isOpen) {
342
306
  import_log2.log.warn("restart due to inactivity timeout", void 0, {
343
307
  F: __dxlog_file2,
344
- L: 175,
308
+ L: 157,
345
309
  S: this,
346
310
  C: (f, a) => f(...a)
347
311
  });
@@ -382,7 +346,6 @@ var EdgeClient = class extends import_context.Resource {
382
346
  super();
383
347
  this._identity = _identity;
384
348
  this._config = _config;
385
- this.statusChanged = new import_async.Event();
386
349
  this._persistentLifecycle = new import_async.PersistentLifecycle({
387
350
  start: async () => this._connect(),
388
351
  stop: async (state) => this._disconnect(state)
@@ -398,13 +361,12 @@ var EdgeClient = class extends import_context.Resource {
398
361
  get info() {
399
362
  return {
400
363
  open: this.isOpen,
401
- status: this.status,
402
364
  identity: this._identity.identityKey,
403
365
  device: this._identity.peerKey
404
366
  };
405
367
  }
406
- get status() {
407
- return Boolean(this._currentConnection) && this._ready.state === import_async.TriggerState.RESOLVED ? import_services.EdgeStatus.CONNECTED : import_services.EdgeStatus.NOT_CONNECTED;
368
+ get isConnected() {
369
+ return Boolean(this._currentConnection) && this._ready.state === import_async.TriggerState.RESOLVED;
408
370
  }
409
371
  get identityKey() {
410
372
  return this._identity.identityKey;
@@ -419,13 +381,13 @@ var EdgeClient = class extends import_context.Resource {
419
381
  oldIdentity: this._identity
420
382
  }, {
421
383
  F: __dxlog_file3,
422
- L: 99,
384
+ L: 94,
423
385
  S: this,
424
386
  C: (f, a) => f(...a)
425
387
  });
426
388
  this._identity = identity;
427
389
  this._closeCurrentConnection(new EdgeIdentityChangedError());
428
- void this._persistentLifecycle.scheduleRestart();
390
+ this._persistentLifecycle.scheduleRestart();
429
391
  }
430
392
  }
431
393
  onMessage(listener) {
@@ -442,7 +404,7 @@ var EdgeClient = class extends import_context.Resource {
442
404
  } catch (error) {
443
405
  import_log.log.catch(error, void 0, {
444
406
  F: __dxlog_file3,
445
- L: 121,
407
+ L: 116,
446
408
  S: this,
447
409
  C: (f, a) => f(...a)
448
410
  });
@@ -460,7 +422,7 @@ var EdgeClient = class extends import_context.Resource {
460
422
  info: this.info
461
423
  }, {
462
424
  F: __dxlog_file3,
463
- L: 133,
425
+ L: 128,
464
426
  S: this,
465
427
  C: (f, a) => f(...a)
466
428
  });
@@ -469,7 +431,7 @@ var EdgeClient = class extends import_context.Resource {
469
431
  err
470
432
  }, {
471
433
  F: __dxlog_file3,
472
- L: 135,
434
+ L: 130,
473
435
  S: this,
474
436
  C: (f, a) => f(...a)
475
437
  });
@@ -483,7 +445,7 @@ var EdgeClient = class extends import_context.Resource {
483
445
  peerKey: this._identity.peerKey
484
446
  }, {
485
447
  F: __dxlog_file3,
486
- L: 143,
448
+ L: 138,
487
449
  S: this,
488
450
  C: (f, a) => f(...a)
489
451
  });
@@ -500,7 +462,7 @@ var EdgeClient = class extends import_context.Resource {
500
462
  if (this._identity !== identity) {
501
463
  (0, import_log.log)("identity changed during auth header request", void 0, {
502
464
  F: __dxlog_file3,
503
- L: 157,
465
+ L: 152,
504
466
  S: this,
505
467
  C: (f, a) => f(...a)
506
468
  });
@@ -513,7 +475,7 @@ var EdgeClient = class extends import_context.Resource {
513
475
  protocolHeader
514
476
  }, {
515
477
  F: __dxlog_file3,
516
- L: 163,
478
+ L: 158,
517
479
  S: this,
518
480
  C: (f, a) => f(...a)
519
481
  });
@@ -528,7 +490,7 @@ var EdgeClient = class extends import_context.Resource {
528
490
  } else {
529
491
  import_log.log.verbose("connected callback ignored, because connection is not active", void 0, {
530
492
  F: __dxlog_file3,
531
- L: 173,
493
+ L: 168,
532
494
  S: this,
533
495
  C: (f, a) => f(...a)
534
496
  });
@@ -537,11 +499,11 @@ var EdgeClient = class extends import_context.Resource {
537
499
  onRestartRequired: () => {
538
500
  if (this._isActive(connection)) {
539
501
  this._closeCurrentConnection();
540
- void this._persistentLifecycle.scheduleRestart();
502
+ this._persistentLifecycle.scheduleRestart();
541
503
  } else {
542
504
  import_log.log.verbose("restart requested by inactive connection", void 0, {
543
505
  F: __dxlog_file3,
544
- L: 181,
506
+ L: 176,
545
507
  S: this,
546
508
  C: (f, a) => f(...a)
547
509
  });
@@ -557,7 +519,7 @@ var EdgeClient = class extends import_context.Resource {
557
519
  type: message.payload?.typeUrl
558
520
  }, {
559
521
  F: __dxlog_file3,
560
- L: 189,
522
+ L: 184,
561
523
  S: this,
562
524
  C: (f, a) => f(...a)
563
525
  });
@@ -576,16 +538,13 @@ var EdgeClient = class extends import_context.Resource {
576
538
  }
577
539
  async _disconnect(state) {
578
540
  await state.close();
579
- this.statusChanged.emit(this.status);
580
541
  }
581
542
  _closeCurrentConnection(error = new EdgeConnectionClosedError()) {
582
543
  this._currentConnection = void 0;
583
544
  this._ready.throw(error);
584
545
  this._ready.reset();
585
- this.statusChanged.emit(this.status);
586
546
  }
587
547
  _notifyReconnected() {
588
- this.statusChanged.emit(this.status);
589
548
  for (const listener of this._reconnectListeners) {
590
549
  try {
591
550
  listener();
@@ -594,7 +553,7 @@ var EdgeClient = class extends import_context.Resource {
594
553
  err
595
554
  }, {
596
555
  F: __dxlog_file3,
597
- L: 225,
556
+ L: 217,
598
557
  S: this,
599
558
  C: (f, a) => f(...a)
600
559
  });
@@ -608,10 +567,10 @@ var EdgeClient = class extends import_context.Resource {
608
567
  } catch (err) {
609
568
  import_log.log.error("ws incoming message processing failed", {
610
569
  err,
611
- payload: import_chunk_ZOL3YSDR.protocol.getPayloadType(message)
570
+ payload: import_chunk_ANV2HBEH.protocol.getPayloadType(message)
612
571
  }, {
613
572
  F: __dxlog_file3,
614
- L: 235,
573
+ L: 227,
615
574
  S: this,
616
575
  C: (f, a) => f(...a)
617
576
  });
@@ -626,7 +585,7 @@ var EdgeClient = class extends import_context.Resource {
626
585
  if (this._ready.state !== import_async.TriggerState.RESOLVED) {
627
586
  (0, import_log.log)("waiting for websocket to become ready", void 0, {
628
587
  F: __dxlog_file3,
629
- L: 246,
588
+ L: 238,
630
589
  S: this,
631
590
  C: (f, a) => f(...a)
632
591
  });
@@ -656,7 +615,7 @@ var EdgeClient = class extends import_context.Resource {
656
615
  statusText: response.statusText
657
616
  }, {
658
617
  F: __dxlog_file3,
659
- L: 271,
618
+ L: 263,
660
619
  S: this,
661
620
  C: (f, a) => f(...a)
662
621
  });
@@ -851,6 +810,7 @@ var EdgeHttpClient = class {
851
810
  async uploadFunction(pathParts, body, args) {
852
811
  const path = [
853
812
  "functions",
813
+ pathParts.spaceId,
854
814
  ...pathParts.functionId ? [
855
815
  pathParts.functionId
856
816
  ] : []
@@ -964,19 +924,19 @@ var EdgeHttpClient = class {
964
924
  C: (f, a) => f(...a)
965
925
  });
966
926
  if (body.errorData?.type === "auth_challenge" && typeof body.errorData?.challenge === "string") {
967
- processingError = new import_protocols2.EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
927
+ processingError = new import_protocols.EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
968
928
  } else {
969
- processingError = import_protocols2.EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
929
+ processingError = import_protocols.EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
970
930
  }
971
931
  } else if (response.status === 401 && !handledAuth) {
972
932
  authHeader = await this._handleUnauthorized(response);
973
933
  handledAuth = true;
974
934
  continue;
975
935
  } else {
976
- processingError = import_protocols2.EdgeCallFailedError.fromHttpFailure(response);
936
+ processingError = import_protocols.EdgeCallFailedError.fromHttpFailure(response);
977
937
  }
978
938
  } catch (error) {
979
- processingError = import_protocols2.EdgeCallFailedError.fromProcessingFailureCause(error);
939
+ processingError = import_protocols.EdgeCallFailedError.fromProcessingFailureCause(error);
980
940
  }
981
941
  if (processingError.isRetryable && await shouldRetry(requestContext, retryAfterHeaderValue)) {
982
942
  (0, import_log3.log)("retrying edge request", {
@@ -1001,7 +961,7 @@ var EdgeHttpClient = class {
1001
961
  S: this,
1002
962
  C: (f, a) => f(...a)
1003
963
  });
1004
- throw import_protocols2.EdgeCallFailedError.fromHttpFailure(response);
964
+ throw import_protocols.EdgeCallFailedError.fromHttpFailure(response);
1005
965
  }
1006
966
  const challenge = await handleAuthChallenge(response, this._edgeIdentity);
1007
967
  this._authHeader = encodeAuthHeader(challenge);
@@ -1050,14 +1010,11 @@ var encodeAuthHeader = (challenge) => {
1050
1010
  };
1051
1011
  // Annotate the CommonJS export names for ESM import in node:
1052
1012
  0 && (module.exports = {
1053
- CLOUDFLARE_MESSAGE_MAX_BYTES,
1054
- CLOUDFLARE_RPC_MAX_BYTES,
1055
1013
  EdgeClient,
1056
1014
  EdgeConnectionClosedError,
1057
1015
  EdgeHttpClient,
1058
1016
  EdgeIdentityChangedError,
1059
1017
  Protocol,
1060
- WebSocketMuxer,
1061
1018
  createChainEdgeIdentity,
1062
1019
  createDeviceEdgeIdentity,
1063
1020
  createEphemeralEdgeIdentity,