@phreshos/client 0.1.54 → 0.1.55

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/wire.d.ts CHANGED
@@ -13,6 +13,8 @@ declare class Wire {
13
13
  private readonly every;
14
14
  private readonly impossible;
15
15
  private identityPromise;
16
+ /** Streams in messages cross as references; their chunks follow as boundary relay messages. */
17
+ private readonly relay;
16
18
  constructor();
17
19
  send(route: string, ...values: unknown[]): void;
18
20
  request(values: unknown[], timeout?: number, transfer?: Transferable[]): Promise<unknown>;
package/dist/wire.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import Deadline from "./deadline.js";
2
2
  import { defaultTimeout } from "./events.js";
3
3
  import captureClientOutput from "./log.js";
4
+ import { StreamRelay } from "@the-link/core";
4
5
  import { deserialize, serialize } from "@the-link/messagepack";
5
6
  /** The client endpoint's sole postMessage adapter. */
6
7
  class Wire {
@@ -11,6 +12,8 @@ class Wire {
11
12
  every = new Map();
12
13
  impossible = new Map();
13
14
  identityPromise = null;
15
+ /** Streams in messages cross as references; their chunks follow as boundary relay messages. */
16
+ relay = new StreamRelay(message => this.post(["boundary", "relay", ...message]));
14
17
  constructor() {
15
18
  window.addEventListener("message", event => {
16
19
  if (event.source !== this.parent || !Array.isArray(event.data))
@@ -20,7 +23,7 @@ class Wire {
20
23
  return;
21
24
  let message;
22
25
  try {
23
- message = deserialize(bytes, attachments);
26
+ message = deserialize(bytes, { attachments, streams: this.relay });
24
27
  }
25
28
  catch {
26
29
  return;
@@ -30,6 +33,10 @@ class Wire {
30
33
  const [route, ...values] = message;
31
34
  if (route === "boundary") {
32
35
  const [operation, ...rest] = values;
36
+ if (operation === "relay") {
37
+ this.relay.receive(rest);
38
+ return;
39
+ }
33
40
  if (operation === "impossible" && typeof rest[0] === "string" && typeof rest[1] === "string") {
34
41
  this.impossible.get(rest[0])?.(new Error(rest[1]));
35
42
  this.impossible.delete(rest[0]);
@@ -197,7 +204,7 @@ class Wire {
197
204
  if (!this.parent)
198
205
  return;
199
206
  const attachments = nativeAttachments(message, transfer);
200
- const bytes = serialize(message, attachments);
207
+ const bytes = serialize(message, { attachments, streams: this.relay });
201
208
  this.parent.postMessage([bytes, ...attachments], "*", [bytes.buffer, ...transfer]);
202
209
  }
203
210
  expectWithin(question, deadline) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phreshos/client",
3
- "version": "0.1.54",
3
+ "version": "0.1.55",
4
4
  "description": "The SDK used by a Program's client endpoint.",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",
@@ -49,7 +49,8 @@
49
49
  "@phreshos/core": "^0.1.64"
50
50
  },
51
51
  "dependencies": {
52
- "@the-link/messagepack": "^0.1.0"
52
+ "@the-link/core": "^0.4.0",
53
+ "@the-link/messagepack": "^0.2.0"
53
54
  },
54
55
  "devDependencies": {
55
56
  "@phreshos/core": "^0.1.64",