@phreshos/client 0.1.37 → 0.1.39

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/system.js CHANGED
@@ -3,80 +3,18 @@ import ClientAppearance from "./appearance.js";
3
3
  import wire from "./wire.js";
4
4
  import { prepareService } from "./service.js";
5
5
  import { uploads } from "./uploads.js";
6
- import controlledStream from "./controlled-stream.js";
7
6
  import Events from "./events.js";
8
7
  import { exit, process, program } from "./domain.js";
9
8
  import { systemStorage } from "./storage.js";
10
- import websocket from "./websocket.js";
9
+ import network from "./network.js";
11
10
  class ClientSystem {
12
11
  storage = systemStorage();
13
12
  appearance = new ClientAppearance();
14
13
  program = new SystemProgramHandle();
15
14
  process = new SystemProcessHandle();
16
15
  uploads = uploads;
17
- async forceCreateProgram(source) {
18
- const answer = await wire.request(["host-program-force-create", source]);
19
- return program(answer[0]);
20
- }
16
+ network = network;
21
17
  service(key) { return prepareService(key); }
22
- async fetch(input, init) {
23
- const request = new Request(input, {
24
- ...init,
25
- ...init?.body instanceof ReadableStream ? { duplex: "half" } : {}
26
- });
27
- const body = request.body;
28
- const control = new MessageChannel();
29
- const abort = () => control.port1.postMessage("abort");
30
- if (request.signal.aborted) {
31
- control.port1.close();
32
- control.port2.close();
33
- throw request.signal.reason;
34
- }
35
- request.signal.addEventListener("abort", abort, { once: true });
36
- const description = {
37
- body: body !== null,
38
- cache: request.cache,
39
- credentials: request.credentials,
40
- headers: requestHeaders(request.headers, init?.headers),
41
- integrity: request.integrity,
42
- keepalive: request.keepalive,
43
- method: request.method,
44
- mode: request.mode,
45
- redirect: request.redirect,
46
- referrer: request.referrer,
47
- referrerPolicy: request.referrerPolicy,
48
- url: request.url
49
- };
50
- let result;
51
- try {
52
- const answer = await wire.request(["fetch", description, body, control.port2], undefined, body ? [body, control.port2] : [control.port2]);
53
- result = answer[0];
54
- }
55
- catch (error) {
56
- abort();
57
- closeControl(request.signal, control.port1, abort);
58
- throw request.signal.aborted ? request.signal.reason : error;
59
- }
60
- const responseBody = result.body
61
- ? controlledStream(result.body, abort, () => closeControl(request.signal, control.port1, abort))
62
- : null;
63
- if (!responseBody)
64
- closeControl(request.signal, control.port1, abort);
65
- const response = new Response(responseBody, {
66
- headers: result.headers,
67
- status: result.status,
68
- statusText: result.statusText
69
- });
70
- Object.defineProperties(response, {
71
- redirected: { configurable: true, enumerable: true, value: result.redirected },
72
- type: { configurable: true, enumerable: true, value: result.type },
73
- url: { configurable: true, enumerable: true, value: result.url }
74
- });
75
- return response;
76
- }
77
- websocket(url, protocols) {
78
- return websocket(url, protocols);
79
- }
80
18
  async *shell(command, options = {}) {
81
19
  const { signal, ...settings } = options;
82
20
  for await (const event of wire.stream(["shell", command, settings], undefined, signal))
@@ -102,6 +40,10 @@ class SystemProgramHandle extends Events {
102
40
  const answer = await wire.request(["host-program-create", source]);
103
41
  return program(answer[0]);
104
42
  }
43
+ async forceCreate(source) {
44
+ const answer = await wire.request(["host-program-force-create", source]);
45
+ return program(answer[0]);
46
+ }
105
47
  }
106
48
  class SystemProcessHandle extends Events {
107
49
  constructor() {
@@ -133,20 +75,5 @@ function systemProgramEvent(event, values) {
133
75
  return { program: program(values[1]), everything: values[2] === true };
134
76
  return values[0];
135
77
  }
136
- function requestHeaders(normalized, supplied) {
137
- if (!supplied)
138
- return [...normalized.entries()];
139
- const explicit = supplied instanceof Headers
140
- ? [...supplied.entries()]
141
- : Array.isArray(supplied)
142
- ? supplied.map(([name, value]) => [name, value])
143
- : Object.entries(supplied);
144
- const names = new Set(explicit.map(([name]) => name.toLowerCase()));
145
- return [...normalized.entries()].filter(([name]) => !names.has(name.toLowerCase())).concat(explicit);
146
- }
147
- function closeControl(signal, port, abort) {
148
- signal.removeEventListener("abort", abort);
149
- port.close();
150
- }
151
78
  /** The global System represented through this Client runtime. */
152
79
  export const system = new ClientSystem();
package/dist/uploads.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { type SystemUploads, type Upload } from "@phreshos/core";
1
+ import { type FileStat, type SystemUploads, type Upload, type WritableContent } from "@phreshos/core";
2
2
  /** Flat upload access transported through the Client's Desktop boundary. */
3
3
  declare class ClientUploads implements SystemUploads {
4
4
  path(): Promise<string>;
5
- write(value: unknown): Promise<Upload>;
5
+ write(value: WritableContent): Promise<Upload>;
6
6
  stream(file: string): Promise<ReadableStream<Uint8Array>>;
7
7
  bytes(file: string): Promise<Uint8Array<ArrayBuffer>>;
8
8
  text(file: string): Promise<string>;
9
9
  json<Value>(file: string): Promise<Value>;
10
- stat(file: string): Promise<Upload | null>;
10
+ stat(file: string): Promise<FileStat | null>;
11
11
  }
12
12
  export declare const uploads: ClientUploads;
13
13
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phreshos/client",
3
- "version": "0.1.37",
3
+ "version": "0.1.39",
4
4
  "description": "The SDK used by a Program's client endpoint.",
5
5
  "type": "module",
6
6
  "main": "dist/main.js",
@@ -41,19 +41,19 @@
41
41
  "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
42
42
  "check": "tsc --noEmit && tsc -p tsconfig.test.json",
43
43
  "build": "node --run clean && tsc --noEmit false --outDir dist --rootDir source",
44
- "verify:completions": "node scripts/verify-completions.mjs",
45
- "verify:package": "node scripts/verify-package.mjs",
46
- "verify": "node --run check && node --run verify:completions && node --run build && node --run verify:package",
47
- "prepack": "node --run build"
44
+ "verify": "node --run check && node --run build && node --run test",
45
+ "prepack": "node --run build",
46
+ "test": "vitest run --project default"
48
47
  },
49
48
  "peerDependencies": {
50
- "@phreshos/core": "^0.1.41"
49
+ "@phreshos/core": "^0.1.43"
51
50
  },
52
51
  "dependencies": {
53
52
  "@the-link/messagepack": "^0.1.0"
54
53
  },
55
54
  "devDependencies": {
56
- "@phreshos/core": "^0.1.41",
57
- "typescript": "^6.0.3"
55
+ "@phreshos/core": "^0.1.43",
56
+ "typescript": "^6.0.3",
57
+ "vitest": "^4.1.10"
58
58
  }
59
59
  }
@@ -1,9 +0,0 @@
1
- import type { DesktopSurfaceEvents, DesktopSurfaceSource } from "@phreshos/core";
2
- import Events from "../events.js";
3
- /** Read-only access to the Desktop surface containing this Client Endpoint. */
4
- export default class ClientSurface extends Events<DesktopSurfaceEvents, never> implements DesktopSurfaceSource {
5
- constructor();
6
- snapshot(): Promise<Readonly<{
7
- size: import("@phreshos/core").DesktopSize;
8
- }>>;
9
- }