@phreshos/client 0.1.43 → 0.1.45
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/authentication.d.ts +3 -0
- package/dist/authentication.js +78 -0
- package/dist/desktop/desktop.js +6 -0
- package/dist/domain.d.ts +1 -2
- package/dist/domain.js +35 -53
- package/dist/system.js +43 -1
- package/package.json +3 -3
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Connection as CoreConnection, Session as CoreSession, parseConnectionSnapshot, parseSessionEndSnapshot, parseSessionSnapshot } from "@phreshos/core";
|
|
2
|
+
import HandleRegistry from "./handle-registry.js";
|
|
3
|
+
import { scoped } from "./domain.js";
|
|
4
|
+
import wire from "./wire.js";
|
|
5
|
+
const handles = new HandleRegistry();
|
|
6
|
+
class ConnectionHandle extends CoreConnection {
|
|
7
|
+
subscribe;
|
|
8
|
+
wait;
|
|
9
|
+
events;
|
|
10
|
+
identity;
|
|
11
|
+
constructor(snapshot) {
|
|
12
|
+
super();
|
|
13
|
+
this.identity = snapshot.identity;
|
|
14
|
+
const events = scoped("connection-host", this.identity, connectionEvent);
|
|
15
|
+
this.subscribe = events.subscribe;
|
|
16
|
+
this.wait = events.wait;
|
|
17
|
+
this.events = events.events;
|
|
18
|
+
}
|
|
19
|
+
async connected() {
|
|
20
|
+
const [snapshot] = await wire.request(["host-connection-state", this.identity]);
|
|
21
|
+
return parseConnectionSnapshot(snapshot).connected;
|
|
22
|
+
}
|
|
23
|
+
async session() {
|
|
24
|
+
const [snapshot] = await wire.request(["host-connection-session", this.identity]);
|
|
25
|
+
return snapshot === null ? null : session(snapshot);
|
|
26
|
+
}
|
|
27
|
+
async signIn() {
|
|
28
|
+
const [snapshot] = await wire.request(["host-connection-sign-in", this.identity]);
|
|
29
|
+
return session(snapshot);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class SessionHandle extends CoreSession {
|
|
33
|
+
subscribe;
|
|
34
|
+
wait;
|
|
35
|
+
events;
|
|
36
|
+
identity;
|
|
37
|
+
constructor(snapshot) {
|
|
38
|
+
super();
|
|
39
|
+
this.identity = snapshot.identity;
|
|
40
|
+
const events = scoped("session-host", this.identity, (event, values) => sessionEvent(this.identity, event, values));
|
|
41
|
+
this.subscribe = events.subscribe;
|
|
42
|
+
this.wait = events.wait;
|
|
43
|
+
this.events = events.events;
|
|
44
|
+
}
|
|
45
|
+
async valid() {
|
|
46
|
+
const [snapshot] = await wire.request(["host-session-state", this.identity]);
|
|
47
|
+
return parseSessionSnapshot(snapshot).valid;
|
|
48
|
+
}
|
|
49
|
+
async connections() {
|
|
50
|
+
const [snapshots] = await wire.request(["host-session-connections", this.identity]);
|
|
51
|
+
return snapshots.map(connection);
|
|
52
|
+
}
|
|
53
|
+
async signOut() {
|
|
54
|
+
await wire.request(["host-session-sign-out", this.identity]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export function connection(value) {
|
|
58
|
+
const snapshot = parseConnectionSnapshot(value);
|
|
59
|
+
return handles.obtain(`connection:${snapshot.identity}`, () => new ConnectionHandle(snapshot));
|
|
60
|
+
}
|
|
61
|
+
export function session(value) {
|
|
62
|
+
const snapshot = parseSessionSnapshot(value);
|
|
63
|
+
return handles.obtain(`session:${snapshot.identity}`, () => new SessionHandle(snapshot));
|
|
64
|
+
}
|
|
65
|
+
function connectionEvent(event, values) {
|
|
66
|
+
if (event === "sessionChange")
|
|
67
|
+
return values[0] === null ? null : session(values[0]);
|
|
68
|
+
if (event === "disconnect")
|
|
69
|
+
return undefined;
|
|
70
|
+
return values[0];
|
|
71
|
+
}
|
|
72
|
+
function sessionEvent(identity, event, values) {
|
|
73
|
+
if (event === "connectionAttach" || event === "connectionDetach")
|
|
74
|
+
return connection(values[0]);
|
|
75
|
+
if (event === "end")
|
|
76
|
+
return { reason: parseSessionEndSnapshot({ identity, valid: false, reason: values[0] }).reason };
|
|
77
|
+
return values[0];
|
|
78
|
+
}
|
package/dist/desktop/desktop.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import { connection } from "../authentication.js";
|
|
2
|
+
import wire from "../wire.js";
|
|
1
3
|
import ClientPreferences from "./preferences.js";
|
|
2
4
|
import ClientViewport from "./viewport.js";
|
|
3
5
|
/** Desktop access bound to the current Client Endpoint's Process boundary. */
|
|
4
6
|
class ClientDesktop {
|
|
5
7
|
viewport = new ClientViewport();
|
|
6
8
|
preferences = new ClientPreferences();
|
|
9
|
+
async connection() {
|
|
10
|
+
const [snapshot] = await wire.request(["desktop-connection"]);
|
|
11
|
+
return connection(snapshot);
|
|
12
|
+
}
|
|
7
13
|
}
|
|
8
14
|
/** The Desktop environment containing this Client Endpoint. */
|
|
9
15
|
export const desktop = new ClientDesktop();
|
package/dist/domain.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClientEndpoint as CoreClientEndpoint, Endpoint as CoreEndpoint, Process as CoreProcess, Program as CoreProgram, ServerEndpoint as CoreServerEndpoint, type AnswerCapture as CoreAnswerCapture, type AnswerMessage as CoreAnswerMessage, type AnswerOutcome, type AnswerSubscriber as CoreAnswerSubscriber, type AskCapture as CoreAskCapture, type AskMessage as CoreAskMessage, type AskSubscriber as CoreAskSubscriber, type Cleanup, type ClientTraffic as CoreClientTraffic, type ClientDeclaration, type EndpointReference as CoreEndpointReference, type EndpointSnapshot, type HandleAddress, type ProcessSnapshot, type ProgramSnapshot, type EndpointTraffic as CoreEndpointTraffic, type EndpointLifecycleEvents, type EndpointDeclaration, type Exit, type EventOptions, type LocalWindow, type
|
|
1
|
+
import { ClientEndpoint as CoreClientEndpoint, Endpoint as CoreEndpoint, Process as CoreProcess, Program as CoreProgram, ServerEndpoint as CoreServerEndpoint, type AnswerCapture as CoreAnswerCapture, type AnswerMessage as CoreAnswerMessage, type AnswerOutcome, type AnswerSubscriber as CoreAnswerSubscriber, type AskCapture as CoreAskCapture, type AskMessage as CoreAskMessage, type AskSubscriber as CoreAskSubscriber, type Cleanup, type ClientTraffic as CoreClientTraffic, type ClientDeclaration, type EndpointReference as CoreEndpointReference, type EndpointSnapshot, type HandleAddress, type ProcessSnapshot, type ProgramSnapshot, type EndpointTraffic as CoreEndpointTraffic, type EndpointLifecycleEvents, type EndpointDeclaration, type Exit, type EventOptions, type LocalWindow, type ProgramProcessRunEvent as CoreProgramProcessRunEvent, type ProgramProcessRunOptions as CoreProgramProcessRunOptions, type ServerTraffic as CoreServerTraffic, type TrafficMessage as CoreTrafficMessage, type TrafficCapture as CoreTrafficCapture, type TrafficEvents as CoreTrafficEvents, type Window as CoreWindow, type WindowState } from "@phreshos/core";
|
|
2
2
|
import Events from "./events.js";
|
|
3
3
|
export type { HandleAddress };
|
|
4
4
|
export type EndpointDeclarationRecord = EndpointDeclaration;
|
|
@@ -9,7 +9,6 @@ export type EndpointRecord = EndpointSnapshot;
|
|
|
9
9
|
export type EndpointReference = CoreEndpointReference;
|
|
10
10
|
export type WindowRecord = WindowState;
|
|
11
11
|
export type Program = CoreProgram;
|
|
12
|
-
export type ProgramProcess = CoreProgramProcess;
|
|
13
12
|
export type ProgramProcessRunEvent = CoreProgramProcessRunEvent;
|
|
14
13
|
export type ProgramProcessRunOptions = CoreProgramProcessRunOptions;
|
|
15
14
|
export type Process = CoreProcess;
|
package/dist/domain.js
CHANGED
|
@@ -21,7 +21,6 @@ class ProgramHandle extends CoreProgram {
|
|
|
21
21
|
database;
|
|
22
22
|
startup;
|
|
23
23
|
launch;
|
|
24
|
-
process;
|
|
25
24
|
permissions;
|
|
26
25
|
record;
|
|
27
26
|
constructor(record) {
|
|
@@ -37,7 +36,6 @@ class ProgramHandle extends CoreProgram {
|
|
|
37
36
|
this.startup = startup(this.address);
|
|
38
37
|
this.launch = launch(this.address);
|
|
39
38
|
this.permissions = programPermissions(this.address);
|
|
40
|
-
this.process = new ProgramProcessHandle(this.address, record.reference);
|
|
41
39
|
const events = scoped("program-host", record.reference, programEvent);
|
|
42
40
|
this.subscribe = events.subscribe;
|
|
43
41
|
this.wait = events.wait;
|
|
@@ -70,6 +68,37 @@ class ProgramHandle extends CoreProgram {
|
|
|
70
68
|
const answer = await wire.request(["installed", this.address]);
|
|
71
69
|
return answer[0];
|
|
72
70
|
}
|
|
71
|
+
async processes() {
|
|
72
|
+
const answer = await wire.request(["program-processes", this.address]);
|
|
73
|
+
return answer[0].map(record => process(record));
|
|
74
|
+
}
|
|
75
|
+
async firstProcess() {
|
|
76
|
+
return chronological(await this.processes())[0] ?? null;
|
|
77
|
+
}
|
|
78
|
+
async lastProcess() {
|
|
79
|
+
return chronological(await this.processes()).at(-1) ?? null;
|
|
80
|
+
}
|
|
81
|
+
async findProcess(identityOrName) {
|
|
82
|
+
const answer = await wire.request(["program-find-process", this.address, identityOrName]);
|
|
83
|
+
return answer[0] ? process(answer[0]) : null;
|
|
84
|
+
}
|
|
85
|
+
async createProcess(launch = {}) {
|
|
86
|
+
const answer = await wire.request(["program-create-process", this.address, launch]);
|
|
87
|
+
return process(answer[0]);
|
|
88
|
+
}
|
|
89
|
+
async findOrCreateProcess(launch) {
|
|
90
|
+
const answer = await wire.request(["program-find-or-create-process", this.address, launch]);
|
|
91
|
+
return process(answer[0]);
|
|
92
|
+
}
|
|
93
|
+
async exitProcesses() {
|
|
94
|
+
const answer = await wire.request(["program-exit-processes", this.address]);
|
|
95
|
+
return answer[0];
|
|
96
|
+
}
|
|
97
|
+
async *runProcess(launch = {}, options = {}) {
|
|
98
|
+
for await (const value of wire.stream(["run", this.address, launch], undefined, options.signal)) {
|
|
99
|
+
yield processRunEvent(value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
73
102
|
async *install(options = {}) {
|
|
74
103
|
for await (const value of wire.stream(["install", this.address, options])) {
|
|
75
104
|
yield programCommandChunk(value);
|
|
@@ -89,50 +118,6 @@ function programCommandChunk(value) {
|
|
|
89
118
|
}
|
|
90
119
|
return Object.freeze({ stream: chunk.stream, text: chunk.text });
|
|
91
120
|
}
|
|
92
|
-
class ProgramProcessHandle {
|
|
93
|
-
address;
|
|
94
|
-
subscribe;
|
|
95
|
-
wait;
|
|
96
|
-
events;
|
|
97
|
-
constructor(address, reference) {
|
|
98
|
-
this.address = address;
|
|
99
|
-
const events = scoped("program-process", reference, programProcessEvent);
|
|
100
|
-
this.subscribe = events.subscribe;
|
|
101
|
-
this.wait = events.wait;
|
|
102
|
-
this.events = events.events;
|
|
103
|
-
}
|
|
104
|
-
async list() {
|
|
105
|
-
const answer = await wire.request(["program-process-list", this.address]);
|
|
106
|
-
return answer[0].map(record => process(record));
|
|
107
|
-
}
|
|
108
|
-
async first() {
|
|
109
|
-
return chronological(await this.list())[0] ?? null;
|
|
110
|
-
}
|
|
111
|
-
async last() {
|
|
112
|
-
return chronological(await this.list()).at(-1) ?? null;
|
|
113
|
-
}
|
|
114
|
-
async find(identityOrName) {
|
|
115
|
-
const answer = await wire.request(["program-process-find", this.address, identityOrName]);
|
|
116
|
-
return answer[0] ? process(answer[0]) : null;
|
|
117
|
-
}
|
|
118
|
-
async create(launch = {}) {
|
|
119
|
-
const answer = await wire.request(["program-process-create", this.address, launch]);
|
|
120
|
-
return process(answer[0]);
|
|
121
|
-
}
|
|
122
|
-
async *run(launch = {}, options = {}) {
|
|
123
|
-
for await (const value of wire.stream(["run", this.address, launch], undefined, options.signal)) {
|
|
124
|
-
yield processRunEvent(value);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
async findOrCreate(launch) {
|
|
128
|
-
const answer = await wire.request(["program-process-find-or-create", this.address, launch]);
|
|
129
|
-
return process(answer[0]);
|
|
130
|
-
}
|
|
131
|
-
async exitAll() {
|
|
132
|
-
const answer = await wire.request(["program-process-exit-all", this.address]);
|
|
133
|
-
return answer[0];
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
121
|
function processRunEvent(value) {
|
|
137
122
|
const event = value;
|
|
138
123
|
if (event?.event === "started" && event.process) {
|
|
@@ -462,16 +447,13 @@ function unscoped(subject, values) {
|
|
|
462
447
|
return values;
|
|
463
448
|
return values[0] === subject ? values.slice(1) : null;
|
|
464
449
|
}
|
|
465
|
-
function
|
|
466
|
-
if (event === "
|
|
450
|
+
function programEvent(event, values) {
|
|
451
|
+
if (event === "processCreate")
|
|
467
452
|
return process(values[0]);
|
|
468
|
-
if (event === "
|
|
453
|
+
if (event === "processExit")
|
|
469
454
|
return { process: process(values[0]), ...exit(values[1], values[2]) };
|
|
470
|
-
return undefined;
|
|
471
|
-
}
|
|
472
|
-
function programEvent(event, values) {
|
|
473
455
|
if (event === "uninstall")
|
|
474
|
-
return values[0] === true;
|
|
456
|
+
return { purge: values[0] === true };
|
|
475
457
|
return undefined;
|
|
476
458
|
}
|
|
477
459
|
function processEvent(event, values) {
|
package/dist/system.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseShellEvent } from "@phreshos/core";
|
|
1
|
+
import { parseShellEvent, parseSessionEndSnapshot } from "@phreshos/core";
|
|
2
2
|
import ClientAppearance from "./appearance.js";
|
|
3
3
|
import wire from "./wire.js";
|
|
4
4
|
import { prepareService } from "./service.js";
|
|
@@ -7,11 +7,14 @@ import Events from "./events.js";
|
|
|
7
7
|
import { exit, process, program } from "./domain.js";
|
|
8
8
|
import { systemStorage } from "./storage.js";
|
|
9
9
|
import network from "./network.js";
|
|
10
|
+
import { connection, session } from "./authentication.js";
|
|
10
11
|
class ClientSystem {
|
|
11
12
|
storage = systemStorage();
|
|
12
13
|
appearance = new ClientAppearance();
|
|
13
14
|
program = new SystemProgramHandle();
|
|
14
15
|
process = new SystemProcessHandle();
|
|
16
|
+
connection = new SystemConnectionHandle();
|
|
17
|
+
session = new SystemSessionHandle();
|
|
15
18
|
uploads = uploads;
|
|
16
19
|
network = network;
|
|
17
20
|
service(key) { return prepareService(key); }
|
|
@@ -61,6 +64,38 @@ class SystemProcessHandle extends Events {
|
|
|
61
64
|
return answer[0] ? process(answer[0]) : null;
|
|
62
65
|
}
|
|
63
66
|
}
|
|
67
|
+
class SystemConnectionHandle extends Events {
|
|
68
|
+
constructor() {
|
|
69
|
+
super((event, listener, impossible) => wire.on("host-connection", event, (...values) => listener(systemConnectionEvent(event, values)), null, impossible), observer => wire.onAll("host-connection", (event, ...values) => {
|
|
70
|
+
if (typeof event === "string")
|
|
71
|
+
observer(event, systemConnectionEvent(event, values));
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
async list() {
|
|
75
|
+
const [snapshots] = await wire.request(["host-connection-list"]);
|
|
76
|
+
return snapshots.map(connection);
|
|
77
|
+
}
|
|
78
|
+
async find(identity) {
|
|
79
|
+
const [snapshot] = await wire.request(["host-connection-find", identity]);
|
|
80
|
+
return snapshot === null ? null : connection(snapshot);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
class SystemSessionHandle extends Events {
|
|
84
|
+
constructor() {
|
|
85
|
+
super((event, listener, impossible) => wire.on("host-session", event, (...values) => listener(systemSessionEvent(event, values)), null, impossible), observer => wire.onAll("host-session", (event, ...values) => {
|
|
86
|
+
if (typeof event === "string")
|
|
87
|
+
observer(event, systemSessionEvent(event, values));
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
async list() {
|
|
91
|
+
const [snapshots] = await wire.request(["host-session-list"]);
|
|
92
|
+
return snapshots.map(session);
|
|
93
|
+
}
|
|
94
|
+
async find(identity) {
|
|
95
|
+
const [snapshot] = await wire.request(["host-session-find", identity]);
|
|
96
|
+
return snapshot === null ? null : session(snapshot);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
64
99
|
function systemProcessEvent(event, values) {
|
|
65
100
|
if (event === "create")
|
|
66
101
|
return process(values[1]);
|
|
@@ -75,5 +110,12 @@ function systemProgramEvent(event, values) {
|
|
|
75
110
|
return { program: program(values[1]), purge: values[2] === true };
|
|
76
111
|
return values[0];
|
|
77
112
|
}
|
|
113
|
+
function systemConnectionEvent(_event, values) {
|
|
114
|
+
return connection(values[1]);
|
|
115
|
+
}
|
|
116
|
+
function systemSessionEvent(event, values) {
|
|
117
|
+
const handle = session(values[1]);
|
|
118
|
+
return event === "end" ? { session: handle, reason: parseSessionEndSnapshot({ ...values[1], reason: values[2] }).reason } : handle;
|
|
119
|
+
}
|
|
78
120
|
/** The global System represented through this Client runtime. */
|
|
79
121
|
export const system = new ClientSystem();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phreshos/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.45",
|
|
4
4
|
"description": "The SDK used by a Program's client endpoint.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"test": "vitest run --project default"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@phreshos/core": "^0.1.
|
|
49
|
+
"@phreshos/core": "^0.1.52"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@the-link/messagepack": "^0.1.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@phreshos/core": "^0.1.
|
|
55
|
+
"@phreshos/core": "^0.1.52",
|
|
56
56
|
"typescript": "^6.0.3",
|
|
57
57
|
"vitest": "^4.1.10"
|
|
58
58
|
}
|