@dxos/edge-client 0.8.4-main.e8ec1fe → 0.8.4-main.ef1bc66f44

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/package.json CHANGED
@@ -1,31 +1,32 @@
1
1
  {
2
2
  "name": "@dxos/edge-client",
3
- "version": "0.8.4-main.e8ec1fe",
3
+ "version": "0.8.4-main.ef1bc66f44",
4
4
  "description": "EDGE Client",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
7
11
  "license": "MIT",
8
12
  "author": "DXOS.org",
9
- "sideEffects": true,
13
+ "sideEffects": false,
10
14
  "type": "module",
11
15
  "exports": {
12
16
  ".": {
13
17
  "source": "./src/index.ts",
14
18
  "types": "./dist/types/src/index.d.ts",
15
- "browser": "./dist/lib/browser/index.mjs",
16
- "node": "./dist/lib/node-esm/index.mjs"
19
+ "default": "./dist/lib/neutral/index.mjs"
17
20
  },
18
21
  "./muxer": {
19
22
  "source": "./src/edge-ws-muxer.ts",
20
23
  "types": "./dist/types/src/edge-ws-muxer.d.ts",
21
- "browser": "./dist/lib/browser/edge-ws-muxer.mjs",
22
- "node": "./dist/lib/node-esm/edge-ws-muxer.mjs"
24
+ "default": "./dist/lib/neutral/edge-ws-muxer.mjs"
23
25
  },
24
26
  "./testing": {
25
27
  "source": "./src/testing/index.ts",
26
28
  "types": "./dist/types/src/testing/index.d.ts",
27
- "browser": "./dist/lib/browser/testing/index.mjs",
28
- "node": "./dist/lib/node-esm/testing/index.mjs"
29
+ "default": "./dist/lib/neutral/testing/index.mjs"
29
30
  }
30
31
  },
31
32
  "types": "dist/types/src/index.d.ts",
@@ -42,27 +43,28 @@
42
43
  "README.md"
43
44
  ],
44
45
  "dependencies": {
45
- "@effect/platform": "^0.92.1",
46
+ "@effect/platform": "0.94.4",
46
47
  "isomorphic-ws": "^5.0.0",
47
48
  "ws": "^8.14.2",
48
- "@dxos/async": "0.8.4-main.e8ec1fe",
49
- "@dxos/context": "0.8.4-main.e8ec1fe",
50
- "@dxos/credentials": "0.8.4-main.e8ec1fe",
51
- "@dxos/crypto": "0.8.4-main.e8ec1fe",
52
- "@dxos/invariant": "0.8.4-main.e8ec1fe",
53
- "@dxos/keyring": "0.8.4-main.e8ec1fe",
54
- "@dxos/debug": "0.8.4-main.e8ec1fe",
55
- "@dxos/keys": "0.8.4-main.e8ec1fe",
56
- "@dxos/log": "0.8.4-main.e8ec1fe",
57
- "@dxos/protocols": "0.8.4-main.e8ec1fe",
58
- "@dxos/util": "0.8.4-main.e8ec1fe",
59
- "@dxos/node-std": "0.8.4-main.e8ec1fe"
49
+ "@dxos/async": "0.8.4-main.ef1bc66f44",
50
+ "@dxos/context": "0.8.4-main.ef1bc66f44",
51
+ "@dxos/crypto": "0.8.4-main.ef1bc66f44",
52
+ "@dxos/debug": "0.8.4-main.ef1bc66f44",
53
+ "@dxos/credentials": "0.8.4-main.ef1bc66f44",
54
+ "@dxos/effect": "0.8.4-main.ef1bc66f44",
55
+ "@dxos/invariant": "0.8.4-main.ef1bc66f44",
56
+ "@dxos/keyring": "0.8.4-main.ef1bc66f44",
57
+ "@dxos/keys": "0.8.4-main.ef1bc66f44",
58
+ "@dxos/log": "0.8.4-main.ef1bc66f44",
59
+ "@dxos/protocols": "0.8.4-main.ef1bc66f44",
60
+ "@dxos/util": "0.8.4-main.ef1bc66f44",
61
+ "@dxos/node-std": "0.8.4-main.ef1bc66f44"
60
62
  },
61
63
  "devDependencies": {
62
- "@dxos/test-utils": "0.8.4-main.e8ec1fe"
64
+ "@dxos/test-utils": "0.8.4-main.ef1bc66f44"
63
65
  },
64
66
  "peerDependencies": {
65
- "effect": "^3.13.3"
67
+ "effect": "3.19.16"
66
68
  },
67
69
  "publishConfig": {
68
70
  "access": "public"
@@ -9,6 +9,7 @@ import * as Function from 'effect/Function';
9
9
 
10
10
  import { sleep } from '@dxos/async';
11
11
  import { Context } from '@dxos/context';
12
+ import { runAndForwardErrors } from '@dxos/effect';
12
13
  import { invariant } from '@dxos/invariant';
13
14
  import { type PublicKey, type SpaceId } from '@dxos/keys';
14
15
  import { log } from '@dxos/log';
@@ -19,10 +20,12 @@ import {
19
20
  type CreateSpaceResponseBody,
20
21
  EdgeAuthChallengeError,
21
22
  EdgeCallFailedError,
23
+ type EdgeFailure,
22
24
  type EdgeStatus,
23
25
  type ExecuteWorkflowResponseBody,
24
26
  type ExportBundleRequest,
25
27
  type ExportBundleResponse,
28
+ type FeedProtocol,
26
29
  type GetAgentStatusResponseBody,
27
30
  type GetNotarizationResponseBody,
28
31
  type ImportBundleRequest,
@@ -32,8 +35,6 @@ import {
32
35
  type JoinSpaceResponseBody,
33
36
  type ObjectId,
34
37
  type PostNotarizationRequestBody,
35
- type QueryResult,
36
- type QueueQuery,
37
38
  type RecoverIdentityRequest,
38
39
  type RecoverIdentityResponseBody,
39
40
  type UploadFunctionRequest,
@@ -75,12 +76,6 @@ type EdgeHttpRequestArgs = {
75
76
  */
76
77
  json?: boolean;
77
78
 
78
- /**
79
- * Do not expect a standard EDGE JSON response with a `success` field.
80
- * @deprecated Use only for debugging.
81
- */
82
- rawResponse?: boolean;
83
-
84
79
  /**
85
80
  * Force authentication.
86
81
  * This should be used for requests with large bodies to avoid sending the body twice.
@@ -92,6 +87,10 @@ type EdgeHttpRequestArgs = {
92
87
  export type EdgeHttpGetArgs = Pick<EdgeHttpRequestArgs, 'context' | 'retry' | 'auth'>;
93
88
  export type EdgeHttpPostArgs = Pick<EdgeHttpRequestArgs, 'context' | 'retry' | 'body' | 'auth'>;
94
89
 
90
+ export type GetCronTriggersResponse = {
91
+ cronIds: string[];
92
+ };
93
+
95
94
  export class EdgeHttpClient {
96
95
  private readonly _baseUrl: string;
97
96
 
@@ -123,7 +122,7 @@ export class EdgeHttpClient {
123
122
  //
124
123
 
125
124
  public async getStatus(args?: EdgeHttpGetArgs): Promise<EdgeStatus> {
126
- return this._call(new URL('/status', this.baseUrl), { ...args, method: 'GET' });
125
+ return this._call(new URL('/status', this.baseUrl), { ...args, method: 'GET', auth: true });
127
126
  }
128
127
 
129
128
  //
@@ -209,10 +208,11 @@ export class EdgeHttpClient {
209
208
  public async queryQueue(
210
209
  subspaceTag: string,
211
210
  spaceId: SpaceId,
212
- query: QueueQuery,
211
+ query: FeedProtocol.QueueQuery,
213
212
  args?: EdgeHttpGetArgs,
214
- ): Promise<QueryResult> {
215
- const { queueId } = query;
213
+ ): Promise<FeedProtocol.QueryResult> {
214
+ const queueId = query.queueIds?.[0];
215
+ invariant(queueId, 'queueId required');
216
216
  return this._call(
217
217
  createUrl(new URL(`/spaces/${subspaceTag}/${spaceId}/queue/${queueId}/query`, this.baseUrl), {
218
218
  after: query.after,
@@ -325,7 +325,6 @@ export class EdgeHttpClient {
325
325
  ...args,
326
326
  body: input,
327
327
  method: 'POST',
328
- rawResponse: true,
329
328
  });
330
329
  }
331
330
 
@@ -350,8 +349,16 @@ export class EdgeHttpClient {
350
349
  // Triggers
351
350
  //
352
351
 
353
- public async getCronTriggers(spaceId: SpaceId) {
354
- return this._call(new URL(`/test/functions/${spaceId}/triggers/crons`, this.baseUrl), { method: 'GET' });
352
+ public async getCronTriggers(spaceId: SpaceId): Promise<GetCronTriggersResponse> {
353
+ return this._call<GetCronTriggersResponse>(new URL(`/test/functions/${spaceId}/triggers/crons`, this.baseUrl), {
354
+ method: 'GET',
355
+ });
356
+ }
357
+
358
+ public async forceRunCronTrigger(spaceId: SpaceId, triggerId: ObjectId) {
359
+ return this._call(new URL(`/test/functions/${spaceId}/triggers/crons/${triggerId}/run`, this.baseUrl), {
360
+ method: 'POST',
361
+ });
355
362
  }
356
363
 
357
364
  //
@@ -390,7 +397,7 @@ export class EdgeHttpClient {
390
397
  Effect.provide(FetchHttpClient.layer),
391
398
  Effect.provide(HttpConfig.default),
392
399
  Effect.withSpan('EdgeHttpClient'),
393
- Effect.runPromise,
400
+ runAndForwardErrors,
394
401
  ) as T;
395
402
  }
396
403
 
@@ -418,9 +425,6 @@ export class EdgeHttpClient {
418
425
 
419
426
  if (response.ok) {
420
427
  const body = await response.clone().json();
421
- if (args.rawResponse) {
422
- return body as any;
423
- }
424
428
  invariant(body, 'Expected body to be present');
425
429
  if (!('success' in body)) {
426
430
  return body;
@@ -434,13 +438,13 @@ export class EdgeHttpClient {
434
438
  continue;
435
439
  }
436
440
 
437
- const body =
441
+ const body: EdgeFailure =
438
442
  response.headers.get('Content-Type') === 'application/json' ? await response.clone().json() : undefined;
439
443
 
440
444
  invariant(!body?.success, 'Expected body to not be a failure response or undefined.');
441
445
 
442
- if (body?.errorData?.type === 'auth_challenge' && typeof body?.errorData?.challenge === 'string') {
443
- processingError = new EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
446
+ if (body?.data?.type === 'auth_challenge' && typeof body?.data?.challenge === 'string') {
447
+ processingError = new EdgeAuthChallengeError(body.data.challenge, body.data);
444
448
  } else if (body?.success === false) {
445
449
  processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
446
450
  } else {
@@ -8,6 +8,7 @@ import * as Effect from 'effect/Effect';
8
8
  import * as Function from 'effect/Function';
9
9
  import { afterEach, beforeEach, describe, it } from 'vitest';
10
10
 
11
+ import { runAndForwardErrors } from '@dxos/effect';
11
12
  import { invariant } from '@dxos/invariant';
12
13
 
13
14
  import { HttpConfig, withLogging, withRetry, withRetryConfig } from './http-client';
@@ -36,7 +37,7 @@ describe('HttpClient', () => {
36
37
  withRetry(HttpClient.get(server.url)),
37
38
  Effect.provide(FetchHttpClient.layer),
38
39
  Effect.withSpan('EdgeHttpClient'),
39
- Effect.runPromise,
40
+ runAndForwardErrors,
40
41
  );
41
42
  expect(result).toMatchObject({ success: true, data: { value: 100 } });
42
43
  }
@@ -49,7 +50,7 @@ describe('HttpClient', () => {
49
50
  Effect.provide(FetchHttpClient.layer),
50
51
  Effect.provide(HttpConfig.default), // TODO(burdon): Swap out to mock.
51
52
  Effect.withSpan('EdgeHttpClient'), // TODO(burdon): OTEL.
52
- Effect.runPromise,
53
+ runAndForwardErrors,
53
54
  );
54
55
  expect(result).toMatchObject({ success: true, data: { value: 100 } });
55
56
  }
@@ -16,13 +16,13 @@ import { toUint8Array } from '../protocol';
16
16
 
17
17
  export const DEFAULT_PORT = 8080;
18
18
 
19
- type TestEdgeWsServerParams = {
19
+ type TestEdgeWsServerProps = {
20
20
  admitConnection?: Trigger;
21
21
  payloadDecoder?: (payload: Uint8Array) => any;
22
22
  messageHandler?: (payload: any) => Promise<Uint8Array | undefined>;
23
23
  };
24
24
 
25
- export const createTestEdgeWsServer = async (port = DEFAULT_PORT, params?: TestEdgeWsServerParams) => {
25
+ export const createTestEdgeWsServer = async (port = DEFAULT_PORT, params?: TestEdgeWsServerProps) => {
26
26
  const wsServer = new WebSocket.Server({
27
27
  port,
28
28
  verifyClient: createConnectionDelayHandler(params),
@@ -86,7 +86,7 @@ export const createTestEdgeWsServer = async (port = DEFAULT_PORT, params?: TestE
86
86
  };
87
87
  };
88
88
 
89
- const createConnectionDelayHandler = (params: TestEdgeWsServerParams | undefined) => {
89
+ const createConnectionDelayHandler = (params: TestEdgeWsServerProps | undefined) => {
90
90
  return (_: any, callback: (admit: boolean) => void) => {
91
91
  if (params?.admitConnection) {
92
92
  log('delaying edge connection admission');
@@ -116,7 +116,7 @@ const createResponseSender = (connection: () => WebSocketMuxer) => {
116
116
  };
117
117
  };
118
118
 
119
- const decodePayload = async (request: Message, params: TestEdgeWsServerParams | undefined) => {
119
+ const decodePayload = async (request: Message, params: TestEdgeWsServerProps | undefined) => {
120
120
  const requestPayload = params?.payloadDecoder
121
121
  ? params.payloadDecoder(request.payload!.value!)
122
122
  : protocol.getPayload(request, TextMessageSchema);
@@ -1 +0,0 @@
1
- {"inputs":{"src/protocol.ts":{"bytes":10133,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/defs.ts":{"bytes":1550,"imports":[{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/protocol.ts","kind":"import-statement","original":"./protocol"}],"format":"esm"},"src/edge-ws-muxer.ts":{"bytes":23993,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"}],"format":"esm"},"src/auth.ts":{"bytes":12117,"imports":[{"path":"@dxos/credentials","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keyring","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true}],"format":"esm"},"src/edge-identity.ts":{"bytes":3976,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true}],"format":"esm"},"src/edge-ws-connection.ts":{"bytes":37349,"imports":[{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"},{"path":"src/edge-ws-muxer.ts","kind":"import-statement","original":"./edge-ws-muxer"},{"path":"src/protocol.ts","kind":"import-statement","original":"./protocol"}],"format":"esm"},"src/errors.ts":{"bytes":1188,"imports":[],"format":"esm"},"src/utils.ts":{"bytes":1398,"imports":[],"format":"esm"},"src/edge-client.ts":{"bytes":37723,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"},{"path":"src/edge-identity.ts","kind":"import-statement","original":"./edge-identity"},{"path":"src/edge-ws-connection.ts","kind":"import-statement","original":"./edge-ws-connection"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/http-client.ts":{"bytes":7286,"imports":[{"path":"effect/Context","kind":"import-statement","external":true},{"path":"effect/Duration","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"effect/Schedule","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/edge-http-client.ts":{"bytes":50966,"imports":[{"path":"@effect/platform/FetchHttpClient","kind":"import-statement","external":true},{"path":"@effect/platform/HttpClient","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/edge-identity.ts","kind":"import-statement","original":"./edge-identity"},{"path":"src/http-client.ts","kind":"import-statement","original":"./http-client"},{"path":"src/utils.ts","kind":"import-statement","original":"./utils"}],"format":"esm"},"src/index.ts":{"bytes":1375,"imports":[{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/auth.ts","kind":"import-statement","original":"./auth"},{"path":"src/defs.ts","kind":"import-statement","original":"./defs"},{"path":"src/edge-client.ts","kind":"import-statement","original":"./edge-client"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"src/protocol.ts","kind":"import-statement","original":"./protocol"},{"path":"src/edge-http-client.ts","kind":"import-statement","original":"./edge-http-client"},{"path":"src/edge-identity.ts","kind":"import-statement","original":"./edge-identity"},{"path":"src/edge-ws-muxer.ts","kind":"import-statement","original":"./edge-ws-muxer"},{"path":"src/http-client.ts","kind":"import-statement","original":"./http-client"}],"format":"esm"},"src/testing/test-server.ts":{"bytes":4545,"imports":[{"path":"@dxos/node-std/http","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"format":"esm"},"src/testing/test-utils.ts":{"bytes":14017,"imports":[{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"src/defs.ts","kind":"import-statement","original":"../defs"},{"path":"src/edge-ws-muxer.ts","kind":"import-statement","original":"../edge-ws-muxer"},{"path":"src/protocol.ts","kind":"import-statement","original":"../protocol"}],"format":"esm"},"src/testing/index.ts":{"bytes":570,"imports":[{"path":"src/testing/test-server.ts","kind":"import-statement","original":"./test-server"},{"path":"src/testing/test-utils.ts","kind":"import-statement","original":"./test-utils"}],"format":"esm"}},"outputs":{"dist/lib/browser/edge-ws-muxer.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":93},"dist/lib/browser/edge-ws-muxer.mjs":{"imports":[{"path":"dist/lib/browser/chunk-VESGVCLQ.mjs","kind":"import-statement"}],"exports":["CLOUDFLARE_MESSAGE_MAX_BYTES","CLOUDFLARE_RPC_MAX_BYTES","WebSocketMuxer"],"entryPoint":"src/edge-ws-muxer.ts","inputs":{},"bytes":249},"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":73632},"dist/lib/browser/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-VESGVCLQ.mjs","kind":"import-statement"},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/credentials","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/keyring","kind":"import-statement","external":true},{"path":"@dxos/keys","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/client/services","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto","kind":"import-statement","external":true},{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@effect/platform/FetchHttpClient","kind":"import-statement","external":true},{"path":"@effect/platform/HttpClient","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Function","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/context","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"effect/Context","kind":"import-statement","external":true},{"path":"effect/Duration","kind":"import-statement","external":true},{"path":"effect/Effect","kind":"import-statement","external":true},{"path":"effect/Layer","kind":"import-statement","external":true},{"path":"effect/Schedule","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true}],"exports":["CLOUDFLARE_MESSAGE_MAX_BYTES","CLOUDFLARE_RPC_MAX_BYTES","EdgeClient","EdgeConnectionClosedError","EdgeHttpClient","EdgeIdentityChangedError","HttpConfig","Protocol","WebSocketMuxer","createChainEdgeIdentity","createDeviceEdgeIdentity","createEphemeralEdgeIdentity","createStubEdgeIdentity","createTestHaloEdgeIdentity","encodeAuthHeader","getTypename","handleAuthChallenge","protocol","toUint8Array","withLogging","withRetry","withRetryConfig"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":60},"src/auth.ts":{"bytesInOutput":2963},"src/edge-client.ts":{"bytesInOutput":10071},"src/edge-identity.ts":{"bytesInOutput":1158},"src/edge-ws-connection.ts":{"bytesInOutput":10215},"src/errors.ts":{"bytesInOutput":232},"src/utils.ts":{"bytesInOutput":244},"src/edge-http-client.ts":{"bytesInOutput":12338},"src/http-client.ts":{"bytesInOutput":1552}},"bytes":39767},"dist/lib/browser/testing/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":9559},"dist/lib/browser/testing/index.mjs":{"imports":[{"path":"dist/lib/browser/chunk-VESGVCLQ.mjs","kind":"import-statement"},{"path":"@dxos/node-std/http","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"isomorphic-ws","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true}],"exports":["DEFAULT_PORT","createTestEdgeWsServer","createTestServer","responseHandler"],"entryPoint":"src/testing/index.ts","inputs":{"src/testing/test-server.ts":{"bytesInOutput":1151},"src/testing/index.ts":{"bytesInOutput":0},"src/testing/test-utils.ts":{"bytesInOutput":3678}},"bytes":5103},"dist/lib/browser/chunk-VESGVCLQ.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":17259},"dist/lib/browser/chunk-VESGVCLQ.mjs":{"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf","kind":"import-statement","external":true},{"path":"@dxos/protocols/buf/dxos/edge/messenger_pb","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["CLOUDFLARE_MESSAGE_MAX_BYTES","CLOUDFLARE_RPC_MAX_BYTES","Protocol","WebSocketMuxer","getTypename","protocol","toUint8Array"],"inputs":{"src/edge-ws-muxer.ts":{"bytesInOutput":5688},"src/defs.ts":{"bytesInOutput":298},"src/protocol.ts":{"bytesInOutput":2604}},"bytes":8880}}}
@@ -1,303 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
-
3
- // src/edge-ws-muxer.ts
4
- import { Trigger } from "@dxos/async";
5
- import { log } from "@dxos/log";
6
- import { buf as buf2 } from "@dxos/protocols/buf";
7
- import { MessageSchema as MessageSchema2 } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
8
-
9
- // src/defs.ts
10
- import { bufWkt as bufWkt2 } from "@dxos/protocols/buf";
11
- import { SwarmRequestSchema, SwarmResponseSchema, TextMessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
12
-
13
- // src/protocol.ts
14
- import { invariant } from "@dxos/invariant";
15
- import { buf, bufWkt } from "@dxos/protocols/buf";
16
- import { MessageSchema } from "@dxos/protocols/buf/dxos/edge/messenger_pb";
17
- import { bufferToArray } from "@dxos/util";
18
- var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/protocol.ts";
19
- var getTypename = (typeName) => `type.googleapis.com/${typeName}`;
20
- var Protocol = class {
21
- _typeRegistry;
22
- constructor(types) {
23
- this._typeRegistry = buf.createRegistry(...types);
24
- }
25
- get typeRegistry() {
26
- return this._typeRegistry;
27
- }
28
- toJson(message) {
29
- try {
30
- return buf.toJson(MessageSchema, message, {
31
- registry: this.typeRegistry
32
- });
33
- } catch (err) {
34
- return {
35
- type: this.getPayloadType(message)
36
- };
37
- }
38
- }
39
- /**
40
- * Return the payload with the given type.
41
- */
42
- getPayload(message, type) {
43
- invariant(message.payload, void 0, {
44
- F: __dxlog_file,
45
- L: 40,
46
- S: this,
47
- A: [
48
- "message.payload",
49
- ""
50
- ]
51
- });
52
- const payloadTypename = this.getPayloadType(message);
53
- if (type && type.typeName !== payloadTypename) {
54
- throw new Error(`Unexpected payload type: ${payloadTypename}; expected ${type.typeName}`);
55
- }
56
- invariant(bufWkt.anyIs(message.payload, type), `Unexpected payload type: ${payloadTypename}}`, {
57
- F: __dxlog_file,
58
- L: 46,
59
- S: this,
60
- A: [
61
- "bufWkt.anyIs(message.payload, type)",
62
- "`Unexpected payload type: ${payloadTypename}}`"
63
- ]
64
- });
65
- const payload = bufWkt.anyUnpack(message.payload, this.typeRegistry);
66
- invariant(payload, `Empty payload: ${payloadTypename}}`, {
67
- F: __dxlog_file,
68
- L: 48,
69
- S: this,
70
- A: [
71
- "payload",
72
- "`Empty payload: ${payloadTypename}}`"
73
- ]
74
- });
75
- return payload;
76
- }
77
- /**
78
- * Get the payload type.
79
- */
80
- getPayloadType(message) {
81
- if (!message.payload) {
82
- return void 0;
83
- }
84
- const [, type] = message.payload.typeUrl.split("/");
85
- return type;
86
- }
87
- /**
88
- * Create a packed message.
89
- */
90
- createMessage(type, { source, target, payload, serviceId }) {
91
- return buf.create(MessageSchema, {
92
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
93
- source,
94
- target,
95
- serviceId,
96
- payload: payload ? bufWkt.anyPack(type, buf.create(type, payload)) : void 0
97
- });
98
- }
99
- };
100
- var toUint8Array = async (data) => {
101
- if (data instanceof Buffer) {
102
- return bufferToArray(data);
103
- }
104
- if (data instanceof Blob) {
105
- return new Uint8Array(await data.arrayBuffer());
106
- }
107
- throw new Error(`Unexpected datatype: ${data}`);
108
- };
109
-
110
- // src/defs.ts
111
- var protocol = new Protocol([
112
- SwarmRequestSchema,
113
- SwarmResponseSchema,
114
- TextMessageSchema,
115
- bufWkt2.AnySchema
116
- ]);
117
-
118
- // src/edge-ws-muxer.ts
119
- var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/edge-ws-muxer.ts";
120
- var FLAG_SEGMENT_SEQ = 1;
121
- var FLAG_SEGMENT_SEQ_TERMINATED = 1 << 1;
122
- var CLOUDFLARE_MESSAGE_MAX_BYTES = 1e3 * 1e3;
123
- var CLOUDFLARE_RPC_MAX_BYTES = 32 * 1e3 * 1e3;
124
- var MAX_CHUNK_LENGTH = 16384;
125
- var MAX_BUFFERED_AMOUNT = CLOUDFLARE_MESSAGE_MAX_BYTES;
126
- var BUFFER_FULL_BACKOFF_TIMEOUT = 100;
127
- var WebSocketMuxer = class {
128
- _ws;
129
- _inMessageAccumulator = /* @__PURE__ */ new Map();
130
- _outMessageChunks = /* @__PURE__ */ new Map();
131
- _outMessageChannelByService = /* @__PURE__ */ new Map();
132
- _sendTimeout;
133
- _maxChunkLength;
134
- constructor(_ws, config) {
135
- this._ws = _ws;
136
- this._maxChunkLength = config?.maxChunkLength ?? MAX_CHUNK_LENGTH;
137
- }
138
- /**
139
- * Resolves when all the message chunks get enqueued for sending.
140
- */
141
- async send(message) {
142
- const binary = buf2.toBinary(MessageSchema2, message);
143
- const channelId = this._resolveChannel(message);
144
- if (channelId == null && binary.byteLength > CLOUDFLARE_MESSAGE_MAX_BYTES || binary.byteLength > CLOUDFLARE_RPC_MAX_BYTES) {
145
- log.error("Large message dropped", {
146
- byteLength: binary.byteLength,
147
- serviceId: message.serviceId,
148
- payload: protocol.getPayloadType(message),
149
- channelId
150
- }, {
151
- F: __dxlog_file2,
152
- L: 62,
153
- S: this,
154
- C: (f, a) => f(...a)
155
- });
156
- return;
157
- }
158
- if (channelId == null || binary.length < this._maxChunkLength) {
159
- const flags = Buffer.from([
160
- 0
161
- ]);
162
- this._ws.send(Buffer.concat([
163
- flags,
164
- binary
165
- ]));
166
- return;
167
- }
168
- const terminatorSentTrigger = new Trigger();
169
- const messageChunks = [];
170
- for (let i = 0; i < binary.length; i += this._maxChunkLength) {
171
- const chunk = binary.slice(i, i + this._maxChunkLength);
172
- const isLastChunk = i + this._maxChunkLength >= binary.length;
173
- if (isLastChunk) {
174
- const flags = Buffer.from([
175
- FLAG_SEGMENT_SEQ | FLAG_SEGMENT_SEQ_TERMINATED,
176
- channelId
177
- ]);
178
- messageChunks.push({
179
- payload: Buffer.concat([
180
- flags,
181
- chunk
182
- ]),
183
- trigger: terminatorSentTrigger
184
- });
185
- } else {
186
- const flags = Buffer.from([
187
- FLAG_SEGMENT_SEQ,
188
- channelId
189
- ]);
190
- messageChunks.push({
191
- payload: Buffer.concat([
192
- flags,
193
- chunk
194
- ])
195
- });
196
- }
197
- }
198
- const queuedMessages = this._outMessageChunks.get(channelId);
199
- if (queuedMessages) {
200
- queuedMessages.push(...messageChunks);
201
- } else {
202
- this._outMessageChunks.set(channelId, messageChunks);
203
- }
204
- this._sendChunkedMessages();
205
- return terminatorSentTrigger.wait();
206
- }
207
- receiveData(data) {
208
- if ((data[0] & FLAG_SEGMENT_SEQ) === 0) {
209
- return buf2.fromBinary(MessageSchema2, data.slice(1));
210
- }
211
- const [flags, channelId, ...payload] = data;
212
- let chunkAccumulator = this._inMessageAccumulator.get(channelId);
213
- if (chunkAccumulator) {
214
- chunkAccumulator.push(Buffer.from(payload));
215
- } else {
216
- chunkAccumulator = [
217
- Buffer.from(payload)
218
- ];
219
- this._inMessageAccumulator.set(channelId, chunkAccumulator);
220
- }
221
- if ((flags & FLAG_SEGMENT_SEQ_TERMINATED) === 0) {
222
- return void 0;
223
- }
224
- const message = buf2.fromBinary(MessageSchema2, Buffer.concat(chunkAccumulator));
225
- this._inMessageAccumulator.delete(channelId);
226
- return message;
227
- }
228
- destroy() {
229
- if (this._sendTimeout) {
230
- clearTimeout(this._sendTimeout);
231
- this._sendTimeout = void 0;
232
- }
233
- for (const channelChunks of this._outMessageChunks.values()) {
234
- channelChunks.forEach((chunk) => chunk.trigger?.wake());
235
- }
236
- this._outMessageChunks.clear();
237
- this._inMessageAccumulator.clear();
238
- this._outMessageChannelByService.clear();
239
- }
240
- _sendChunkedMessages() {
241
- if (this._sendTimeout) {
242
- return;
243
- }
244
- const send = () => {
245
- if (this._ws.readyState === 2 || this._ws.readyState === 3) {
246
- log.warn("send called for closed websocket", void 0, {
247
- F: __dxlog_file2,
248
- L: 146,
249
- S: this,
250
- C: (f, a) => f(...a)
251
- });
252
- this._sendTimeout = void 0;
253
- return;
254
- }
255
- let timeout = 0;
256
- const emptyChannels = [];
257
- for (const [channelId, messages] of this._outMessageChunks.entries()) {
258
- if (this._ws.bufferedAmount != null) {
259
- if (this._ws.bufferedAmount + MAX_CHUNK_LENGTH > MAX_BUFFERED_AMOUNT) {
260
- timeout = BUFFER_FULL_BACKOFF_TIMEOUT;
261
- break;
262
- }
263
- }
264
- const nextMessage = messages.shift();
265
- if (nextMessage) {
266
- this._ws.send(nextMessage.payload);
267
- nextMessage.trigger?.wake();
268
- } else {
269
- emptyChannels.push(channelId);
270
- }
271
- }
272
- emptyChannels.forEach((channelId) => this._outMessageChunks.delete(channelId));
273
- if (this._outMessageChunks.size > 0) {
274
- this._sendTimeout = setTimeout(send, timeout);
275
- } else {
276
- this._sendTimeout = void 0;
277
- }
278
- };
279
- this._sendTimeout = setTimeout(send);
280
- }
281
- _resolveChannel(message) {
282
- if (!message.serviceId) {
283
- return void 0;
284
- }
285
- let id = this._outMessageChannelByService.get(message.serviceId);
286
- if (!id) {
287
- id = this._outMessageChannelByService.size + 1;
288
- this._outMessageChannelByService.set(message.serviceId, id);
289
- }
290
- return id;
291
- }
292
- };
293
-
294
- export {
295
- getTypename,
296
- Protocol,
297
- toUint8Array,
298
- protocol,
299
- CLOUDFLARE_MESSAGE_MAX_BYTES,
300
- CLOUDFLARE_RPC_MAX_BYTES,
301
- WebSocketMuxer
302
- };
303
- //# sourceMappingURL=chunk-JTBFRYNM.mjs.map