@phreshos/server 0.1.10 → 0.1.11
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 +30 -2
- package/dist/current.js +2 -2
- package/dist/domain.d.ts +17 -12
- package/dist/domain.js +38 -26
- package/dist/host.d.ts +42 -37
- package/dist/host.js +52 -24
- package/dist/main.d.ts +3 -3
- package/dist/permissions.d.ts +2 -2
- package/dist/permissions.js +5 -5
- package/dist/service.d.ts +3 -3
- package/dist/service.js +12 -12
- package/dist/theme.js +4 -18
- package/dist/wire.d.ts +2 -0
- package/dist/wire.js +11 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -113,9 +113,37 @@ waiter.
|
|
|
113
113
|
Server Program handles add `install()` and `fork()`. Their filesystem areas
|
|
114
114
|
also expose `path()` and traversal-safe `resolve()`, because filesystem work is
|
|
115
115
|
performed locally in the Server SDK after the Host supplies only the area root.
|
|
116
|
-
Object descriptions passed to `host.
|
|
116
|
+
Object descriptions passed to `host.program.create()` therefore require an
|
|
117
117
|
explicit absolute storage root as well as at least one declared Endpoint.
|
|
118
118
|
|
|
119
|
+
Host registries are separated by owner. Reads, commands, and the complete
|
|
120
|
+
subscription contract live on their relevant capability rather than directly
|
|
121
|
+
on `host`:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
const programs = await host.program.list()
|
|
125
|
+
const program = await host.program.find("counter")
|
|
126
|
+
const processes = await host.process.list()
|
|
127
|
+
const serviceKeys = await host.service.list()
|
|
128
|
+
|
|
129
|
+
const stopPrograms = host.program.subscribe("create", value => undefined)
|
|
130
|
+
const stopProcesses = host.process.subscribe("exit", value => undefined)
|
|
131
|
+
const stopServices = host.service.subscribe("enable", key => undefined)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
A Program owns its scoped Process capability:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
const processes = await program.process.list()
|
|
138
|
+
const process = await program.process.find("worker")
|
|
139
|
+
const created = await program.process.create({ name: "worker" })
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`host.service.prepare(key)` creates the exact opaque service handle. The
|
|
143
|
+
handler exposes its authored `name`, `enabled()`, `waitReady()`, lifecycle
|
|
144
|
+
subscriptions, and channel; it does not expose its Program or Endpoint as
|
|
145
|
+
separate fields.
|
|
146
|
+
|
|
119
147
|
`program.icon()` requests a guaranteed PNG `Blob` in `small`, `medium`, or
|
|
120
148
|
`large` form without exposing the Program's source path or the system's private
|
|
121
149
|
asset-hosting address. Omitting the size selects `medium`.
|
|
@@ -137,6 +165,6 @@ await program.startup.disable()
|
|
|
137
165
|
```
|
|
138
166
|
|
|
139
167
|
The system validates this through the same launch contract as
|
|
140
|
-
`
|
|
168
|
+
`program.process.create()`. Setting startup does not create a Process immediately.
|
|
141
169
|
`uninstall(false)` preserves the configuration but makes it inactive until the
|
|
142
170
|
Program is installed again; removing everything deletes it.
|
package/dist/current.js
CHANGED
|
@@ -31,7 +31,7 @@ let ownerPromise = null;
|
|
|
31
31
|
let currentClient;
|
|
32
32
|
function owner() {
|
|
33
33
|
if (!ownerPromise) {
|
|
34
|
-
const resolving = wire.request(["process"]).then(answer => {
|
|
34
|
+
const resolving = wire.request(["current-process"]).then(answer => {
|
|
35
35
|
return process(answer[0], { client: currentClient });
|
|
36
36
|
});
|
|
37
37
|
const retained = resolving.catch(error => {
|
|
@@ -58,7 +58,7 @@ class ServerCurrent {
|
|
|
58
58
|
return answer[0] ? process(answer[0]) : null;
|
|
59
59
|
}
|
|
60
60
|
async program() {
|
|
61
|
-
const answer = await wire.request(["program"]);
|
|
61
|
+
const answer = await wire.request(["current-program"]);
|
|
62
62
|
return program(answer[0]);
|
|
63
63
|
}
|
|
64
64
|
async option(name) {
|
package/dist/domain.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Client as CoreClient, Endpoint as CoreEndpoint, Process as CoreProcess, Program as CoreProgram, Server as CoreServer, type AnswerCapture, type AskCapture, type Cleanup, type ClientDeclaration, type EndpointDeclaration, type Exit, type Launch, type
|
|
1
|
+
import { Client as CoreClient, Endpoint as CoreEndpoint, Process as CoreProcess, Program as CoreProgram, Server as CoreServer, type AnswerCapture, type AskCapture, type Cleanup, type ClientDeclaration, type EndpointDeclaration, type Exit, type Launch, type ProgramPermission, type ProgramProcess as CoreProgramProcess, type ProgramArea as CoreProgramArea, type TrafficMessage, type Window as CoreWindow, type WindowState } from "@phreshos/core";
|
|
2
2
|
import Events from "./events.js";
|
|
3
3
|
import { type ProgramStartup } from "./startup.js";
|
|
4
4
|
export interface HandleAddress {
|
|
@@ -40,7 +40,7 @@ export interface EndpointReference {
|
|
|
40
40
|
}
|
|
41
41
|
export type WindowRecord = WindowState;
|
|
42
42
|
/** Server-visible Program handle and privileged Program operations. */
|
|
43
|
-
export interface Program<Events extends object = {}> extends CoreProgram<Events> {
|
|
43
|
+
export interface Program<Events extends object = {}> extends Omit<CoreProgram<Events>, "process"> {
|
|
44
44
|
/** Persistent filesystem data shared by every Process of this Program. */
|
|
45
45
|
readonly data: ProgramArea;
|
|
46
46
|
/** Disposable filesystem data shared by every Process of this Program. */
|
|
@@ -48,21 +48,26 @@ export interface Program<Events extends object = {}> extends CoreProgram<Events>
|
|
|
48
48
|
/** Persistent Process launch used when the system starts. */
|
|
49
49
|
readonly startup: ProgramStartup;
|
|
50
50
|
/** Persistent permission decisions owned by this Program. */
|
|
51
|
-
readonly
|
|
51
|
+
readonly permission: ProgramPermission;
|
|
52
|
+
/** Operations and lifecycle observation for this Program's Processes. */
|
|
53
|
+
readonly process: ProgramProcess;
|
|
54
|
+
/** Installs this Program and returns the same handle. */
|
|
55
|
+
install(): Promise<this>;
|
|
56
|
+
/** Creates a new runtime Program with the supplied stable identity. */
|
|
57
|
+
fork(identity: string): Promise<Program>;
|
|
58
|
+
}
|
|
59
|
+
/** Server-visible Process operations scoped to one Program. */
|
|
60
|
+
export interface ProgramProcess extends Omit<CoreProgramProcess, "list" | "first" | "last" | "find" | "create"> {
|
|
52
61
|
/** Returns every live Process of this Program. */
|
|
53
|
-
|
|
62
|
+
list(): Promise<Process[]>;
|
|
54
63
|
/** Returns the earliest-started live Process, or `null` when none exist. */
|
|
55
|
-
|
|
64
|
+
first(): Promise<Process | null>;
|
|
56
65
|
/** Returns the latest-started live Process, or `null` when none exist. */
|
|
57
|
-
|
|
66
|
+
last(): Promise<Process | null>;
|
|
58
67
|
/** Finds a live Process by runtime identity or Program-local name. */
|
|
59
|
-
|
|
68
|
+
find(identityOrName: string): Promise<Process | null>;
|
|
60
69
|
/** Creates one Process of this Program. */
|
|
61
|
-
|
|
62
|
-
/** Installs this Program and returns the same handle. */
|
|
63
|
-
install(): Promise<this>;
|
|
64
|
-
/** Creates a new runtime Program with the supplied stable identity. */
|
|
65
|
-
fork(identity: string): Promise<Program>;
|
|
70
|
+
create(launch?: Launch): Promise<Process>;
|
|
66
71
|
}
|
|
67
72
|
/** Server-visible Process handle. */
|
|
68
73
|
export interface Process<Events extends object = {}> extends CoreProcess<Events> {
|
package/dist/domain.js
CHANGED
|
@@ -5,7 +5,7 @@ import Deadline from "./deadline.js";
|
|
|
5
5
|
import HandleRegistry from "./handle-registry.js";
|
|
6
6
|
import { area, sql, store } from "./storage.js";
|
|
7
7
|
import startup, {} from "./startup.js";
|
|
8
|
-
import
|
|
8
|
+
import permission from "./permissions.js";
|
|
9
9
|
import wire from "./wire.js";
|
|
10
10
|
import { endpointService } from "./service.js";
|
|
11
11
|
const handles = new HandleRegistry();
|
|
@@ -22,7 +22,8 @@ class ProgramHandle extends ProgramBase {
|
|
|
22
22
|
logs;
|
|
23
23
|
database;
|
|
24
24
|
startup;
|
|
25
|
-
|
|
25
|
+
permission;
|
|
26
|
+
process;
|
|
26
27
|
record;
|
|
27
28
|
constructor(record) {
|
|
28
29
|
super();
|
|
@@ -35,8 +36,9 @@ class ProgramHandle extends ProgramBase {
|
|
|
35
36
|
this.logs = sql("logs", this.address);
|
|
36
37
|
this.database = sql("database", this.address);
|
|
37
38
|
this.startup = startup(this.address);
|
|
38
|
-
this.
|
|
39
|
-
|
|
39
|
+
this.permission = permission(this.address);
|
|
40
|
+
this.process = new ProgramProcessHandle(this.address, record.reference);
|
|
41
|
+
bindEvents(this, scoped("program-host", record.reference, programEvent));
|
|
40
42
|
}
|
|
41
43
|
get name() { return this.record.name; }
|
|
42
44
|
get version() { return this.record.version; }
|
|
@@ -49,24 +51,6 @@ class ProgramHandle extends ProgramBase {
|
|
|
49
51
|
throw new Error("A Program handle cannot become another Program");
|
|
50
52
|
this.record = record;
|
|
51
53
|
}
|
|
52
|
-
async processes() {
|
|
53
|
-
const answer = await wire.request(["processes", this.address]);
|
|
54
|
-
return answer[0].map(record => process(record));
|
|
55
|
-
}
|
|
56
|
-
async firstProcess() {
|
|
57
|
-
return chronological(await this.processes())[0] ?? null;
|
|
58
|
-
}
|
|
59
|
-
async lastProcess() {
|
|
60
|
-
return chronological(await this.processes()).at(-1) ?? null;
|
|
61
|
-
}
|
|
62
|
-
async getProcess(identityOrName) {
|
|
63
|
-
const answer = await wire.request(["program-process", this.address, identityOrName]);
|
|
64
|
-
return answer[0] ? process(answer[0]) : null;
|
|
65
|
-
}
|
|
66
|
-
async createProcess(launch = {}) {
|
|
67
|
-
const answer = await wire.request(["create-process", this.address, launch]);
|
|
68
|
-
return process(answer[0]);
|
|
69
|
-
}
|
|
70
54
|
async icon(size = "medium") {
|
|
71
55
|
const answer = await wire.request(["icon", this.address, size]);
|
|
72
56
|
return new Blob([Uint8Array.from(answer[0])], { type: "image/png" });
|
|
@@ -89,8 +73,33 @@ class ProgramHandle extends ProgramBase {
|
|
|
89
73
|
async forget() {
|
|
90
74
|
await wire.request(["forget", this.address]);
|
|
91
75
|
}
|
|
76
|
+
}
|
|
77
|
+
class ProgramProcessHandle {
|
|
78
|
+
address;
|
|
79
|
+
constructor(address, reference) {
|
|
80
|
+
this.address = address;
|
|
81
|
+
bindEvents(this, scoped("program-process", reference, programProcessEvent));
|
|
82
|
+
}
|
|
83
|
+
async list() {
|
|
84
|
+
const answer = await wire.request(["program-process-list", this.address]);
|
|
85
|
+
return answer[0].map(record => process(record));
|
|
86
|
+
}
|
|
87
|
+
async first() {
|
|
88
|
+
return chronological(await this.list())[0] ?? null;
|
|
89
|
+
}
|
|
90
|
+
async last() {
|
|
91
|
+
return chronological(await this.list()).at(-1) ?? null;
|
|
92
|
+
}
|
|
93
|
+
async find(identityOrName) {
|
|
94
|
+
const answer = await wire.request(["program-process-find", this.address, identityOrName]);
|
|
95
|
+
return answer[0] ? process(answer[0]) : null;
|
|
96
|
+
}
|
|
97
|
+
async create(launch = {}) {
|
|
98
|
+
const answer = await wire.request(["program-process-create", this.address, launch]);
|
|
99
|
+
return process(answer[0]);
|
|
100
|
+
}
|
|
92
101
|
async exitAll() {
|
|
93
|
-
const answer = await wire.request(["exit-all", this.address]);
|
|
102
|
+
const answer = await wire.request(["program-process-exit-all", this.address]);
|
|
94
103
|
return answer[0];
|
|
95
104
|
}
|
|
96
105
|
}
|
|
@@ -339,13 +348,16 @@ function unscoped(subject, values) {
|
|
|
339
348
|
return values;
|
|
340
349
|
return values[0] === subject ? values.slice(1) : null;
|
|
341
350
|
}
|
|
342
|
-
function
|
|
351
|
+
function programProcessEvent(event, values) {
|
|
343
352
|
if (event === "endpointStart" || event === "endpointStop")
|
|
344
353
|
return lifecycleEndpoint(values[0], values[1]);
|
|
345
|
-
if (event === "
|
|
354
|
+
if (event === "create")
|
|
346
355
|
return process(values[0]);
|
|
347
|
-
if (event === "
|
|
356
|
+
if (event === "exit")
|
|
348
357
|
return { process: process(values[0]), ...exit(values[1], values[2]) };
|
|
358
|
+
return undefined;
|
|
359
|
+
}
|
|
360
|
+
function programEvent(event, values) {
|
|
349
361
|
if (event === "uninstall")
|
|
350
362
|
return { everythingRemoved: values[0] === true };
|
|
351
363
|
return undefined;
|
package/dist/host.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DesktopWallpaper, Exit, FileWallpaper, Layer, Position, ServedFile, ClientServiceHandler, ServerServiceHandler, Size, Subscribable, ThemeProperties, WritableTheme } from "@phreshos/core";
|
|
1
|
+
import type { DesktopWallpaper, Exit, FileWallpaper, Layer, Position, ServedFile, ClientServiceHandler, ServerServiceHandler, ServiceKey, ServiceRegistryEvents, Size, Subscribable, ThemeProperties, WritableTheme } from "@phreshos/core";
|
|
2
2
|
import { type Client, type Process, type Program, type Server } from "./domain.js";
|
|
3
3
|
/** Resolved production description for a Program's Server. */
|
|
4
4
|
export type ServerDescription = Readonly<{
|
|
@@ -55,68 +55,73 @@ export type ProgramDescription = Description & (Readonly<{
|
|
|
55
55
|
client: ClientDescription;
|
|
56
56
|
}>);
|
|
57
57
|
/** An uninstall reported with the affected Program and removal scope. */
|
|
58
|
-
export type
|
|
58
|
+
export type ProgramHostUninstall = Readonly<{
|
|
59
59
|
/** Program that left the installed state. */
|
|
60
60
|
program: Program;
|
|
61
61
|
/** Whether all installed resources, including storage, were removed. */
|
|
62
62
|
everythingRemoved: boolean;
|
|
63
63
|
}>;
|
|
64
64
|
/** A Process exit reported with the Process that ended. */
|
|
65
|
-
export type
|
|
65
|
+
export type ProcessHostExit = Exit & Readonly<{
|
|
66
66
|
/** Process that ended. */
|
|
67
67
|
process: Process;
|
|
68
68
|
}>;
|
|
69
69
|
/** Authoritative lifecycle events visible to the Server host. */
|
|
70
|
-
export type
|
|
71
|
-
/** One Process Endpoint entered a new live incarnation. */
|
|
72
|
-
endpointStart: Server | Client;
|
|
73
|
-
/** One Process Endpoint incarnation ended. */
|
|
74
|
-
endpointStop: Server | Client;
|
|
70
|
+
export type ProgramHostEvents = {
|
|
75
71
|
/** A Program entered the runtime registry. */
|
|
76
|
-
|
|
72
|
+
create: Program;
|
|
77
73
|
/** A Program left the runtime registry. */
|
|
78
|
-
|
|
74
|
+
forget: Program;
|
|
79
75
|
/** A Program entered the installed state. */
|
|
80
|
-
|
|
76
|
+
install: Program;
|
|
81
77
|
/** A Program left the installed state. */
|
|
82
|
-
|
|
78
|
+
uninstall: ProgramHostUninstall;
|
|
79
|
+
};
|
|
80
|
+
/** Authoritative Process lifecycle events visible to the Server host. */
|
|
81
|
+
export type ProcessHostEvents = {
|
|
82
|
+
/** One Process Endpoint entered a new live incarnation. */
|
|
83
|
+
endpointStart: Server | Client;
|
|
84
|
+
/** One Process Endpoint incarnation ended. */
|
|
85
|
+
endpointStop: Server | Client;
|
|
83
86
|
/** A Process entered the runtime set. */
|
|
84
|
-
|
|
87
|
+
create: Process;
|
|
85
88
|
/** A Process left the runtime set. */
|
|
86
|
-
|
|
89
|
+
exit: ProcessHostExit;
|
|
87
90
|
};
|
|
91
|
+
/** Authoritative Program registry available to a Server endpoint. */
|
|
92
|
+
export interface HostProgram extends Subscribable<ProgramHostEvents, never> {
|
|
93
|
+
list(onlyInstalled?: boolean): Promise<Program[]>;
|
|
94
|
+
find(identity: string): Promise<Program | null>;
|
|
95
|
+
create(source: ProgramDescription | string): Promise<Program>;
|
|
96
|
+
}
|
|
97
|
+
/** Authoritative Process registry available to a Server endpoint. */
|
|
98
|
+
export interface HostProcess extends Subscribable<ProcessHostEvents, never> {
|
|
99
|
+
list(): Promise<Process[]>;
|
|
100
|
+
find(identity: string): Promise<Process | null>;
|
|
101
|
+
}
|
|
102
|
+
/** Authoritative public service registry available to a Server endpoint. */
|
|
103
|
+
export interface HostService extends Subscribable<ServiceRegistryEvents, never> {
|
|
104
|
+
list(): Promise<readonly ServiceKey[]>;
|
|
105
|
+
prepare<ServiceEvents extends object = {}>(key: ServiceKey & {
|
|
106
|
+
endpoint: "server";
|
|
107
|
+
}): ServerServiceHandler<ServiceEvents>;
|
|
108
|
+
prepare<ServiceEvents extends object = {}>(key: ServiceKey & {
|
|
109
|
+
endpoint: "client";
|
|
110
|
+
}): ClientServiceHandler<ServiceEvents>;
|
|
111
|
+
}
|
|
88
112
|
/** Authoritative system capabilities available to a Server endpoint. */
|
|
89
|
-
export interface Host
|
|
113
|
+
export interface Host {
|
|
90
114
|
/** Observable system Theme authority. */
|
|
91
115
|
readonly theme: WritableTheme<ThemeProperties>;
|
|
92
116
|
/** Authoritative wallpaper visible before authentication. */
|
|
93
117
|
readonly signInWallpaper: FileWallpaper;
|
|
94
118
|
/** Authoritative wallpaper visible within authenticated desktops. */
|
|
95
119
|
readonly desktopWallpaper: DesktopWallpaper;
|
|
120
|
+
readonly program: HostProgram;
|
|
121
|
+
readonly process: HostProcess;
|
|
122
|
+
readonly service: HostService;
|
|
96
123
|
/** Publishes a value through the host and returns its public file metadata. */
|
|
97
124
|
serve(value: unknown): Promise<ServedFile>;
|
|
98
|
-
/** Returns all known Programs, optionally restricted to installed Programs. */
|
|
99
|
-
programs(onlyInstalled?: boolean): Promise<Program[]>;
|
|
100
|
-
/** Returns the Program with the given stable identity. */
|
|
101
|
-
getProgram(identity: string): Promise<Program>;
|
|
102
|
-
/** Creates a runtime Program from a description or description file path. */
|
|
103
|
-
createProgram(source: ProgramDescription | string): Promise<Program>;
|
|
104
|
-
/** Returns every live Process known to the authoritative host. */
|
|
105
|
-
processes(): Promise<Process[]>;
|
|
106
|
-
/** Returns the live Process with the given runtime identity. */
|
|
107
|
-
getProcess(identity: string): Promise<Process>;
|
|
108
|
-
/** Returns a stable handle for one exact Server service identity. */
|
|
109
|
-
service<ServiceEvents extends object = {}>(key: {
|
|
110
|
-
program: string;
|
|
111
|
-
endpoint: "server";
|
|
112
|
-
name: string;
|
|
113
|
-
}): ServerServiceHandler<ServiceEvents>;
|
|
114
|
-
/** Returns a stable handle for one exact Client service identity. */
|
|
115
|
-
service<ServiceEvents extends object = {}>(key: {
|
|
116
|
-
program: string;
|
|
117
|
-
endpoint: "client";
|
|
118
|
-
name: string;
|
|
119
|
-
}): ClientServiceHandler<ServiceEvents>;
|
|
120
125
|
}
|
|
121
126
|
/** Authoritative system capabilities for the currently executing Server. */
|
|
122
127
|
export declare const host: Host;
|
package/dist/host.js
CHANGED
|
@@ -4,55 +4,83 @@ import serve from "./served.js";
|
|
|
4
4
|
import ServerTheme from "./theme.js";
|
|
5
5
|
import { ServerDesktopWallpaper, ServerSignInWallpaper } from "./wallpaper.js";
|
|
6
6
|
import wire from "./wire.js";
|
|
7
|
-
import {
|
|
8
|
-
class ServerHost
|
|
7
|
+
import { prepareService } from "./service.js";
|
|
8
|
+
class ServerHost {
|
|
9
9
|
theme = new ServerTheme();
|
|
10
10
|
signInWallpaper = new ServerSignInWallpaper();
|
|
11
11
|
desktopWallpaper = new ServerDesktopWallpaper();
|
|
12
|
+
program = new ServerHostProgram();
|
|
13
|
+
process = new ServerHostProcess();
|
|
14
|
+
service = new ServerHostService();
|
|
15
|
+
serve(value) { return serve(value); }
|
|
16
|
+
}
|
|
17
|
+
class ServerHostProgram extends Events {
|
|
12
18
|
constructor() {
|
|
13
|
-
super((event, listener, impossible) => wire.on("host-
|
|
19
|
+
super((event, listener, impossible) => wire.on("host-program", event, (...values) => listener(hostProgramEvent(event, values)), null, impossible), observer => wire.onAll("host-program", (event, ...values) => {
|
|
14
20
|
if (typeof event === "string")
|
|
15
|
-
observer(event,
|
|
21
|
+
observer(event, hostProgramEvent(event, values));
|
|
16
22
|
}));
|
|
17
23
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const answer = await wire.request(["programs", onlyInstalled]);
|
|
24
|
+
async list(onlyInstalled = false) {
|
|
25
|
+
const answer = await wire.request(["host-program-list", onlyInstalled]);
|
|
21
26
|
return answer[0].map(program);
|
|
22
27
|
}
|
|
23
|
-
async
|
|
24
|
-
const answer = await wire.request(["program", identity]);
|
|
25
|
-
return program(answer[0]);
|
|
28
|
+
async find(identity) {
|
|
29
|
+
const answer = await wire.request(["host-program-find", identity]);
|
|
30
|
+
return answer[0] ? program(answer[0]) : null;
|
|
26
31
|
}
|
|
27
|
-
async
|
|
28
|
-
const answer = await wire.request(["
|
|
32
|
+
async create(source) {
|
|
33
|
+
const answer = await wire.request(["host-program-create", source]);
|
|
29
34
|
return program(answer[0]);
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
}
|
|
37
|
+
class ServerHostProcess extends Events {
|
|
38
|
+
constructor() {
|
|
39
|
+
super((event, listener, impossible) => wire.on("host-process", event, (...values) => listener(hostProcessEvent(event, values)), null, impossible), observer => wire.onAll("host-process", (event, ...values) => {
|
|
40
|
+
if (typeof event === "string")
|
|
41
|
+
observer(event, hostProcessEvent(event, values));
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
async list() {
|
|
45
|
+
const answer = await wire.request(["host-process-list"]);
|
|
33
46
|
return answer[0].map(record => process(record));
|
|
34
47
|
}
|
|
35
|
-
async
|
|
36
|
-
const answer = await wire.request(["process", identity]);
|
|
37
|
-
return process(answer[0]);
|
|
48
|
+
async find(identity) {
|
|
49
|
+
const answer = await wire.request(["host-process-find", identity]);
|
|
50
|
+
return answer[0] ? process(answer[0]) : null;
|
|
38
51
|
}
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
}
|
|
53
|
+
class ServerHostService extends Events {
|
|
54
|
+
constructor() {
|
|
55
|
+
super((event, listener) => wire.followServiceRegistry(event, listener), observer => wire.followServiceRegistry(null, (event, key) => {
|
|
56
|
+
if (typeof event === "string")
|
|
57
|
+
observer(event, key);
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
async list() {
|
|
61
|
+
const answer = await wire.request(["host-service-list"]);
|
|
62
|
+
return Object.freeze(answer[0]);
|
|
63
|
+
}
|
|
64
|
+
prepare(key) {
|
|
65
|
+
return prepareService(key);
|
|
41
66
|
}
|
|
42
67
|
}
|
|
43
|
-
function
|
|
68
|
+
function hostProcessEvent(event, values) {
|
|
44
69
|
if (event === "endpointStart" || event === "endpointStop")
|
|
45
70
|
return lifecycleEndpoint(values[1], values[2]);
|
|
46
|
-
if (event === "
|
|
71
|
+
if (event === "create") {
|
|
47
72
|
return process(values[1]);
|
|
48
73
|
}
|
|
49
|
-
if (event === "
|
|
74
|
+
if (event === "exit") {
|
|
50
75
|
return { process: process(values[1]), ...exit(values[2], values[3]) };
|
|
51
76
|
}
|
|
52
|
-
|
|
77
|
+
return values[0];
|
|
78
|
+
}
|
|
79
|
+
function hostProgramEvent(event, values) {
|
|
80
|
+
if (event === "create" || event === "forget" || event === "install") {
|
|
53
81
|
return program(values[1]);
|
|
54
82
|
}
|
|
55
|
-
if (event === "
|
|
83
|
+
if (event === "uninstall") {
|
|
56
84
|
return { program: program(values[1]), everythingRemoved: values[2] === true };
|
|
57
85
|
}
|
|
58
86
|
return values[0];
|
package/dist/main.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { host, type Host, type ClientDescription, type
|
|
1
|
+
export { host, type Host, type HostProcess, type HostProgram, type HostService, type ClientDescription, type ProcessHostEvents, type ProcessHostExit, type ProgramHostEvents, type ProgramHostUninstall, type ProgramDescription, type ServerDescription } from "./host.js";
|
|
2
2
|
export { current, type Current, type CurrentClient } from "./current.js";
|
|
3
3
|
export { type Answerer, type Channel } from "./channel.js";
|
|
4
4
|
export { type ProgramStartup } from "./startup.js";
|
|
5
5
|
export { ClientServiceHandler, ServerServiceHandler, ServiceHandler, type ClientServiceChannel, type ServerServiceChannel, type ServiceChannel, type ServiceKey, type ServiceLifecycleEvents } from "@phreshos/core";
|
|
6
|
-
export { Client, Endpoint, Process, Program, Server, type Window, type ProgramArea } from "./domain.js";
|
|
7
|
-
export type { AnswerCapture, AnswerMessage, AnswerObserver, Askable, AskCapture, AskMessage, AskObserver, Capture, Captures, ChannelCapture, ChannelEvents, ChannelMessage, ClientTraffic, ClientDeclaration, Cleanup, DirectoryStat, EndpointDeclaration, EndpointTraffic, EntryStat, EventMessage, EventName, EventObserver, EventOptions, EventSubscriber, Exit, FileStat, Launch, LaunchClient, Layer, LogKind, LogRecord, LogSource, Message, OtherStat, Outcome, Position, ProgramEvents,
|
|
6
|
+
export { Client, Endpoint, Process, Program, Server, type Window, type ProgramArea, type ProgramProcess } from "./domain.js";
|
|
7
|
+
export type { AnswerCapture, AnswerMessage, AnswerObserver, Askable, AskCapture, AskMessage, AskObserver, Capture, Captures, ChannelCapture, ChannelEvents, ChannelMessage, ClientTraffic, ClientDeclaration, Cleanup, DirectoryStat, EndpointDeclaration, EndpointTraffic, EntryStat, EventMessage, EventName, EventObserver, EventOptions, EventSubscriber, Exit, FileStat, Launch, LaunchClient, Layer, LogKind, LogRecord, LogSource, Message, OtherStat, Outcome, Position, ProgramEvents, ProgramPermission, ProgramProcessEvents, ProgramProcessExit, ProgramSql, ProgramStore, ProcessEvents, Publishable, ServedFile, ServerTraffic, Size, Subscribable, SubscribableEvents, SubscribableFallback, TimedAskable, TrafficCapture, TrafficEvents, TrafficMessage, Value, Theme, ThemeEvents, ThemeProperties, WallpaperLaunch, FileWallpaper, DesktopWallpaper, WritableTheme, WindowEvents, WindowGeometry, WindowLayer, WindowState } from "@phreshos/core";
|
package/dist/permissions.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ProgramPermission } from "@phreshos/core";
|
|
2
2
|
/** Creates the persistent permission manager for one Program handle. */
|
|
3
|
-
export default function
|
|
3
|
+
export default function permission(program: unknown): ProgramPermission;
|
package/dist/permissions.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import wire from "./wire.js";
|
|
2
2
|
/** Creates the persistent permission manager for one Program handle. */
|
|
3
|
-
export default function
|
|
3
|
+
export default function permission(program) {
|
|
4
4
|
return {
|
|
5
5
|
async get(name) {
|
|
6
|
-
const answer = await wire.request(["
|
|
6
|
+
const answer = await wire.request(["program-permission", program, "get", name]);
|
|
7
7
|
return answer[0];
|
|
8
8
|
},
|
|
9
9
|
async getAll() {
|
|
10
|
-
const answer = await wire.request(["
|
|
10
|
+
const answer = await wire.request(["program-permission", program, "getAll"]);
|
|
11
11
|
return answer[0];
|
|
12
12
|
},
|
|
13
13
|
async set(name, value) {
|
|
14
|
-
await wire.request(["
|
|
14
|
+
await wire.request(["program-permission", program, "set", name, value]);
|
|
15
15
|
},
|
|
16
16
|
async delete(name) {
|
|
17
|
-
await wire.request(["
|
|
17
|
+
await wire.request(["program-permission", program, "delete", name]);
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
}
|
package/dist/service.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type ClientServiceHandler, type ServerServiceDefinition, type ServerServiceHandler, type ServiceHandler, type ServiceKey } from "@phreshos/core";
|
|
2
2
|
import type { HandleAddress } from "./domain.js";
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function prepareService<EventsMap extends object = {}>(key: ServiceKey & {
|
|
4
4
|
endpoint: "server";
|
|
5
5
|
}): ServerServiceHandler<EventsMap>;
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function prepareService<EventsMap extends object = {}>(key: ServiceKey & {
|
|
7
7
|
endpoint: "client";
|
|
8
8
|
}): ClientServiceHandler<EventsMap>;
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function prepareService(key: ServiceKey): ServiceHandler;
|
|
10
10
|
export declare function enableCurrentService(definition: ServerServiceDefinition): 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>;
|
package/dist/service.js
CHANGED
|
@@ -47,22 +47,22 @@ class ClientChannelHandle extends Events {
|
|
|
47
47
|
}
|
|
48
48
|
class ServerHandler extends ServerServiceBase {
|
|
49
49
|
key;
|
|
50
|
-
program;
|
|
51
|
-
endpoint = "server";
|
|
52
50
|
name;
|
|
53
51
|
channel;
|
|
54
52
|
constructor(key) {
|
|
55
53
|
super();
|
|
56
54
|
this.key = key;
|
|
57
|
-
this.program = key.program;
|
|
58
55
|
this.name = key.name;
|
|
59
56
|
this.channel = new ServerChannelHandle(key);
|
|
60
57
|
bindEvents(this, new Events(...serviceEvents(key, "lifecycle")));
|
|
61
58
|
}
|
|
62
|
-
async
|
|
63
|
-
const answer = await wire.request(["service-
|
|
59
|
+
async enabled() {
|
|
60
|
+
const answer = await wire.request(["service-enabled", this.key]);
|
|
64
61
|
return answer[0];
|
|
65
62
|
}
|
|
63
|
+
async waitReady(timeout) {
|
|
64
|
+
await wire.request(["service-wait-ready", this.key, timeout], timeout);
|
|
65
|
+
}
|
|
66
66
|
async docs() {
|
|
67
67
|
const answer = await wire.request(["service-docs", this.key]);
|
|
68
68
|
return answer[0];
|
|
@@ -70,24 +70,24 @@ class ServerHandler extends ServerServiceBase {
|
|
|
70
70
|
}
|
|
71
71
|
class ClientHandler extends ClientServiceBase {
|
|
72
72
|
key;
|
|
73
|
-
program;
|
|
74
|
-
endpoint = "client";
|
|
75
73
|
name;
|
|
76
74
|
channel;
|
|
77
75
|
constructor(key) {
|
|
78
76
|
super();
|
|
79
77
|
this.key = key;
|
|
80
|
-
this.program = key.program;
|
|
81
78
|
this.name = key.name;
|
|
82
79
|
this.channel = new ClientChannelHandle(key);
|
|
83
80
|
bindEvents(this, new Events(...serviceEvents(key, "lifecycle")));
|
|
84
81
|
}
|
|
85
|
-
async
|
|
86
|
-
const answer = await wire.request(["service-
|
|
82
|
+
async enabled() {
|
|
83
|
+
const answer = await wire.request(["service-enabled", this.key]);
|
|
87
84
|
return answer[0];
|
|
88
85
|
}
|
|
86
|
+
async waitReady(timeout) {
|
|
87
|
+
await wire.request(["service-wait-ready", this.key, timeout], timeout);
|
|
88
|
+
}
|
|
89
89
|
}
|
|
90
|
-
export function
|
|
90
|
+
export function prepareService(key) {
|
|
91
91
|
if (!isServiceKey(key))
|
|
92
92
|
throw new Error("A complete service key is required");
|
|
93
93
|
const normalized = Object.freeze({ program: key.program, endpoint: key.endpoint, name: key.name });
|
|
@@ -106,7 +106,7 @@ export async function disableCurrentService() {
|
|
|
106
106
|
}
|
|
107
107
|
export async function endpointService(target, endpoint) {
|
|
108
108
|
const answer = await wire.request(["endpoint-service", target, endpoint]);
|
|
109
|
-
return answer[0] ?
|
|
109
|
+
return answer[0] ? prepareService(answer[0]) : null;
|
|
110
110
|
}
|
|
111
111
|
function serviceEvents(key, scope) {
|
|
112
112
|
return [
|
package/dist/theme.js
CHANGED
|
@@ -5,31 +5,17 @@ import wire from "./wire.js";
|
|
|
5
5
|
export default class ServerTheme extends Events {
|
|
6
6
|
constructor() {
|
|
7
7
|
super((event, listener, impossible) => wire.on("host-theme", event, value => {
|
|
8
|
-
|
|
9
|
-
listener(createThemeSnapshot(value));
|
|
8
|
+
listener(createThemeSnapshot(value));
|
|
10
9
|
}, null, impossible), observer => wire.onAll("host-theme", (event, value) => {
|
|
11
|
-
if (typeof event === "string"
|
|
10
|
+
if (typeof event === "string")
|
|
12
11
|
observer(event, createThemeSnapshot(value));
|
|
13
12
|
}));
|
|
14
13
|
}
|
|
15
14
|
async snapshot() {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
throw new Error("The host returned an invalid Theme snapshot");
|
|
19
|
-
return createThemeSnapshot(answer[0]);
|
|
15
|
+
const [theme] = await wire.request(["theme"]);
|
|
16
|
+
return createThemeSnapshot(theme);
|
|
20
17
|
}
|
|
21
18
|
update = async (theme) => {
|
|
22
19
|
await wire.request(["update-theme", theme]);
|
|
23
20
|
};
|
|
24
21
|
}
|
|
25
|
-
function isObject(value) {
|
|
26
|
-
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
27
|
-
return false;
|
|
28
|
-
const theme = value;
|
|
29
|
-
const surface = theme.surface;
|
|
30
|
-
return typeof theme.background === "string" && typeof theme.foreground === "string" && typeof theme.accent === "string"
|
|
31
|
-
&& typeof theme.spacing === "number" && typeof theme.radius === "number"
|
|
32
|
-
&& typeof surface === "object" && surface !== null
|
|
33
|
-
&& typeof surface.grain === "number" && typeof surface.animation === "number"
|
|
34
|
-
&& typeof surface.backdrop === "number" && typeof surface.opacity === "number";
|
|
35
|
-
}
|
package/dist/wire.d.ts
CHANGED
|
@@ -32,6 +32,8 @@ declare class Wire {
|
|
|
32
32
|
follow(target: HandleAddress | null, half: "server" | "client", event: string | null, handler: Handler, impossible?: Failure): Cleanup;
|
|
33
33
|
/** Follow one exact service lifecycle or application event route. */
|
|
34
34
|
followService(key: ServiceKey, scope: "lifecycle" | "channel", event: string | null, handler: Handler): Cleanup;
|
|
35
|
+
/** Follow lifecycle changes across the authoritative service registry. */
|
|
36
|
+
followServiceRegistry(event: string | null, handler: Handler): Cleanup;
|
|
35
37
|
private register;
|
|
36
38
|
private unregister;
|
|
37
39
|
private deliver;
|
package/dist/wire.js
CHANGED
|
@@ -69,7 +69,7 @@ class Wire {
|
|
|
69
69
|
/** Resolves this endpoint's Process address only for operations that need it. */
|
|
70
70
|
identity() {
|
|
71
71
|
if (!this.identityPromise) {
|
|
72
|
-
const resolving = this.request(["process"]).then(value => {
|
|
72
|
+
const resolving = this.request(["current-process"]).then(value => {
|
|
73
73
|
const [record] = value;
|
|
74
74
|
if (typeof record?.identity !== "string" || typeof record.reference !== "string") {
|
|
75
75
|
throw new Error("The host returned an invalid Process identity");
|
|
@@ -176,6 +176,16 @@ class Wire {
|
|
|
176
176
|
this.send("end-host", "service-unfollow", subscription);
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
|
+
/** Follow lifecycle changes across the authoritative service registry. */
|
|
180
|
+
followServiceRegistry(event, handler) {
|
|
181
|
+
const subscription = randomUUID();
|
|
182
|
+
const stop = this.on("service-registry-event", subscription, handler);
|
|
183
|
+
this.send("end-host", "service-registry-follow", subscription, event);
|
|
184
|
+
return once(() => {
|
|
185
|
+
stop();
|
|
186
|
+
this.send("end-host", "service-registry-unfollow", subscription);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
179
189
|
register(kind, route, event, subject, impossible) {
|
|
180
190
|
const subscription = randomUUID();
|
|
181
191
|
if (impossible)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phreshos/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "The SDK used by a Program's server endpoint.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"prepack": "node --run build"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"@phreshos/core": "^0.1.
|
|
49
|
+
"@phreshos/core": "^0.1.9"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@msgpack/msgpack": "^3.1.3"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@phreshos/core": "^0.1.
|
|
55
|
+
"@phreshos/core": "^0.1.9",
|
|
56
56
|
"@types/node": "^26.2.0",
|
|
57
57
|
"typescript": "^6.0.3"
|
|
58
58
|
}
|