@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
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import { Event } from '@dxos/async';
|
|
2
1
|
import { Resource, type Lifecycle } from '@dxos/context';
|
|
3
2
|
import { type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
4
|
-
import { EdgeStatus } from '@dxos/protocols/proto/dxos/client/services';
|
|
5
3
|
import { type EdgeIdentity } from './edge-identity';
|
|
6
4
|
import { type Protocol } from './protocol';
|
|
7
5
|
export type MessageListener = (message: Message) => void;
|
|
8
6
|
export type ReconnectListener = () => void;
|
|
9
7
|
export interface EdgeConnection extends Required<Lifecycle> {
|
|
10
|
-
statusChanged: Event<EdgeStatus>;
|
|
11
8
|
get info(): any;
|
|
12
9
|
get identityKey(): string;
|
|
13
10
|
get peerKey(): string;
|
|
14
11
|
get isOpen(): boolean;
|
|
15
|
-
get
|
|
12
|
+
get isConnected(): boolean;
|
|
16
13
|
setIdentity(identity: EdgeIdentity): void;
|
|
17
14
|
onMessage(listener: MessageListener): () => void;
|
|
18
15
|
onReconnected(listener: ReconnectListener): () => void;
|
|
@@ -33,7 +30,6 @@ export type MessengerConfig = {
|
|
|
33
30
|
export declare class EdgeClient extends Resource implements EdgeConnection {
|
|
34
31
|
private _identity;
|
|
35
32
|
private readonly _config;
|
|
36
|
-
readonly statusChanged: Event<EdgeStatus>;
|
|
37
33
|
private readonly _persistentLifecycle;
|
|
38
34
|
private readonly _messageListeners;
|
|
39
35
|
private readonly _reconnectListeners;
|
|
@@ -44,11 +40,10 @@ export declare class EdgeClient extends Resource implements EdgeConnection {
|
|
|
44
40
|
constructor(_identity: EdgeIdentity, _config: MessengerConfig);
|
|
45
41
|
get info(): {
|
|
46
42
|
open: boolean;
|
|
47
|
-
status: EdgeStatus;
|
|
48
43
|
identity: string;
|
|
49
44
|
device: string;
|
|
50
45
|
};
|
|
51
|
-
get
|
|
46
|
+
get isConnected(): boolean;
|
|
52
47
|
get identityKey(): string;
|
|
53
48
|
get peerKey(): string;
|
|
54
49
|
setIdentity(identity: EdgeIdentity): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-client.d.ts","sourceRoot":"","sources":["../../../src/edge-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"edge-client.d.ts","sourceRoot":"","sources":["../../../src/edge-client.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AA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AAmB,CAAgC;IAEpE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IAEtC,OAAO,CAAC,kBAAkB,CAAC,CAA+B;IAC1D,OAAO,CAAC,MAAM,CAAiB;gBAGrB,SAAS,EAAE,YAAY,EACd,OAAO,EAAE,eAAe;IAO3C,IACW,IAAI;;;;MAMd;IAED,IAAI,WAAW,YAEd;IAED,IAAI,WAAW,WAEd;IAED,IAAI,OAAO,WAEV;IAED,WAAW,CAAC,QAAQ,EAAE,YAAY;IAS3B,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI;IAKhD,aAAa,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAkBtD;;OAEG;cACsB,KAAK;IAO9B;;OAEG;cACsB,MAAM;YAMjB,QAAQ;YA2DR,WAAW;IAIzB,OAAO,CAAC,uBAAuB;IAM/B,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,sBAAsB;IAU9B;;;OAGG;IACU,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YAoBpC,iBAAiB;IAY/B,OAAO,CAAC,SAAS,CAA4E;CAC9F"}
|
|
@@ -22,6 +22,7 @@ export declare class EdgeHttpClient {
|
|
|
22
22
|
recoverIdentity(body: RecoverIdentityRequest, args?: EdgeHttpGetArgs): Promise<RecoverIdentityResponseBody>;
|
|
23
23
|
executeWorkflow(spaceId: SpaceId, graphId: ObjectId, input: any, args?: EdgeHttpGetArgs): Promise<ExecuteWorkflowResponseBody>;
|
|
24
24
|
uploadFunction(pathParts: {
|
|
25
|
+
spaceId: SpaceId;
|
|
25
26
|
functionId?: string;
|
|
26
27
|
}, body: UploadFunctionRequest, args?: EdgeHttpGetArgs): Promise<UploadFunctionResponseBody>;
|
|
27
28
|
initiateOAuthFlow(body: InitiateOAuthFlowRequest, args?: EdgeHttpGetArgs): Promise<InitiateOAuth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CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,GAAG,CAAC;IAAC,KAAK,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-identity.d.ts","sourceRoot":"","sources":["../../../src/edge-identity.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAEhF,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACrF;AAED,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"edge-identity.d.ts","sourceRoot":"","sources":["../../../src/edge-identity.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAEhF,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,SAAS,EAAE,EAAE;QAAE,SAAS,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACrF;AAED,eAAO,MAAM,mBAAmB,mBAA0B,QAAQ,YAAY,YAAY,KAAG,OAAO,CAAC,UAAU,CAW9G,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-ws-connection.d.ts","sourceRoot":"","sources":["../../../src/edge-ws-connection.ts"],"names":[],"mappings":"AAOA,OAAO,EAAW,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"edge-ws-connection.d.ts","sourceRoot":"","sources":["../../../src/edge-ws-connection.ts"],"names":[],"mappings":"AAOA,OAAO,EAAW,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIlD,OAAO,EAAiB,KAAK,OAAO,EAAE,MAAM,4CAA4C,CAAC;AAGzF,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAWpD,MAAM,MAAM,yBAAyB,GAAG;IACtC,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACtC,iBAAiB,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAEF,qBAAa,gBAAiB,SAAQ,QAAQ;IAK1C,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAN7B,OAAO,CAAC,qBAAqB,CAAsB;IACnD,OAAO,CAAC,GAAG,CAAwB;gBAGhB,SAAS,EAAE,YAAY,EACvB,eAAe,EAAE;QAAE,GAAG,EAAE,GAAG,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAA;KAAE,EACtD,UAAU,EAAE,yBAAyB;IAKxD,IACW,IAAI;;;;MAMd;IAEM,IAAI,CAAC,OAAO,EAAE,OAAO;cAeH,KAAK;cAkDL,MAAM;IAc/B,OAAO,CAAC,mBAAmB;IAe3B,OAAO,CAAC,2BAA2B;CAiBpC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,4CAA4C,CAAC;AAE3D,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAIA,cAAc,4CAA4C,CAAC;AAE3D,cAAc,eAAe,CAAC;AAC9B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/protocol.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,GAAG,EAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,KAAK,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAG1G,MAAM,MAAM,QAAQ,GAAG,GAAG,CAAC,gBAAgB,CAAC,OAAO,UAAU,CAAC,CAAC;AAE/D,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../../src/protocol.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,GAAG,EAAU,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,KAAK,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAG1G,MAAM,MAAM,QAAQ,GAAG,GAAG,CAAC,gBAAgB,CAAC,OAAO,UAAU,CAAC,CAAC;AAE/D,eAAO,MAAM,WAAW,aAAc,MAAM,WAAsC,CAAC;AAEnF;;GAEG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;gBAEjC,KAAK,EAAE,GAAG,CAAC,WAAW,EAAE;IAIpC,IAAI,YAAY,IAAI,GAAG,CAAC,QAAQ,CAE/B;IAED,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,GAAG;IAQ7B;;OAEG;IACH,UAAU,CAAC,IAAI,SAAS,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC;IAa9F;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS;IASpD;;OAEG;IACH,aAAa,CAAC,IAAI,SAAS,GAAG,CAAC,WAAW,EACxC,IAAI,EAAE,IAAI,EACV,EACE,MAAM,EACN,MAAM,EACN,OAAO,EACP,SAAS,GACV,EAAE;QACD,MAAM,CAAC,EAAE,QAAQ,CAAC;QAClB,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;QACpB,OAAO,CAAC,EAAE,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACrC,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB;CAUJ;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,SAAgB,GAAG,KAAG,OAAO,CAAC,UAAU,CAYhE,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import WebSocket from 'isomorphic-ws';
|
|
2
2
|
import { Trigger } from '@dxos/async';
|
|
3
3
|
import { type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
4
|
-
import { WebSocketMuxer } from '../edge-ws-muxer';
|
|
5
4
|
export declare const DEFAULT_PORT = 8080;
|
|
6
5
|
type TestEdgeWsServerParams = {
|
|
7
6
|
admitConnection?: Trigger;
|
|
@@ -14,12 +13,9 @@ export declare const createTestEdgeWsServer: (port?: number, params?: TestEdgeWs
|
|
|
14
13
|
messageSourceLog: any[];
|
|
15
14
|
endpoint: string;
|
|
16
15
|
cleanup: () => void;
|
|
17
|
-
currentConnection: () =>
|
|
18
|
-
ws: WebSocket;
|
|
19
|
-
muxer: WebSocketMuxer;
|
|
20
|
-
} | undefined;
|
|
16
|
+
currentConnection: () => WebSocket | undefined;
|
|
21
17
|
sendResponseMessage: (request: Message, responsePayload: Uint8Array) => void;
|
|
22
|
-
sendMessage: (msg: Message) =>
|
|
18
|
+
sendMessage: (msg: Message) => void;
|
|
23
19
|
closeConnection: () => Promise<void>;
|
|
24
20
|
}>;
|
|
25
21
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-utils.ts"],"names":[],"mappings":"AAIA,OAAO,SAAS,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-utils.ts"],"names":[],"mappings":"AAIA,OAAO,SAAS,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAoC,KAAK,OAAO,EAAE,MAAM,4CAA4C,CAAC;AAK5G,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,KAAK,sBAAsB,GAAG;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,GAAG,CAAC;IAC9C,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;CACpE,CAAC;AAEF,eAAO,MAAM,sBAAsB,2BAAwC,sBAAsB;;;;;;;mCAsE9E,OAAO,mBAAmB,UAAU;uBA1BhC,OAAO;;EAS7B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,sBAAsB,YAAa,MAAM,YAAY,MAAM,GAAG,IAAI,WAK9E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"5.
|
|
1
|
+
{"version":"5.7.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/edge-client",
|
|
3
|
-
"version": "0.8.2-
|
|
3
|
+
"version": "0.8.2-staging.7ac8446",
|
|
4
4
|
"description": "EDGE Client",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -14,11 +14,6 @@
|
|
|
14
14
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
15
|
"node": "./dist/lib/node-esm/index.mjs"
|
|
16
16
|
},
|
|
17
|
-
"./muxer": {
|
|
18
|
-
"types": "./dist/types/src/edge-ws-muxer.d.ts",
|
|
19
|
-
"browser": "./dist/lib/browser/edge-ws-muxer.mjs",
|
|
20
|
-
"node": "./dist/lib/node-esm/edge-ws-muxer.mjs"
|
|
21
|
-
},
|
|
22
17
|
"./testing": {
|
|
23
18
|
"types": "./dist/types/src/testing/index.d.ts",
|
|
24
19
|
"browser": "./dist/lib/browser/testing/index.mjs",
|
|
@@ -41,21 +36,21 @@
|
|
|
41
36
|
"dependencies": {
|
|
42
37
|
"isomorphic-ws": "^5.0.0",
|
|
43
38
|
"ws": "^8.14.2",
|
|
44
|
-
"@dxos/async": "0.8.2-
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/util": "0.8.2-
|
|
39
|
+
"@dxos/async": "0.8.2-staging.7ac8446",
|
|
40
|
+
"@dxos/context": "0.8.2-staging.7ac8446",
|
|
41
|
+
"@dxos/credentials": "0.8.2-staging.7ac8446",
|
|
42
|
+
"@dxos/crypto": "0.8.2-staging.7ac8446",
|
|
43
|
+
"@dxos/keyring": "0.8.2-staging.7ac8446",
|
|
44
|
+
"@dxos/debug": "0.8.2-staging.7ac8446",
|
|
45
|
+
"@dxos/keys": "0.8.2-staging.7ac8446",
|
|
46
|
+
"@dxos/invariant": "0.8.2-staging.7ac8446",
|
|
47
|
+
"@dxos/log": "0.8.2-staging.7ac8446",
|
|
48
|
+
"@dxos/protocols": "0.8.2-staging.7ac8446",
|
|
49
|
+
"@dxos/node-std": "0.8.2-staging.7ac8446",
|
|
50
|
+
"@dxos/util": "0.8.2-staging.7ac8446"
|
|
56
51
|
},
|
|
57
52
|
"devDependencies": {
|
|
58
|
-
"@dxos/test-utils": "0.8.2-
|
|
53
|
+
"@dxos/test-utils": "0.8.2-staging.7ac8446"
|
|
59
54
|
},
|
|
60
55
|
"publishConfig": {
|
|
61
56
|
"access": "public"
|
package/src/edge-client.test.ts
CHANGED
|
@@ -7,7 +7,6 @@ import { describe, expect, onTestFinished, test } from 'vitest';
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
8
|
import { Keyring } from '@dxos/keyring';
|
|
9
9
|
import { TextMessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
10
|
-
import { EdgeStatus } from '@dxos/protocols/proto/dxos/client/services';
|
|
11
10
|
import { openAndClose } from '@dxos/test-utils';
|
|
12
11
|
|
|
13
12
|
import { createEphemeralEdgeIdentity, createTestHaloEdgeIdentity } from './auth';
|
|
@@ -41,17 +40,17 @@ describe('EdgeClient', () => {
|
|
|
41
40
|
|
|
42
41
|
const { client } = await openNewClient(endpoint);
|
|
43
42
|
|
|
44
|
-
expect(client.
|
|
43
|
+
expect(client.isConnected).toBeFalsy();
|
|
45
44
|
admitConnection.wake();
|
|
46
|
-
await expect.poll(() => client.
|
|
45
|
+
await expect.poll(() => client.isConnected).toBeTruthy();
|
|
47
46
|
|
|
48
47
|
admitConnection.reset();
|
|
49
48
|
await closeConnection();
|
|
50
49
|
expect(client.isOpen).is.true;
|
|
51
|
-
await expect.poll(() => client.
|
|
50
|
+
await expect.poll(() => client.isConnected).toBeFalsy();
|
|
52
51
|
|
|
53
52
|
admitConnection.wake();
|
|
54
|
-
await expect.poll(() => client.
|
|
53
|
+
await expect.poll(() => client.isConnected).toBeTruthy();
|
|
55
54
|
});
|
|
56
55
|
|
|
57
56
|
test('set identity reconnects', async () => {
|
package/src/edge-client.ts
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle
|
|
5
|
+
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle } from '@dxos/async';
|
|
6
6
|
import { Resource, type Lifecycle } from '@dxos/context';
|
|
7
7
|
import { log, logInfo } from '@dxos/log';
|
|
8
8
|
import { type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
9
|
-
import { EdgeStatus } from '@dxos/protocols/proto/dxos/client/services';
|
|
10
9
|
|
|
11
10
|
import { protocol } from './defs';
|
|
12
11
|
import { type EdgeIdentity, handleAuthChallenge } from './edge-identity';
|
|
@@ -21,12 +20,11 @@ export type MessageListener = (message: Message) => void;
|
|
|
21
20
|
export type ReconnectListener = () => void;
|
|
22
21
|
|
|
23
22
|
export interface EdgeConnection extends Required<Lifecycle> {
|
|
24
|
-
statusChanged: Event<EdgeStatus>;
|
|
25
23
|
get info(): any;
|
|
26
24
|
get identityKey(): string;
|
|
27
25
|
get peerKey(): string;
|
|
28
26
|
get isOpen(): boolean;
|
|
29
|
-
get
|
|
27
|
+
get isConnected(): boolean;
|
|
30
28
|
setIdentity(identity: EdgeIdentity): void;
|
|
31
29
|
onMessage(listener: MessageListener): () => void;
|
|
32
30
|
onReconnected(listener: ReconnectListener): () => void;
|
|
@@ -47,8 +45,6 @@ export type MessengerConfig = {
|
|
|
47
45
|
* - Dispatches connection state and message notifications.
|
|
48
46
|
*/
|
|
49
47
|
export class EdgeClient extends Resource implements EdgeConnection {
|
|
50
|
-
public readonly statusChanged = new Event<EdgeStatus>();
|
|
51
|
-
|
|
52
48
|
private readonly _persistentLifecycle = new PersistentLifecycle<EdgeWsConnection>({
|
|
53
49
|
start: async () => this._connect(),
|
|
54
50
|
stop: async (state: EdgeWsConnection) => this._disconnect(state),
|
|
@@ -56,8 +52,10 @@ export class EdgeClient extends Resource implements EdgeConnection {
|
|
|
56
52
|
|
|
57
53
|
private readonly _messageListeners = new Set<MessageListener>();
|
|
58
54
|
private readonly _reconnectListeners = new Set<ReconnectListener>();
|
|
55
|
+
|
|
59
56
|
private readonly _baseWsUrl: string;
|
|
60
57
|
private readonly _baseHttpUrl: string;
|
|
58
|
+
|
|
61
59
|
private _currentConnection?: EdgeWsConnection = undefined;
|
|
62
60
|
private _ready = new Trigger();
|
|
63
61
|
|
|
@@ -74,16 +72,13 @@ export class EdgeClient extends Resource implements EdgeConnection {
|
|
|
74
72
|
public get info() {
|
|
75
73
|
return {
|
|
76
74
|
open: this.isOpen,
|
|
77
|
-
status: this.status,
|
|
78
75
|
identity: this._identity.identityKey,
|
|
79
76
|
device: this._identity.peerKey,
|
|
80
77
|
};
|
|
81
78
|
}
|
|
82
79
|
|
|
83
|
-
get
|
|
84
|
-
return Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED
|
|
85
|
-
? EdgeStatus.CONNECTED
|
|
86
|
-
: EdgeStatus.NOT_CONNECTED;
|
|
80
|
+
get isConnected() {
|
|
81
|
+
return Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED;
|
|
87
82
|
}
|
|
88
83
|
|
|
89
84
|
get identityKey() {
|
|
@@ -99,7 +94,7 @@ export class EdgeClient extends Resource implements EdgeConnection {
|
|
|
99
94
|
log('Edge identity changed', { identity, oldIdentity: this._identity });
|
|
100
95
|
this._identity = identity;
|
|
101
96
|
this._closeCurrentConnection(new EdgeIdentityChangedError());
|
|
102
|
-
|
|
97
|
+
this._persistentLifecycle.scheduleRestart();
|
|
103
98
|
}
|
|
104
99
|
}
|
|
105
100
|
|
|
@@ -176,7 +171,7 @@ export class EdgeClient extends Resource implements EdgeConnection {
|
|
|
176
171
|
onRestartRequired: () => {
|
|
177
172
|
if (this._isActive(connection)) {
|
|
178
173
|
this._closeCurrentConnection();
|
|
179
|
-
|
|
174
|
+
this._persistentLifecycle.scheduleRestart();
|
|
180
175
|
} else {
|
|
181
176
|
log.verbose('restart requested by inactive connection');
|
|
182
177
|
}
|
|
@@ -206,18 +201,15 @@ export class EdgeClient extends Resource implements EdgeConnection {
|
|
|
206
201
|
|
|
207
202
|
private async _disconnect(state: EdgeWsConnection) {
|
|
208
203
|
await state.close();
|
|
209
|
-
this.statusChanged.emit(this.status);
|
|
210
204
|
}
|
|
211
205
|
|
|
212
206
|
private _closeCurrentConnection(error: Error = new EdgeConnectionClosedError()) {
|
|
213
207
|
this._currentConnection = undefined;
|
|
214
208
|
this._ready.throw(error);
|
|
215
209
|
this._ready.reset();
|
|
216
|
-
this.statusChanged.emit(this.status);
|
|
217
210
|
}
|
|
218
211
|
|
|
219
212
|
private _notifyReconnected() {
|
|
220
|
-
this.statusChanged.emit(this.status);
|
|
221
213
|
for (const listener of this._reconnectListeners) {
|
|
222
214
|
try {
|
|
223
215
|
listener();
|
package/src/edge-http-client.ts
CHANGED
|
@@ -112,11 +112,11 @@ export class EdgeHttpClient {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
public async uploadFunction(
|
|
115
|
-
pathParts: { functionId?: string },
|
|
115
|
+
pathParts: { spaceId: SpaceId; functionId?: string },
|
|
116
116
|
body: UploadFunctionRequest,
|
|
117
117
|
args?: EdgeHttpGetArgs,
|
|
118
118
|
): Promise<UploadFunctionResponseBody> {
|
|
119
|
-
const path = ['functions', ...(pathParts.functionId ? [pathParts.functionId] : [])].join('/');
|
|
119
|
+
const path = ['functions', pathParts.spaceId, ...(pathParts.functionId ? [pathParts.functionId] : [])].join('/');
|
|
120
120
|
return this._call(path, { ...args, body, method: 'PUT' });
|
|
121
121
|
}
|
|
122
122
|
|
|
@@ -8,18 +8,21 @@ import { scheduleTask, scheduleTaskInterval } from '@dxos/async';
|
|
|
8
8
|
import { Context, Resource } from '@dxos/context';
|
|
9
9
|
import { invariant } from '@dxos/invariant';
|
|
10
10
|
import { log, logInfo } from '@dxos/log';
|
|
11
|
-
import { EdgeWebsocketProtocol } from '@dxos/protocols';
|
|
12
11
|
import { buf } from '@dxos/protocols/buf';
|
|
13
12
|
import { MessageSchema, type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
14
13
|
|
|
15
14
|
import { protocol } from './defs';
|
|
16
15
|
import { type EdgeIdentity } from './edge-identity';
|
|
17
|
-
import { CLOUDFLARE_MESSAGE_MAX_BYTES, WebSocketMuxer } from './edge-ws-muxer';
|
|
18
16
|
import { toUint8Array } from './protocol';
|
|
19
17
|
|
|
20
18
|
const SIGNAL_KEEPALIVE_INTERVAL = 4_000;
|
|
21
19
|
const SIGNAL_KEEPALIVE_TIMEOUT = 12_000;
|
|
22
20
|
|
|
21
|
+
/**
|
|
22
|
+
* 1MB websocket message limit: https://developers.cloudflare.com/durable-objects/platform/limits/
|
|
23
|
+
*/
|
|
24
|
+
const CLOUDFLARE_MESSAGE_LENGTH_LIMIT = 1024 * 1024;
|
|
25
|
+
|
|
23
26
|
export type EdgeWsConnectionCallbacks = {
|
|
24
27
|
onConnected: () => void;
|
|
25
28
|
onMessage: (message: Message) => void;
|
|
@@ -29,7 +32,6 @@ export type EdgeWsConnectionCallbacks = {
|
|
|
29
32
|
export class EdgeWsConnection extends Resource {
|
|
30
33
|
private _inactivityTimeoutCtx: Context | undefined;
|
|
31
34
|
private _ws: WebSocket | undefined;
|
|
32
|
-
private _wsMuxer: WebSocketMuxer | undefined;
|
|
33
35
|
|
|
34
36
|
constructor(
|
|
35
37
|
private readonly _identity: EdgeIdentity,
|
|
@@ -50,34 +52,24 @@ export class EdgeWsConnection extends Resource {
|
|
|
50
52
|
|
|
51
53
|
public send(message: Message) {
|
|
52
54
|
invariant(this._ws);
|
|
53
|
-
invariant(this._wsMuxer);
|
|
54
55
|
log('sending...', { peerKey: this._identity.peerKey, payload: protocol.getPayloadType(message) });
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
this._ws.send(binary);
|
|
66
|
-
} else {
|
|
67
|
-
this._wsMuxer.send(message).catch((e) => log.catch(e));
|
|
56
|
+
const encoded = buf.toBinary(MessageSchema, message);
|
|
57
|
+
if (encoded.byteLength >= CLOUDFLARE_MESSAGE_LENGTH_LIMIT) {
|
|
58
|
+
log.error('edge message dropped due to websocket message limit', {
|
|
59
|
+
byteLength: encoded.byteLength,
|
|
60
|
+
serviceId: message.serviceId,
|
|
61
|
+
payload: protocol.getPayloadType(message),
|
|
62
|
+
});
|
|
63
|
+
return;
|
|
68
64
|
}
|
|
65
|
+
this._ws.send(encoded);
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
protected override async _open() {
|
|
72
|
-
const baseProtocols = [...Object.values(EdgeWebsocketProtocol)];
|
|
73
69
|
this._ws = new WebSocket(
|
|
74
70
|
this._connectionInfo.url.toString(),
|
|
75
|
-
this._connectionInfo.protocolHeader
|
|
76
|
-
? [...baseProtocols, this._connectionInfo.protocolHeader]
|
|
77
|
-
: [...baseProtocols],
|
|
71
|
+
this._connectionInfo.protocolHeader ? [this._connectionInfo.protocolHeader] : [],
|
|
78
72
|
);
|
|
79
|
-
const muxer = new WebSocketMuxer(this._ws);
|
|
80
|
-
this._wsMuxer = muxer;
|
|
81
73
|
|
|
82
74
|
this._ws.onopen = () => {
|
|
83
75
|
if (this.isOpen) {
|
|
@@ -92,7 +84,6 @@ export class EdgeWsConnection extends Resource {
|
|
|
92
84
|
if (this.isOpen) {
|
|
93
85
|
log.warn('disconnected while being open', { code: event.code, reason: event.reason });
|
|
94
86
|
this._callbacks.onRestartRequired();
|
|
95
|
-
muxer.destroy();
|
|
96
87
|
}
|
|
97
88
|
};
|
|
98
89
|
this._ws.onerror = (event) => {
|
|
@@ -115,16 +106,9 @@ export class EdgeWsConnection extends Resource {
|
|
|
115
106
|
this._rescheduleHeartbeatTimeout();
|
|
116
107
|
return;
|
|
117
108
|
}
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const message = this._ws?.protocol?.includes(EdgeWebsocketProtocol.V0)
|
|
124
|
-
? buf.fromBinary(MessageSchema, bytes)
|
|
125
|
-
: muxer.receiveData(bytes);
|
|
126
|
-
|
|
127
|
-
if (message) {
|
|
109
|
+
const data = await toUint8Array(event.data);
|
|
110
|
+
if (this.isOpen) {
|
|
111
|
+
const message = buf.fromBinary(MessageSchema, data);
|
|
128
112
|
log('received', { from: message.source, payload: protocol.getPayloadType(message) });
|
|
129
113
|
this._callbacks.onMessage(message);
|
|
130
114
|
}
|
|
@@ -137,8 +121,6 @@ export class EdgeWsConnection extends Resource {
|
|
|
137
121
|
try {
|
|
138
122
|
this._ws?.close();
|
|
139
123
|
this._ws = undefined;
|
|
140
|
-
this._wsMuxer?.destroy();
|
|
141
|
-
this._wsMuxer = undefined;
|
|
142
124
|
} catch (err) {
|
|
143
125
|
if (err instanceof Error && err.message.includes('WebSocket is closed before the connection is established.')) {
|
|
144
126
|
return;
|
package/src/index.ts
CHANGED
|
@@ -6,12 +6,10 @@ import WebSocket from 'isomorphic-ws';
|
|
|
6
6
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
8
|
import { log } from '@dxos/log';
|
|
9
|
-
import { EdgeWebsocketProtocol } from '@dxos/protocols';
|
|
10
9
|
import { buf } from '@dxos/protocols/buf';
|
|
11
10
|
import { MessageSchema, TextMessageSchema, type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
12
11
|
|
|
13
12
|
import { protocol } from '../defs';
|
|
14
|
-
import { WebSocketMuxer } from '../edge-ws-muxer';
|
|
15
13
|
import { toUint8Array } from '../protocol';
|
|
16
14
|
|
|
17
15
|
export const DEFAULT_PORT = 8080;
|
|
@@ -23,33 +21,24 @@ type TestEdgeWsServerParams = {
|
|
|
23
21
|
};
|
|
24
22
|
|
|
25
23
|
export const createTestEdgeWsServer = async (port = DEFAULT_PORT, params?: TestEdgeWsServerParams) => {
|
|
26
|
-
const
|
|
27
|
-
port,
|
|
28
|
-
verifyClient: createConnectionDelayHandler(params),
|
|
29
|
-
handleProtocols: () => [EdgeWebsocketProtocol.V1],
|
|
30
|
-
});
|
|
24
|
+
const server = new WebSocket.Server({ port, verifyClient: createConnectionDelayHandler(params) });
|
|
31
25
|
|
|
32
|
-
let connection:
|
|
26
|
+
let connection: WebSocket | undefined;
|
|
33
27
|
|
|
34
28
|
const messageSink: any[] = [];
|
|
35
29
|
const messageSourceLog: any[] = [];
|
|
36
30
|
const closeTrigger = new Trigger();
|
|
37
|
-
const sendResponseMessage = createResponseSender(() => connection
|
|
31
|
+
const sendResponseMessage = createResponseSender(() => connection!);
|
|
38
32
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
connection = { ws, muxer };
|
|
33
|
+
server.on('connection', (ws) => {
|
|
34
|
+
connection = ws;
|
|
42
35
|
ws.on('error', (err) => log.catch(err));
|
|
43
36
|
ws.on('message', async (data) => {
|
|
44
37
|
if (String(data) === '__ping__') {
|
|
45
38
|
ws.send('__pong__');
|
|
46
39
|
return;
|
|
47
40
|
}
|
|
48
|
-
const
|
|
49
|
-
if (!message) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const { request, requestPayload } = await decodePayload(message, params);
|
|
41
|
+
const { request, requestPayload } = await decodeRequest(params, data);
|
|
53
42
|
messageSourceLog.push(request.source);
|
|
54
43
|
if (params?.messageHandler) {
|
|
55
44
|
const responsePayload = await params.messageHandler(requestPayload);
|
|
@@ -68,19 +57,19 @@ export const createTestEdgeWsServer = async (port = DEFAULT_PORT, params?: TestE
|
|
|
68
57
|
});
|
|
69
58
|
|
|
70
59
|
return {
|
|
71
|
-
server
|
|
60
|
+
server,
|
|
72
61
|
messageSink,
|
|
73
62
|
messageSourceLog,
|
|
74
|
-
endpoint: `ws://
|
|
75
|
-
cleanup: () =>
|
|
63
|
+
endpoint: `ws://localhost:${port}`,
|
|
64
|
+
cleanup: () => server.close(),
|
|
76
65
|
currentConnection: () => connection,
|
|
77
66
|
sendResponseMessage,
|
|
78
67
|
sendMessage: (msg: Message) => {
|
|
79
|
-
|
|
68
|
+
connection!.send(buf.toBinary(MessageSchema, msg));
|
|
80
69
|
},
|
|
81
70
|
closeConnection: () => {
|
|
82
71
|
closeTrigger.reset();
|
|
83
|
-
connection!.
|
|
72
|
+
connection!.close(1011);
|
|
84
73
|
return closeTrigger.wait();
|
|
85
74
|
},
|
|
86
75
|
};
|
|
@@ -100,23 +89,27 @@ const createConnectionDelayHandler = (params: TestEdgeWsServerParams | undefined
|
|
|
100
89
|
};
|
|
101
90
|
};
|
|
102
91
|
|
|
103
|
-
const createResponseSender = (connection: () =>
|
|
92
|
+
const createResponseSender = (connection: () => WebSocket) => {
|
|
104
93
|
return (request: Message, responsePayload: Uint8Array) => {
|
|
105
94
|
const recipient = request.source!;
|
|
106
|
-
|
|
107
|
-
buf.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
95
|
+
connection().send(
|
|
96
|
+
buf.toBinary(
|
|
97
|
+
MessageSchema,
|
|
98
|
+
buf.create(MessageSchema, {
|
|
99
|
+
source: {
|
|
100
|
+
identityKey: recipient.identityKey,
|
|
101
|
+
peerKey: recipient.peerKey,
|
|
102
|
+
},
|
|
103
|
+
serviceId: request.serviceId!,
|
|
104
|
+
payload: { value: responsePayload },
|
|
105
|
+
}),
|
|
106
|
+
),
|
|
115
107
|
);
|
|
116
108
|
};
|
|
117
109
|
};
|
|
118
110
|
|
|
119
|
-
const
|
|
111
|
+
const decodeRequest = async (params: TestEdgeWsServerParams | undefined, data: any) => {
|
|
112
|
+
const request = buf.fromBinary(MessageSchema, await toUint8Array(data));
|
|
120
113
|
const requestPayload = params?.payloadDecoder
|
|
121
114
|
? params.payloadDecoder(request.payload!.value!)
|
|
122
115
|
: protocol.getPayload(request, TextMessageSchema);
|