@dxos/edge-client 0.8.4-main.f9ba587 → 0.8.4-main.fd6878d
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-LMP5TVOP.mjs → chunk-SUXH7FH6.mjs} +8 -1
- package/dist/lib/browser/{chunk-LMP5TVOP.mjs.map → chunk-SUXH7FH6.mjs.map} +3 -3
- package/dist/lib/browser/edge-ws-muxer.mjs +1 -1
- package/dist/lib/browser/index.mjs +72 -37
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node-esm/{chunk-X7J46ISZ.mjs → chunk-R6K4IIBW.mjs} +8 -1
- package/dist/lib/node-esm/{chunk-X7J46ISZ.mjs.map → chunk-R6K4IIBW.mjs.map} +3 -3
- package/dist/lib/node-esm/edge-ws-muxer.mjs +1 -1
- package/dist/lib/node-esm/index.mjs +72 -37
- 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 +1 -1
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/types/src/edge-client.d.ts +1 -1
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-http-client.d.ts +2 -1
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/edge-ws-connection.d.ts +1 -0
- package/dist/types/src/edge-ws-connection.d.ts.map +1 -1
- package/dist/types/src/edge-ws-muxer.d.ts.map +1 -1
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -15
- package/src/edge-client.ts +2 -2
- package/src/edge-http-client.ts +10 -6
- package/src/edge-ws-connection.ts +11 -3
- package/src/edge-ws-muxer.ts +1 -1
- package/src/http-client.test.ts +0 -1
- package/src/testing/test-utils.ts +1 -1
- package/src/websocket.test.ts +1 -1
|
@@ -16,6 +16,7 @@ import { bufferToArray } from "@dxos/util";
|
|
|
16
16
|
var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/protocol.ts";
|
|
17
17
|
var getTypename = (typeName) => `type.googleapis.com/${typeName}`;
|
|
18
18
|
var Protocol = class {
|
|
19
|
+
_typeRegistry;
|
|
19
20
|
constructor(types) {
|
|
20
21
|
this._typeRegistry = buf.createRegistry(...types);
|
|
21
22
|
}
|
|
@@ -122,6 +123,12 @@ var MAX_CHUNK_LENGTH = 16384;
|
|
|
122
123
|
var MAX_BUFFERED_AMOUNT = CLOUDFLARE_MESSAGE_MAX_BYTES;
|
|
123
124
|
var BUFFER_FULL_BACKOFF_TIMEOUT = 100;
|
|
124
125
|
var WebSocketMuxer = class {
|
|
126
|
+
_ws;
|
|
127
|
+
_inMessageAccumulator;
|
|
128
|
+
_outMessageChunks;
|
|
129
|
+
_outMessageChannelByService;
|
|
130
|
+
_sendTimeout;
|
|
131
|
+
_maxChunkLength;
|
|
125
132
|
constructor(_ws, config) {
|
|
126
133
|
this._ws = _ws;
|
|
127
134
|
this._inMessageAccumulator = /* @__PURE__ */ new Map();
|
|
@@ -294,4 +301,4 @@ export {
|
|
|
294
301
|
CLOUDFLARE_RPC_MAX_BYTES,
|
|
295
302
|
WebSocketMuxer
|
|
296
303
|
};
|
|
297
|
-
//# sourceMappingURL=chunk-
|
|
304
|
+
//# sourceMappingURL=chunk-SUXH7FH6.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/edge-ws-muxer.ts", "../../../src/defs.ts", "../../../src/protocol.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Trigger } from '@dxos/async';\nimport { log } from '@dxos/log';\nimport { buf } from '@dxos/protocols/buf';\nimport { MessageSchema, type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nimport { protocol } from './defs';\n\n/**\n * 0000 0001 - message contains a part of segmented message chunk sequence.\n * The next byte defines a channel id and the rest of the message contains a part of Message proto binary.\n * Messages from different channels might interleave.\n * When the flag is NOT set the rest of the message should be interpreted as the valid Message proto binary.\n */\nconst FLAG_SEGMENT_SEQ = 1;\n/**\n * 0000 0010 - message terminates a segmented message chunk sequence.\n * All the chunks accumulated for the channel specified by the second byte can be concatenated\n * and interpreted as a valid Message proto binary.\n */\nconst FLAG_SEGMENT_SEQ_TERMINATED = 1 << 1;\n\n/**\n * https://developers.cloudflare.com/durable-objects/platform/limits/\n */\nexport const CLOUDFLARE_MESSAGE_MAX_BYTES = 1000 * 1000; // 1MB\nexport const CLOUDFLARE_RPC_MAX_BYTES = 32 * 1000 * 1000; // 32MB\n\nconst MAX_CHUNK_LENGTH = 16384;\nconst MAX_BUFFERED_AMOUNT = CLOUDFLARE_MESSAGE_MAX_BYTES;\nconst BUFFER_FULL_BACKOFF_TIMEOUT = 100;\n\nexport class WebSocketMuxer {\n private readonly _inMessageAccumulator = new Map<number, Buffer[]>();\n private readonly _outMessageChunks = new Map<number, MessageChunk[]>();\n private readonly _outMessageChannelByService = new Map<string, number>();\n\n private _sendTimeout: any | undefined;\n\n private readonly _maxChunkLength: number;\n\n constructor(\n private readonly _ws: WebSocketCompat,\n config?: { maxChunkLength: number },\n ) {\n this._maxChunkLength = config?.maxChunkLength ?? MAX_CHUNK_LENGTH;\n }\n\n /**\n * Resolves when all the message chunks get enqueued for sending.\n */\n public async send(message: Message): Promise<void> {\n const binary = buf.toBinary(MessageSchema, message);\n const channelId = this._resolveChannel(message);\n if (\n (channelId == null && binary.byteLength > CLOUDFLARE_MESSAGE_MAX_BYTES) ||\n binary.byteLength > CLOUDFLARE_RPC_MAX_BYTES\n ) {\n log.error('Large message dropped', {\n byteLength: binary.byteLength,\n serviceId: message.serviceId,\n payload: protocol.getPayloadType(message),\n channelId,\n });\n return;\n }\n\n if (channelId == null || binary.length < this._maxChunkLength) {\n const flags = Buffer.from([0]);\n this._ws.send(Buffer.concat([flags, binary]));\n return;\n }\n\n const terminatorSentTrigger = new Trigger();\n const messageChunks: MessageChunk[] = [];\n for (let i = 0; i < binary.length; i += this._maxChunkLength) {\n const chunk = binary.slice(i, i + this._maxChunkLength);\n const isLastChunk = i + this._maxChunkLength >= binary.length;\n if (isLastChunk) {\n const flags = Buffer.from([FLAG_SEGMENT_SEQ | FLAG_SEGMENT_SEQ_TERMINATED, channelId]);\n messageChunks.push({ payload: Buffer.concat([flags, chunk]), trigger: terminatorSentTrigger });\n } else {\n const flags = Buffer.from([FLAG_SEGMENT_SEQ, channelId]);\n messageChunks.push({ payload: Buffer.concat([flags, chunk]) });\n }\n }\n\n const queuedMessages = this._outMessageChunks.get(channelId);\n if (queuedMessages) {\n queuedMessages.push(...messageChunks);\n } else {\n this._outMessageChunks.set(channelId, messageChunks);\n }\n\n this._sendChunkedMessages();\n\n return terminatorSentTrigger.wait();\n }\n\n public receiveData(data: Uint8Array): Message | undefined {\n if ((data[0] & FLAG_SEGMENT_SEQ) === 0) {\n return buf.fromBinary(MessageSchema, data.slice(1));\n }\n\n const [flags, channelId, ...payload] = data;\n let chunkAccumulator = this._inMessageAccumulator.get(channelId);\n if (chunkAccumulator) {\n chunkAccumulator.push(Buffer.from(payload));\n } else {\n chunkAccumulator = [Buffer.from(payload)];\n this._inMessageAccumulator.set(channelId, chunkAccumulator);\n }\n\n if ((flags & FLAG_SEGMENT_SEQ_TERMINATED) === 0) {\n return undefined;\n }\n\n const message = buf.fromBinary(MessageSchema, Buffer.concat(chunkAccumulator));\n this._inMessageAccumulator.delete(channelId);\n return message;\n }\n\n public destroy(): void {\n if (this._sendTimeout) {\n clearTimeout(this._sendTimeout);\n this._sendTimeout = undefined;\n }\n for (const channelChunks of this._outMessageChunks.values()) {\n channelChunks.forEach((chunk) => chunk.trigger?.wake());\n }\n this._outMessageChunks.clear();\n this._inMessageAccumulator.clear();\n this._outMessageChannelByService.clear();\n }\n\n private _sendChunkedMessages(): void {\n if (this._sendTimeout) {\n return;\n }\n\n const send = () => {\n if (this._ws.readyState === WebSocket.CLOSING || this._ws.readyState === WebSocket.CLOSED) {\n log.warn('send called for closed websocket');\n this._sendTimeout = undefined;\n return;\n }\n\n let timeout = 0;\n const emptyChannels: number[] = [];\n for (const [channelId, messages] of this._outMessageChunks.entries()) {\n if (this._ws.bufferedAmount != null) {\n if (this._ws.bufferedAmount + MAX_CHUNK_LENGTH > MAX_BUFFERED_AMOUNT) {\n timeout = BUFFER_FULL_BACKOFF_TIMEOUT;\n break;\n }\n }\n\n const nextMessage = messages.shift();\n if (nextMessage) {\n this._ws.send(nextMessage.payload);\n nextMessage.trigger?.wake();\n } else {\n emptyChannels.push(channelId);\n }\n }\n\n emptyChannels.forEach((channelId) => this._outMessageChunks.delete(channelId));\n\n if (this._outMessageChunks.size > 0) {\n this._sendTimeout = setTimeout(send, timeout);\n } else {\n this._sendTimeout = undefined;\n }\n };\n this._sendTimeout = setTimeout(send);\n }\n\n private _resolveChannel(message: Message): number | undefined {\n if (!message.serviceId) {\n return undefined;\n }\n let id = this._outMessageChannelByService.get(message.serviceId);\n if (!id) {\n id = this._outMessageChannelByService.size + 1;\n this._outMessageChannelByService.set(message.serviceId, id);\n }\n return id;\n }\n}\n\ntype WebSocketCompat = {\n readonly readyState: number;\n /**\n * Not available in workerd.\n */\n bufferedAmount?: number;\n send(message: (ArrayBuffer | ArrayBufferView) | string): void;\n};\n\ntype MessageChunk = {\n payload: Buffer;\n /**\n * Wakes when the payload is enqueued by WebSocket.\n */\n trigger?: Trigger;\n};\n\n/**\n * To avoid using isomorphic-ws on edge.\n */\nenum WebSocket {\n CLOSING = 2,\n CLOSED = 3,\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", "//\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 ): Message {\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"],
|
|
5
|
-
"mappings": ";AAIA,SAASA,eAAe;AACxB,SAASC,WAAW;AACpB,SAASC,OAAAA,YAAW;AACpB,
|
|
6
|
-
"names": ["Trigger", "log", "buf", "MessageSchema", "bufWkt", "SwarmRequestSchema", "SwarmResponseSchema", "TextMessageSchema", "invariant", "buf", "bufWkt", "MessageSchema", "bufferToArray", "getTypename", "typeName", "Protocol", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Trigger } from '@dxos/async';\nimport { log } from '@dxos/log';\nimport { buf } from '@dxos/protocols/buf';\nimport { type Message, MessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';\n\nimport { protocol } from './defs';\n\n/**\n * 0000 0001 - message contains a part of segmented message chunk sequence.\n * The next byte defines a channel id and the rest of the message contains a part of Message proto binary.\n * Messages from different channels might interleave.\n * When the flag is NOT set the rest of the message should be interpreted as the valid Message proto binary.\n */\nconst FLAG_SEGMENT_SEQ = 1;\n/**\n * 0000 0010 - message terminates a segmented message chunk sequence.\n * All the chunks accumulated for the channel specified by the second byte can be concatenated\n * and interpreted as a valid Message proto binary.\n */\nconst FLAG_SEGMENT_SEQ_TERMINATED = 1 << 1;\n\n/**\n * https://developers.cloudflare.com/durable-objects/platform/limits/\n */\nexport const CLOUDFLARE_MESSAGE_MAX_BYTES = 1000 * 1000; // 1MB\nexport const CLOUDFLARE_RPC_MAX_BYTES = 32 * 1000 * 1000; // 32MB\n\nconst MAX_CHUNK_LENGTH = 16384;\nconst MAX_BUFFERED_AMOUNT = CLOUDFLARE_MESSAGE_MAX_BYTES;\nconst BUFFER_FULL_BACKOFF_TIMEOUT = 100;\n\nexport class WebSocketMuxer {\n private readonly _inMessageAccumulator = new Map<number, Buffer[]>();\n private readonly _outMessageChunks = new Map<number, MessageChunk[]>();\n private readonly _outMessageChannelByService = new Map<string, number>();\n\n private _sendTimeout: any | undefined;\n\n private readonly _maxChunkLength: number;\n\n constructor(\n private readonly _ws: WebSocketCompat,\n config?: { maxChunkLength: number },\n ) {\n this._maxChunkLength = config?.maxChunkLength ?? MAX_CHUNK_LENGTH;\n }\n\n /**\n * Resolves when all the message chunks get enqueued for sending.\n */\n public async send(message: Message): Promise<void> {\n const binary = buf.toBinary(MessageSchema, message);\n const channelId = this._resolveChannel(message);\n if (\n (channelId == null && binary.byteLength > CLOUDFLARE_MESSAGE_MAX_BYTES) ||\n binary.byteLength > CLOUDFLARE_RPC_MAX_BYTES\n ) {\n log.error('Large message dropped', {\n byteLength: binary.byteLength,\n serviceId: message.serviceId,\n payload: protocol.getPayloadType(message),\n channelId,\n });\n return;\n }\n\n if (channelId == null || binary.length < this._maxChunkLength) {\n const flags = Buffer.from([0]);\n this._ws.send(Buffer.concat([flags, binary]));\n return;\n }\n\n const terminatorSentTrigger = new Trigger();\n const messageChunks: MessageChunk[] = [];\n for (let i = 0; i < binary.length; i += this._maxChunkLength) {\n const chunk = binary.slice(i, i + this._maxChunkLength);\n const isLastChunk = i + this._maxChunkLength >= binary.length;\n if (isLastChunk) {\n const flags = Buffer.from([FLAG_SEGMENT_SEQ | FLAG_SEGMENT_SEQ_TERMINATED, channelId]);\n messageChunks.push({ payload: Buffer.concat([flags, chunk]), trigger: terminatorSentTrigger });\n } else {\n const flags = Buffer.from([FLAG_SEGMENT_SEQ, channelId]);\n messageChunks.push({ payload: Buffer.concat([flags, chunk]) });\n }\n }\n\n const queuedMessages = this._outMessageChunks.get(channelId);\n if (queuedMessages) {\n queuedMessages.push(...messageChunks);\n } else {\n this._outMessageChunks.set(channelId, messageChunks);\n }\n\n this._sendChunkedMessages();\n\n return terminatorSentTrigger.wait();\n }\n\n public receiveData(data: Uint8Array): Message | undefined {\n if ((data[0] & FLAG_SEGMENT_SEQ) === 0) {\n return buf.fromBinary(MessageSchema, data.slice(1));\n }\n\n const [flags, channelId, ...payload] = data;\n let chunkAccumulator = this._inMessageAccumulator.get(channelId);\n if (chunkAccumulator) {\n chunkAccumulator.push(Buffer.from(payload));\n } else {\n chunkAccumulator = [Buffer.from(payload)];\n this._inMessageAccumulator.set(channelId, chunkAccumulator);\n }\n\n if ((flags & FLAG_SEGMENT_SEQ_TERMINATED) === 0) {\n return undefined;\n }\n\n const message = buf.fromBinary(MessageSchema, Buffer.concat(chunkAccumulator));\n this._inMessageAccumulator.delete(channelId);\n return message;\n }\n\n public destroy(): void {\n if (this._sendTimeout) {\n clearTimeout(this._sendTimeout);\n this._sendTimeout = undefined;\n }\n for (const channelChunks of this._outMessageChunks.values()) {\n channelChunks.forEach((chunk) => chunk.trigger?.wake());\n }\n this._outMessageChunks.clear();\n this._inMessageAccumulator.clear();\n this._outMessageChannelByService.clear();\n }\n\n private _sendChunkedMessages(): void {\n if (this._sendTimeout) {\n return;\n }\n\n const send = () => {\n if (this._ws.readyState === WebSocket.CLOSING || this._ws.readyState === WebSocket.CLOSED) {\n log.warn('send called for closed websocket');\n this._sendTimeout = undefined;\n return;\n }\n\n let timeout = 0;\n const emptyChannels: number[] = [];\n for (const [channelId, messages] of this._outMessageChunks.entries()) {\n if (this._ws.bufferedAmount != null) {\n if (this._ws.bufferedAmount + MAX_CHUNK_LENGTH > MAX_BUFFERED_AMOUNT) {\n timeout = BUFFER_FULL_BACKOFF_TIMEOUT;\n break;\n }\n }\n\n const nextMessage = messages.shift();\n if (nextMessage) {\n this._ws.send(nextMessage.payload);\n nextMessage.trigger?.wake();\n } else {\n emptyChannels.push(channelId);\n }\n }\n\n emptyChannels.forEach((channelId) => this._outMessageChunks.delete(channelId));\n\n if (this._outMessageChunks.size > 0) {\n this._sendTimeout = setTimeout(send, timeout);\n } else {\n this._sendTimeout = undefined;\n }\n };\n this._sendTimeout = setTimeout(send);\n }\n\n private _resolveChannel(message: Message): number | undefined {\n if (!message.serviceId) {\n return undefined;\n }\n let id = this._outMessageChannelByService.get(message.serviceId);\n if (!id) {\n id = this._outMessageChannelByService.size + 1;\n this._outMessageChannelByService.set(message.serviceId, id);\n }\n return id;\n }\n}\n\ntype WebSocketCompat = {\n readonly readyState: number;\n /**\n * Not available in workerd.\n */\n bufferedAmount?: number;\n send(message: (ArrayBuffer | ArrayBufferView) | string): void;\n};\n\ntype MessageChunk = {\n payload: Buffer;\n /**\n * Wakes when the payload is enqueued by WebSocket.\n */\n trigger?: Trigger;\n};\n\n/**\n * To avoid using isomorphic-ws on edge.\n */\nenum WebSocket {\n CLOSING = 2,\n CLOSED = 3,\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", "//\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 ): Message {\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"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,eAAe;AACxB,SAASC,WAAW;AACpB,SAASC,OAAAA,YAAW;AACpB,SAA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,GAAI;AACpE,YAAI,KAAKxD,IAAIyD,kBAAkB,MAAM;AACnC,cAAI,KAAKzD,IAAIyD,iBAAiBlE,mBAAmBC,qBAAqB;AACpE6D,sBAAU5D;AACV;UACF;QACF;AAEA,cAAMiE,cAAcH,SAASI,MAAK;AAClC,YAAID,aAAa;AACf,eAAK1D,IAAII,KAAKsD,YAAY1C,OAAO;AACjC0C,sBAAY1B,SAASiB,KAAAA;QACvB,OAAO;AACLK,wBAAcvB,KAAKrB,SAAAA;QACrB;MACF;AAEA4C,oBAAcN,QAAQ,CAACtC,cAAc,KAAKd,kBAAkB+C,OAAOjC,SAAAA,CAAAA;AAEnE,UAAI,KAAKd,kBAAkBgE,OAAO,GAAG;AACnC,aAAK9D,eAAe+D,WAAWzD,MAAMiD,OAAAA;MACvC,OAAO;AACL,aAAKvD,eAAe4C;MACtB;IACF;AACA,SAAK5C,eAAe+D,WAAWzD,IAAAA;EACjC;EAEQO,gBAAgBN,SAAsC;AAC5D,QAAI,CAACA,QAAQU,WAAW;AACtB,aAAO2B;IACT;AACA,QAAIoB,KAAK,KAAKjE,4BAA4BqC,IAAI7B,QAAQU,SAAS;AAC/D,QAAI,CAAC+C,IAAI;AACPA,WAAK,KAAKjE,4BAA4B+D,OAAO;AAC7C,WAAK/D,4BAA4BsC,IAAI9B,QAAQU,WAAW+C,EAAAA;IAC1D;AACA,WAAOA;EACT;AACF;",
|
|
6
|
+
"names": ["Trigger", "log", "buf", "MessageSchema", "bufWkt", "SwarmRequestSchema", "SwarmResponseSchema", "TextMessageSchema", "invariant", "buf", "bufWkt", "MessageSchema", "bufferToArray", "getTypename", "typeName", "Protocol", "_typeRegistry", "types", "createRegistry", "typeRegistry", "toJson", "message", "registry", "err", "type", "getPayloadType", "getPayload", "payload", "payloadTypename", "Error", "anyIs", "anyUnpack", "undefined", "typeUrl", "split", "createMessage", "source", "target", "serviceId", "create", "timestamp", "Date", "toISOString", "anyPack", "toUint8Array", "data", "Buffer", "Blob", "Uint8Array", "arrayBuffer", "protocol", "Protocol", "SwarmRequestSchema", "SwarmResponseSchema", "TextMessageSchema", "bufWkt", "AnySchema", "FLAG_SEGMENT_SEQ", "FLAG_SEGMENT_SEQ_TERMINATED", "CLOUDFLARE_MESSAGE_MAX_BYTES", "CLOUDFLARE_RPC_MAX_BYTES", "MAX_CHUNK_LENGTH", "MAX_BUFFERED_AMOUNT", "BUFFER_FULL_BACKOFF_TIMEOUT", "WebSocketMuxer", "_inMessageAccumulator", "_outMessageChunks", "_outMessageChannelByService", "_sendTimeout", "_maxChunkLength", "_ws", "config", "Map", "maxChunkLength", "send", "message", "binary", "buf", "toBinary", "MessageSchema", "channelId", "_resolveChannel", "byteLength", "log", "error", "serviceId", "payload", "protocol", "getPayloadType", "length", "flags", "Buffer", "from", "concat", "terminatorSentTrigger", "Trigger", "messageChunks", "i", "chunk", "slice", "isLastChunk", "push", "trigger", "queuedMessages", "get", "set", "_sendChunkedMessages", "wait", "receiveData", "data", "fromBinary", "chunkAccumulator", "undefined", "delete", "destroy", "clearTimeout", "channelChunks", "values", "forEach", "wake", "clear", "readyState", "warn", "timeout", "emptyChannels", "messages", "entries", "bufferedAmount", "nextMessage", "shift", "size", "setTimeout", "id"]
|
|
7
7
|
}
|
|
@@ -6,13 +6,13 @@ import {
|
|
|
6
6
|
getTypename,
|
|
7
7
|
protocol,
|
|
8
8
|
toUint8Array
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-SUXH7FH6.mjs";
|
|
10
10
|
|
|
11
11
|
// src/index.ts
|
|
12
12
|
export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
|
|
13
13
|
|
|
14
14
|
// src/edge-client.ts
|
|
15
|
-
import {
|
|
15
|
+
import { Event, PersistentLifecycle, Trigger, TriggerState, scheduleMicroTask } from "@dxos/async";
|
|
16
16
|
import { Resource as Resource2 } from "@dxos/context";
|
|
17
17
|
import { log as log2, logInfo as logInfo2 } from "@dxos/log";
|
|
18
18
|
import { EdgeStatus } from "@dxos/protocols/proto/dxos/client/services";
|
|
@@ -76,8 +76,15 @@ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-c
|
|
|
76
76
|
var SIGNAL_KEEPALIVE_INTERVAL = 4e3;
|
|
77
77
|
var SIGNAL_KEEPALIVE_TIMEOUT = 12e3;
|
|
78
78
|
var EdgeWsConnection = class extends Resource {
|
|
79
|
+
_identity;
|
|
80
|
+
_connectionInfo;
|
|
81
|
+
_callbacks;
|
|
82
|
+
_inactivityTimeoutCtx;
|
|
83
|
+
_ws;
|
|
84
|
+
_wsMuxer;
|
|
85
|
+
_lastReceivedMessageTimestamp;
|
|
79
86
|
constructor(_identity, _connectionInfo, _callbacks) {
|
|
80
|
-
super(), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks;
|
|
87
|
+
super(), this._identity = _identity, this._connectionInfo = _connectionInfo, this._callbacks = _callbacks, this._lastReceivedMessageTimestamp = Date.now();
|
|
81
88
|
}
|
|
82
89
|
get info() {
|
|
83
90
|
return {
|
|
@@ -89,7 +96,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
89
96
|
send(message) {
|
|
90
97
|
invariant2(this._ws, void 0, {
|
|
91
98
|
F: __dxlog_file2,
|
|
92
|
-
L:
|
|
99
|
+
L: 53,
|
|
93
100
|
S: this,
|
|
94
101
|
A: [
|
|
95
102
|
"this._ws",
|
|
@@ -98,7 +105,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
98
105
|
});
|
|
99
106
|
invariant2(this._wsMuxer, void 0, {
|
|
100
107
|
F: __dxlog_file2,
|
|
101
|
-
L:
|
|
108
|
+
L: 54,
|
|
102
109
|
S: this,
|
|
103
110
|
A: [
|
|
104
111
|
"this._wsMuxer",
|
|
@@ -110,7 +117,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
110
117
|
payload: protocol.getPayloadType(message)
|
|
111
118
|
}, {
|
|
112
119
|
F: __dxlog_file2,
|
|
113
|
-
L:
|
|
120
|
+
L: 55,
|
|
114
121
|
S: this,
|
|
115
122
|
C: (f, a) => f(...a)
|
|
116
123
|
});
|
|
@@ -123,7 +130,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
123
130
|
payload: protocol.getPayloadType(message)
|
|
124
131
|
}, {
|
|
125
132
|
F: __dxlog_file2,
|
|
126
|
-
L:
|
|
133
|
+
L: 59,
|
|
127
134
|
S: this,
|
|
128
135
|
C: (f, a) => f(...a)
|
|
129
136
|
});
|
|
@@ -133,7 +140,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
133
140
|
} else {
|
|
134
141
|
this._wsMuxer.send(message).catch((e) => log.catch(e, void 0, {
|
|
135
142
|
F: __dxlog_file2,
|
|
136
|
-
L:
|
|
143
|
+
L: 68,
|
|
137
144
|
S: this,
|
|
138
145
|
C: (f, a) => f(...a)
|
|
139
146
|
}));
|
|
@@ -155,7 +162,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
155
162
|
if (this.isOpen) {
|
|
156
163
|
log("connected", void 0, {
|
|
157
164
|
F: __dxlog_file2,
|
|
158
|
-
L:
|
|
165
|
+
L: 85,
|
|
159
166
|
S: this,
|
|
160
167
|
C: (f, a) => f(...a)
|
|
161
168
|
});
|
|
@@ -166,7 +173,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
166
173
|
currentIdentity: this._identity
|
|
167
174
|
}, {
|
|
168
175
|
F: __dxlog_file2,
|
|
169
|
-
L:
|
|
176
|
+
L: 89,
|
|
170
177
|
S: this,
|
|
171
178
|
C: (f, a) => f(...a)
|
|
172
179
|
});
|
|
@@ -179,7 +186,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
179
186
|
reason: event.reason
|
|
180
187
|
}, {
|
|
181
188
|
F: __dxlog_file2,
|
|
182
|
-
L:
|
|
189
|
+
L: 94,
|
|
183
190
|
S: this,
|
|
184
191
|
C: (f, a) => f(...a)
|
|
185
192
|
});
|
|
@@ -194,7 +201,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
194
201
|
info: event.message
|
|
195
202
|
}, {
|
|
196
203
|
F: __dxlog_file2,
|
|
197
|
-
L:
|
|
204
|
+
L: 101,
|
|
198
205
|
S: this,
|
|
199
206
|
C: (f, a) => f(...a)
|
|
200
207
|
});
|
|
@@ -204,7 +211,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
204
211
|
error: event.error
|
|
205
212
|
}, {
|
|
206
213
|
F: __dxlog_file2,
|
|
207
|
-
L:
|
|
214
|
+
L: 104,
|
|
208
215
|
S: this,
|
|
209
216
|
C: (f, a) => f(...a)
|
|
210
217
|
});
|
|
@@ -216,12 +223,13 @@ var EdgeWsConnection = class extends Resource {
|
|
|
216
223
|
event: event.type
|
|
217
224
|
}, {
|
|
218
225
|
F: __dxlog_file2,
|
|
219
|
-
L:
|
|
226
|
+
L: 112,
|
|
220
227
|
S: this,
|
|
221
228
|
C: (f, a) => f(...a)
|
|
222
229
|
});
|
|
223
230
|
return;
|
|
224
231
|
}
|
|
232
|
+
this._lastReceivedMessageTimestamp = Date.now();
|
|
225
233
|
if (event.data === "__pong__") {
|
|
226
234
|
this._rescheduleHeartbeatTimeout();
|
|
227
235
|
return;
|
|
@@ -237,7 +245,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
237
245
|
payload: protocol.getPayloadType(message)
|
|
238
246
|
}, {
|
|
239
247
|
F: __dxlog_file2,
|
|
240
|
-
L:
|
|
248
|
+
L: 130,
|
|
241
249
|
S: this,
|
|
242
250
|
C: (f, a) => f(...a)
|
|
243
251
|
});
|
|
@@ -261,7 +269,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
261
269
|
err
|
|
262
270
|
}, {
|
|
263
271
|
F: __dxlog_file2,
|
|
264
|
-
L:
|
|
272
|
+
L: 148,
|
|
265
273
|
S: this,
|
|
266
274
|
C: (f, a) => f(...a)
|
|
267
275
|
});
|
|
@@ -270,7 +278,7 @@ var EdgeWsConnection = class extends Resource {
|
|
|
270
278
|
_scheduleHeartbeats() {
|
|
271
279
|
invariant2(this._ws, void 0, {
|
|
272
280
|
F: __dxlog_file2,
|
|
273
|
-
L:
|
|
281
|
+
L: 153,
|
|
274
282
|
S: this,
|
|
275
283
|
A: [
|
|
276
284
|
"this._ws",
|
|
@@ -290,17 +298,23 @@ var EdgeWsConnection = class extends Resource {
|
|
|
290
298
|
void this._inactivityTimeoutCtx?.dispose();
|
|
291
299
|
this._inactivityTimeoutCtx = new Context(void 0, {
|
|
292
300
|
F: __dxlog_file2,
|
|
293
|
-
L:
|
|
301
|
+
L: 172
|
|
294
302
|
});
|
|
295
303
|
scheduleTask(this._inactivityTimeoutCtx, () => {
|
|
296
304
|
if (this.isOpen) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
305
|
+
if (Date.now() - this._lastReceivedMessageTimestamp > SIGNAL_KEEPALIVE_TIMEOUT) {
|
|
306
|
+
log.warn("restart due to inactivity timeout", {
|
|
307
|
+
lastReceivedMessageTimestamp: this._lastReceivedMessageTimestamp
|
|
308
|
+
}, {
|
|
309
|
+
F: __dxlog_file2,
|
|
310
|
+
L: 178,
|
|
311
|
+
S: this,
|
|
312
|
+
C: (f, a) => f(...a)
|
|
313
|
+
});
|
|
314
|
+
this._callbacks.onRestartRequired();
|
|
315
|
+
} else {
|
|
316
|
+
this._rescheduleHeartbeatTimeout();
|
|
317
|
+
}
|
|
304
318
|
}
|
|
305
319
|
}, SIGNAL_KEEPALIVE_TIMEOUT);
|
|
306
320
|
}
|
|
@@ -339,6 +353,16 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
339
353
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-client.ts";
|
|
340
354
|
var DEFAULT_TIMEOUT = 1e4;
|
|
341
355
|
var EdgeClient = class extends Resource2 {
|
|
356
|
+
_identity;
|
|
357
|
+
_config;
|
|
358
|
+
statusChanged;
|
|
359
|
+
_persistentLifecycle;
|
|
360
|
+
_messageListeners;
|
|
361
|
+
_reconnectListeners;
|
|
362
|
+
_baseWsUrl;
|
|
363
|
+
_baseHttpUrl;
|
|
364
|
+
_currentConnection;
|
|
365
|
+
_ready;
|
|
342
366
|
constructor(_identity, _config) {
|
|
343
367
|
super(), this._identity = _identity, this._config = _config, this.statusChanged = new Event(), this._persistentLifecycle = new PersistentLifecycle({
|
|
344
368
|
start: async () => this._connect(),
|
|
@@ -615,6 +639,7 @@ var EdgeClient = class extends Resource2 {
|
|
|
615
639
|
return void 0;
|
|
616
640
|
}
|
|
617
641
|
}
|
|
642
|
+
_isActive;
|
|
618
643
|
};
|
|
619
644
|
_ts_decorate2([
|
|
620
645
|
logInfo2
|
|
@@ -749,13 +774,11 @@ import { Context as Context2, Duration, Effect, Layer, Schedule } from "effect";
|
|
|
749
774
|
import { log as log3 } from "@dxos/log";
|
|
750
775
|
var __dxlog_file5 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/http-client.ts";
|
|
751
776
|
var HttpConfig = class _HttpConfig extends Context2.Tag("HttpConfig")() {
|
|
752
|
-
static {
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
});
|
|
758
|
-
}
|
|
777
|
+
static default = Layer.succeed(_HttpConfig, {
|
|
778
|
+
timeout: Duration.millis(1e3),
|
|
779
|
+
retryTimes: 3,
|
|
780
|
+
retryBaseDelay: Duration.millis(1e3)
|
|
781
|
+
});
|
|
759
782
|
};
|
|
760
783
|
var withRetry = (effect, { timeout = Duration.millis(1e3), retryBaseDelay = Duration.millis(1e3), retryTimes = 3 } = {}) => {
|
|
761
784
|
return effect.pipe(Effect.flatMap((res) => (
|
|
@@ -789,6 +812,12 @@ var DEFAULT_RETRY_TIMEOUT = 1500;
|
|
|
789
812
|
var DEFAULT_RETRY_JITTER = 500;
|
|
790
813
|
var DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
791
814
|
var EdgeHttpClient = class {
|
|
815
|
+
_baseUrl;
|
|
816
|
+
_edgeIdentity;
|
|
817
|
+
/**
|
|
818
|
+
* Auth header is cached until receiving the next 401 from EDGE, at which point it gets refreshed.
|
|
819
|
+
*/
|
|
820
|
+
_authHeader;
|
|
792
821
|
constructor(baseUrl) {
|
|
793
822
|
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, "http");
|
|
794
823
|
log4("created", {
|
|
@@ -873,6 +902,12 @@ var EdgeHttpClient = class {
|
|
|
873
902
|
//
|
|
874
903
|
// OAuth and credentials
|
|
875
904
|
//
|
|
905
|
+
async listFunctions(args) {
|
|
906
|
+
return this._call(new URL("/functions", this.baseUrl), {
|
|
907
|
+
...args,
|
|
908
|
+
method: "GET"
|
|
909
|
+
});
|
|
910
|
+
}
|
|
876
911
|
async initiateOAuthFlow(body, args) {
|
|
877
912
|
return this._call(new URL("/oauth/initiate", this.baseUrl), {
|
|
878
913
|
...args,
|
|
@@ -960,14 +995,14 @@ var EdgeHttpClient = class {
|
|
|
960
995
|
const shouldRetry = createRetryHandler(args);
|
|
961
996
|
const requestContext = args.context ?? new Context3(void 0, {
|
|
962
997
|
F: __dxlog_file6,
|
|
963
|
-
L:
|
|
998
|
+
L: 293
|
|
964
999
|
});
|
|
965
1000
|
log4("fetch", {
|
|
966
1001
|
url,
|
|
967
1002
|
request: args.body
|
|
968
1003
|
}, {
|
|
969
1004
|
F: __dxlog_file6,
|
|
970
|
-
L:
|
|
1005
|
+
L: 294,
|
|
971
1006
|
S: this,
|
|
972
1007
|
C: (f, a) => f(...a)
|
|
973
1008
|
});
|
|
@@ -989,7 +1024,7 @@ var EdgeHttpClient = class {
|
|
|
989
1024
|
body
|
|
990
1025
|
}, {
|
|
991
1026
|
F: __dxlog_file6,
|
|
992
|
-
L:
|
|
1027
|
+
L: 310,
|
|
993
1028
|
S: this,
|
|
994
1029
|
C: (f, a) => f(...a)
|
|
995
1030
|
});
|
|
@@ -1014,7 +1049,7 @@ var EdgeHttpClient = class {
|
|
|
1014
1049
|
processingError
|
|
1015
1050
|
}, {
|
|
1016
1051
|
F: __dxlog_file6,
|
|
1017
|
-
L:
|
|
1052
|
+
L: 328,
|
|
1018
1053
|
S: this,
|
|
1019
1054
|
C: (f, a) => f(...a)
|
|
1020
1055
|
});
|
|
@@ -1027,7 +1062,7 @@ var EdgeHttpClient = class {
|
|
|
1027
1062
|
if (!this._edgeIdentity) {
|
|
1028
1063
|
log4.warn("unauthorized response received before identity was set", void 0, {
|
|
1029
1064
|
F: __dxlog_file6,
|
|
1030
|
-
L:
|
|
1065
|
+
L: 337,
|
|
1031
1066
|
S: this,
|
|
1032
1067
|
C: (f, a) => f(...a)
|
|
1033
1068
|
});
|