@phreshos/client 0.1.13 → 0.1.14
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/README.md +18 -3
- package/dist/channel.d.ts +2 -2
- package/dist/channel.js +1 -1
- package/dist/domain.d.ts +19 -4
- package/dist/domain.js +33 -2
- package/dist/host.d.ts +5 -18
- package/dist/host.js +1 -6
- package/dist/main.d.ts +1 -1
- package/dist/service.d.ts +2 -2
- package/dist/service.js +2 -6
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -63,11 +63,11 @@ only when no known decision can answer immediately and returns `null` if its
|
|
|
63
63
|
deadline expires. The desktop remains the internal enforcement boundary, but
|
|
64
64
|
permission ownership does not alter the public shape of `host`.
|
|
65
65
|
|
|
66
|
-
The Client Host exposes
|
|
67
|
-
|
|
66
|
+
The Client Host exposes only direct, exact Service handles. Creating a handle
|
|
67
|
+
does not read or start the Service and exposes no Service registry:
|
|
68
68
|
|
|
69
69
|
```ts
|
|
70
|
-
const service = host.service
|
|
70
|
+
const service = host.service({
|
|
71
71
|
program: "counter",
|
|
72
72
|
endpoint: "server",
|
|
73
73
|
name: "state"
|
|
@@ -147,6 +147,21 @@ authoritative, subscribable Window capability and its `window.local` physical
|
|
|
147
147
|
representation on this desktop. Local reads and updates have no events and do
|
|
148
148
|
not change Server state. `current.window` is only convenient access to the
|
|
149
149
|
executing Client's canonical Window; it has no additional authority.
|
|
150
|
+
|
|
151
|
+
A Program may converge its Clients on one named Process without a manual
|
|
152
|
+
`find()`/`create()` race:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
const shared = await program.process.findOrCreate({
|
|
156
|
+
name: "shared-server",
|
|
157
|
+
server: true,
|
|
158
|
+
client: false
|
|
159
|
+
})
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
The authoritative Core returns the existing Process only when its normalized
|
|
163
|
+
launch is equivalent; a conflicting launch rejects without changing it.
|
|
164
|
+
|
|
150
165
|
When both dimensions must change, `setGeometry({ position, size })` commits
|
|
151
166
|
them through one authoritative request and produces one `geometry` event.
|
|
152
167
|
Calling `move()` and `resize()` sequentially or through `Promise.all()` remains
|
package/dist/channel.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Channel as CoreChannel, ChannelCapture as CoreChannelCapture, ChannelEvents as CoreChannelEvents, ChannelMessage as CoreChannelMessage
|
|
1
|
+
import type { Channel as CoreChannel, ChannelCapture as CoreChannelCapture, ChannelEvents as CoreChannelEvents, ChannelMessage as CoreChannelMessage } from "@phreshos/core";
|
|
2
2
|
import { type Endpoint } from "./domain.js";
|
|
3
3
|
/** One value addressed to the current Client, with a client-visible sender. */
|
|
4
4
|
export type ChannelMessage<Payload = unknown> = CoreChannelMessage<Payload, Endpoint | null>;
|
|
@@ -7,6 +7,6 @@ export type ChannelEvents<Events extends object> = CoreChannelEvents<Events, End
|
|
|
7
7
|
/** Every event observable through the current Client's Channel. */
|
|
8
8
|
export type ChannelCapture<Events extends object = {}> = CoreChannelCapture<Events, Endpoint | null>;
|
|
9
9
|
/** Events explicitly accepted by the current Client. */
|
|
10
|
-
export interface Channel<Events extends object = {}> extends CoreChannel<Events, Endpoint | null
|
|
10
|
+
export interface Channel<Events extends object = {}> extends CoreChannel<Events, Endpoint | null> {
|
|
11
11
|
}
|
|
12
12
|
export declare const channel: Channel;
|
package/dist/channel.js
CHANGED
|
@@ -12,7 +12,7 @@ class ClientChannel extends Events {
|
|
|
12
12
|
publish(event, payload = undefined) {
|
|
13
13
|
wire.send("end-host", "emit", event, payload);
|
|
14
14
|
}
|
|
15
|
-
async enableService(
|
|
15
|
+
async enableService(name) { await enableCurrentService(name); }
|
|
16
16
|
async disableService() { await disableCurrentService(); }
|
|
17
17
|
}
|
|
18
18
|
function message(value) {
|
package/dist/domain.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import { Client as CoreClient, Endpoint as CoreEndpoint, Process as CoreProcess, Program as CoreProgram, Server as CoreServer, type AnswerCapture as CoreAnswerCapture, type AnswerMessage as CoreAnswerMessage, type AnswerObserver as CoreAnswerObserver, type AskCapture as CoreAskCapture, type AskMessage as CoreAskMessage, type AskObserver as CoreAskObserver, type Cleanup, type ClientTraffic as CoreClientTraffic, type ClientDeclaration, type EndpointTraffic as CoreEndpointTraffic, type
|
|
1
|
+
import { Client as CoreClient, Endpoint as CoreEndpoint, Process as CoreProcess, Program as CoreProgram, Server as CoreServer, type AnswerCapture as CoreAnswerCapture, type AnswerMessage as CoreAnswerMessage, type AnswerObserver as CoreAnswerObserver, type AskCapture as CoreAskCapture, type AskMessage as CoreAskMessage, type AskObserver as CoreAskObserver, type Cleanup, type ClientTraffic as CoreClientTraffic, type ClientDeclaration, type EndpointTraffic as CoreEndpointTraffic, type Exit, type Launch, type LocalWindow, type Permission, type Position, type ProgramProcess as CoreProgramProcess, type ServerTraffic as CoreServerTraffic, type Size, 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 interface HandleAddress {
|
|
4
4
|
identity: string;
|
|
5
5
|
reference: string;
|
|
6
6
|
}
|
|
7
|
+
export interface EndpointDeclarationRecord {
|
|
8
|
+
start: boolean;
|
|
9
|
+
hasService: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface ClientDeclarationRecord extends EndpointDeclarationRecord {
|
|
12
|
+
title: string | null;
|
|
13
|
+
size: Size | null;
|
|
14
|
+
position: Position | null;
|
|
15
|
+
layer: ClientDeclaration["layer"];
|
|
16
|
+
minimize: boolean | null;
|
|
17
|
+
}
|
|
7
18
|
export interface ProgramRecord {
|
|
8
19
|
reference: string;
|
|
9
20
|
identity: string;
|
|
@@ -11,8 +22,8 @@ export interface ProgramRecord {
|
|
|
11
22
|
name: string;
|
|
12
23
|
version: string | null;
|
|
13
24
|
description: string | null;
|
|
14
|
-
server:
|
|
15
|
-
client:
|
|
25
|
+
server: EndpointDeclarationRecord | null;
|
|
26
|
+
client: ClientDeclarationRecord | null;
|
|
16
27
|
}
|
|
17
28
|
export interface ProcessRecord {
|
|
18
29
|
reference: string;
|
|
@@ -37,7 +48,7 @@ export type Program<Events extends object = {}> = Omit<CoreProgram<Events>, "pro
|
|
|
37
48
|
readonly process: ProgramProcess;
|
|
38
49
|
};
|
|
39
50
|
/** Client-visible Process operations scoped to one Program. */
|
|
40
|
-
export type ProgramProcess = Omit<CoreProgramProcess, "list" | "first" | "last" | "find" | "create"> & {
|
|
51
|
+
export type ProgramProcess = Omit<CoreProgramProcess, "list" | "first" | "last" | "find" | "create" | "findOrCreate"> & {
|
|
41
52
|
/** Returns every live Process of this Program visible to the current Client. */
|
|
42
53
|
list(): Promise<Process[]>;
|
|
43
54
|
/** Returns the earliest-started visible live Process, or `null` when none exist. */
|
|
@@ -48,6 +59,10 @@ export type ProgramProcess = Omit<CoreProgramProcess, "list" | "first" | "last"
|
|
|
48
59
|
find(identityOrName: string): Promise<Process | null>;
|
|
49
60
|
/** Creates one Process of this same Program. */
|
|
50
61
|
create(launch?: Launch): Promise<Process>;
|
|
62
|
+
/** Finds the named Process or atomically creates it with the same resolved launch. */
|
|
63
|
+
findOrCreate(launch: Launch & Readonly<{
|
|
64
|
+
name: string;
|
|
65
|
+
}>): Promise<Process>;
|
|
51
66
|
};
|
|
52
67
|
/** Process handle visible inside a structurally isolated Client. */
|
|
53
68
|
export type Process<Events extends object = {}> = Omit<CoreProcess<Events>, "server" | "client" | "program" | "parent"> & {
|
package/dist/domain.js
CHANGED
|
@@ -33,8 +33,12 @@ class ProgramHandle extends ProgramBase {
|
|
|
33
33
|
get name() { return this.record.name; }
|
|
34
34
|
get version() { return this.record.version; }
|
|
35
35
|
get description() { return this.record.description; }
|
|
36
|
-
get server() {
|
|
37
|
-
|
|
36
|
+
get server() {
|
|
37
|
+
return this.record.server ? declaration("server", this.record.server) : null;
|
|
38
|
+
}
|
|
39
|
+
get client() {
|
|
40
|
+
return this.record.client ? clientDeclaration(this.record.client) : null;
|
|
41
|
+
}
|
|
38
42
|
update(record) {
|
|
39
43
|
if (record.reference !== this.reference)
|
|
40
44
|
throw new Error("A Program handle cannot become another Program");
|
|
@@ -51,6 +55,29 @@ class ProgramHandle extends ProgramBase {
|
|
|
51
55
|
async uninstall(everything = false) { await wire.request(["uninstall", undefined, everything]); }
|
|
52
56
|
async forget() { await wire.request(["forget"]); }
|
|
53
57
|
}
|
|
58
|
+
function declaration(endpoint, record) {
|
|
59
|
+
return Object.freeze({
|
|
60
|
+
start: record.start,
|
|
61
|
+
hasService: () => record.hasService,
|
|
62
|
+
docs: () => endpointDocs(endpoint, record.hasService)
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function clientDeclaration(record) {
|
|
66
|
+
return Object.freeze({
|
|
67
|
+
...declaration("client", record),
|
|
68
|
+
title: record.title,
|
|
69
|
+
size: record.size,
|
|
70
|
+
position: record.position,
|
|
71
|
+
layer: record.layer,
|
|
72
|
+
minimize: record.minimize
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async function endpointDocs(endpoint, declared) {
|
|
76
|
+
if (!declared)
|
|
77
|
+
return null;
|
|
78
|
+
const answer = await wire.request(["endpoint-docs", endpoint]);
|
|
79
|
+
return answer[0];
|
|
80
|
+
}
|
|
54
81
|
class ProgramProcessHandle {
|
|
55
82
|
constructor(program) {
|
|
56
83
|
bindEvents(this, scoped("program-process", program, programProcessEvent));
|
|
@@ -73,6 +100,10 @@ class ProgramProcessHandle {
|
|
|
73
100
|
const answer = await wire.request(["program-process-create", launch]);
|
|
74
101
|
return process(answer[0]);
|
|
75
102
|
}
|
|
103
|
+
async findOrCreate(launch) {
|
|
104
|
+
const answer = await wire.request(["program-process-find-or-create", launch]);
|
|
105
|
+
return process(answer[0]);
|
|
106
|
+
}
|
|
76
107
|
async exitAll() {
|
|
77
108
|
const answer = await wire.request(["program-process-exit-all"]);
|
|
78
109
|
return answer[0];
|
package/dist/host.d.ts
CHANGED
|
@@ -18,25 +18,12 @@ export interface Host {
|
|
|
18
18
|
serve(value: unknown): Promise<ServedFile>;
|
|
19
19
|
/** Performs an unrestricted server-side fetch on behalf of this Client. */
|
|
20
20
|
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
21
|
-
/** Prepares exact public service handles without exposing the service registry. */
|
|
22
|
-
readonly service: HostService;
|
|
23
|
-
}
|
|
24
|
-
/** Exact public service preparation available to a Client endpoint. */
|
|
25
|
-
export interface HostService {
|
|
26
21
|
/** Returns a precisely typed stable handle for either service endpoint. */
|
|
27
|
-
|
|
28
|
-
/** Returns a stable handle for one exact Server service identity. */
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
name: string;
|
|
33
|
-
}): ServerServiceHandler<ServiceEvents>;
|
|
34
|
-
/** Returns a stable handle for one exact Client service identity. */
|
|
35
|
-
prepare<ServiceEvents extends object = {}>(key: {
|
|
36
|
-
program: string;
|
|
37
|
-
endpoint: "client";
|
|
38
|
-
name: string;
|
|
39
|
-
}): ClientServiceHandler<ServiceEvents>;
|
|
22
|
+
service<Endpoint extends ServiceEndpoint>(key: ServiceAddress<Endpoint>): ServiceHandle<Endpoint, {}>;
|
|
23
|
+
/** Returns a typed stable handle for one exact Server service identity. */
|
|
24
|
+
service<ServiceEvents extends object>(key: ServiceAddress<"server">): ServerServiceHandler<ServiceEvents>;
|
|
25
|
+
/** Returns a typed stable handle for one exact Client service identity. */
|
|
26
|
+
service<ServiceEvents extends object>(key: ServiceAddress<"client">): ClientServiceHandler<ServiceEvents>;
|
|
40
27
|
}
|
|
41
28
|
/** Desktop capabilities available to this Client. */
|
|
42
29
|
export declare const host: Host;
|
package/dist/host.js
CHANGED
|
@@ -8,7 +8,7 @@ class ClientHost {
|
|
|
8
8
|
theme = new ClientTheme();
|
|
9
9
|
desktop = new ClientDesktop();
|
|
10
10
|
pointer = new ClientPointer();
|
|
11
|
-
service
|
|
11
|
+
service(key) { return prepareService(key); }
|
|
12
12
|
async serve(value) {
|
|
13
13
|
const source = content(value);
|
|
14
14
|
const channel = new MessageChannel();
|
|
@@ -80,11 +80,6 @@ class ClientHost {
|
|
|
80
80
|
return response;
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
-
class ClientHostService {
|
|
84
|
-
prepare(key) {
|
|
85
|
-
return prepareService(key);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
83
|
function requestHeaders(normalized, supplied) {
|
|
89
84
|
if (!supplied)
|
|
90
85
|
return [...normalized.entries()];
|
package/dist/main.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { host, type Host
|
|
1
|
+
export { host, type Host } from "./host.js";
|
|
2
2
|
export { type HostPointer, type PointerEvents, type PointerPosition } from "./pointer.js";
|
|
3
3
|
export { type DesktopEvents, type DesktopSize, type HostDesktop } from "./desktop.js";
|
|
4
4
|
export { current, type Current, type CurrentServer } from "./current.js";
|
package/dist/service.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ClientServiceHandler, type ServerServiceHandler, type
|
|
1
|
+
import { type ClientServiceHandler, type ServerServiceHandler, type ServiceHandler, type ServiceKey } from "@phreshos/core";
|
|
2
2
|
import type { HandleAddress } from "./domain.js";
|
|
3
3
|
export declare function prepareService<EventsMap extends object = {}>(key: ServiceKey & {
|
|
4
4
|
endpoint: "server";
|
|
@@ -7,7 +7,7 @@ export declare function prepareService<EventsMap extends object = {}>(key: Servi
|
|
|
7
7
|
endpoint: "client";
|
|
8
8
|
}): ClientServiceHandler<EventsMap>;
|
|
9
9
|
export declare function prepareService(key: ServiceKey): ServiceHandler;
|
|
10
|
-
export declare function enableCurrentService(
|
|
10
|
+
export declare function enableCurrentService(name: string): Promise<void>;
|
|
11
11
|
export declare function disableCurrentService(): Promise<void>;
|
|
12
12
|
export declare function endpointService<EventsMap extends object = {}>(target: HandleAddress | null, endpoint: "server"): Promise<ServerServiceHandler<EventsMap> | null>;
|
|
13
13
|
export declare function endpointService<EventsMap extends object = {}>(target: HandleAddress | null, endpoint: "client"): Promise<ClientServiceHandler<EventsMap> | null>;
|
package/dist/service.js
CHANGED
|
@@ -62,10 +62,6 @@ class ServerHandler extends ServerServiceBase {
|
|
|
62
62
|
async waitReady(timeout) {
|
|
63
63
|
await wire.request(["service-wait-ready", this.key, timeout], timeout);
|
|
64
64
|
}
|
|
65
|
-
async docs() {
|
|
66
|
-
const answer = await wire.request(["service-docs", this.key]);
|
|
67
|
-
return answer[0];
|
|
68
|
-
}
|
|
69
65
|
}
|
|
70
66
|
class ClientHandler extends ClientServiceBase {
|
|
71
67
|
key;
|
|
@@ -97,8 +93,8 @@ export function prepareService(key) {
|
|
|
97
93
|
: new ClientHandler(normalized);
|
|
98
94
|
});
|
|
99
95
|
}
|
|
100
|
-
export async function enableCurrentService(
|
|
101
|
-
await wire.request(["enable-service",
|
|
96
|
+
export async function enableCurrentService(name) {
|
|
97
|
+
await wire.request(["enable-service", name]);
|
|
102
98
|
}
|
|
103
99
|
export async function disableCurrentService() {
|
|
104
100
|
await wire.request(["disable-service"]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phreshos/client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "The SDK used by a Program's client endpoint.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"prepack": "node --run build"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@phreshos/core": "^0.1.
|
|
50
|
+
"@phreshos/core": "^0.1.11"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@msgpack/msgpack": "^3.1.3"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@phreshos/core": "^0.1.
|
|
56
|
+
"@phreshos/core": "^0.1.11",
|
|
57
57
|
"typescript": "^6.0.3"
|
|
58
58
|
}
|
|
59
59
|
}
|