@phreshos/server 0.1.11 → 0.1.12

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 CHANGED
@@ -124,11 +124,9 @@ on `host`:
124
124
  const programs = await host.program.list()
125
125
  const program = await host.program.find("counter")
126
126
  const processes = await host.process.list()
127
- const serviceKeys = await host.service.list()
128
127
 
129
128
  const stopPrograms = host.program.subscribe("create", value => undefined)
130
129
  const stopProcesses = host.process.subscribe("exit", value => undefined)
131
- const stopServices = host.service.subscribe("enable", key => undefined)
132
130
  ```
133
131
 
134
132
  A Program owns its scoped Process capability:
@@ -137,12 +135,24 @@ A Program owns its scoped Process capability:
137
135
  const processes = await program.process.list()
138
136
  const process = await program.process.find("worker")
139
137
  const created = await program.process.create({ name: "worker" })
138
+ const shared = await program.process.findOrCreate({
139
+ name: "shared-server",
140
+ server: true,
141
+ client: false
142
+ })
140
143
  ```
141
144
 
142
- `host.service.prepare(key)` creates the exact opaque service handle. The
145
+ `findOrCreate()` is atomic at the authoritative Core. Concurrent equivalent
146
+ launches converge on one named Process; a different launch for that name
147
+ rejects instead of reconfiguring the existing Process.
148
+
149
+ `host.service(key)` creates the exact opaque service handle. The
143
150
  handler exposes its authored `name`, `enabled()`, `waitReady()`, lifecycle
144
151
  subscriptions, and channel; it does not expose its Program or Endpoint as
145
- separate fields.
152
+ separate fields. Services are not a second public registry: inspect Programs
153
+ and their Endpoint declarations. `program.server?.hasService()` identifies a
154
+ declared Service capability, while `await program.server?.docs()` reads its
155
+ installed policy and API documentation before the Endpoint starts.
146
156
 
147
157
  `program.icon()` requests a guaranteed PNG `Blob` in `small`, `medium`, or
148
158
  `large` form without exposing the Program's source path or the system's private
package/dist/channel.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { Channel as CoreChannel, ChannelMessage, Cleanup, ServerServiceDefinition } from "@phreshos/core";
1
+ import type { Channel as CoreChannel, ChannelMessage, Cleanup } from "@phreshos/core";
2
2
  import { type Endpoint } from "./domain.js";
3
3
  /** Handles one question addressed to the current Server. */
4
4
  export type Answerer<Payload = unknown, Result = undefined> = (message: ChannelMessage<Payload>) => Result | Promise<Result>;
5
5
  /** Events and questions explicitly accepted by the current Server. */
6
- export interface Channel<Events extends object = {}> extends CoreChannel<Events, Endpoint, ServerServiceDefinition> {
6
+ export interface Channel<Events extends object = {}> extends CoreChannel<Events, Endpoint> {
7
7
  /** Registers one answerer; omitting its return produces `undefined`. */
8
8
  answer<Payload = unknown, Result = undefined>(event: string, answerer: Answerer<Payload, Result>): Cleanup;
9
9
  }
package/dist/channel.js CHANGED
@@ -12,7 +12,7 @@ class ServerChannel extends Events {
12
12
  publish(event, payload = undefined) {
13
13
  wire.send("end-host", "emit", event, payload);
14
14
  }
15
- async enableService(definition) { await enableCurrentService(definition); }
15
+ async enableService(name) { await enableCurrentService(name); }
16
16
  async disableService() { await disableCurrentService(); }
17
17
  answer(event, answerer) {
18
18
  return wire.answer("end-end", event, value => answerer(message(value)));
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 ProgramPermission, type ProgramProcess as CoreProgramProcess, type ProgramArea as CoreProgramArea, type TrafficMessage, type Window as CoreWindow, type WindowState } from "@phreshos/core";
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 Exit, type Launch, type Position, type ProgramPermission, type ProgramProcess as CoreProgramProcess, type ProgramArea as CoreProgramArea, type Size, 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 {
@@ -13,6 +13,17 @@ export interface ProgramArea extends CoreProgramArea {
13
13
  resolve(...path: string[]): Promise<string>;
14
14
  }
15
15
  /** Client-safe Program data transported by the authoritative host. */
16
+ export interface EndpointDeclarationRecord {
17
+ start: boolean;
18
+ hasService: boolean;
19
+ }
20
+ export interface ClientDeclarationRecord extends EndpointDeclarationRecord {
21
+ title: string | null;
22
+ size: Size | null;
23
+ position: Position | null;
24
+ layer: ClientDeclaration["layer"];
25
+ minimize: boolean | null;
26
+ }
16
27
  export interface ProgramRecord {
17
28
  reference: string;
18
29
  identity: string;
@@ -20,8 +31,8 @@ export interface ProgramRecord {
20
31
  name: string;
21
32
  version: string | null;
22
33
  description: string | null;
23
- server: EndpointDeclaration | null;
24
- client: ClientDeclaration | null;
34
+ server: EndpointDeclarationRecord | null;
35
+ client: ClientDeclarationRecord | null;
25
36
  }
26
37
  /** Process data transported with every Endpoint reference. */
27
38
  export interface ProcessRecord {
@@ -57,7 +68,7 @@ export interface Program<Events extends object = {}> extends Omit<CoreProgram<Ev
57
68
  fork(identity: string): Promise<Program>;
58
69
  }
59
70
  /** Server-visible Process operations scoped to one Program. */
60
- export interface ProgramProcess extends Omit<CoreProgramProcess, "list" | "first" | "last" | "find" | "create"> {
71
+ export interface ProgramProcess extends Omit<CoreProgramProcess, "list" | "first" | "last" | "find" | "create" | "findOrCreate"> {
61
72
  /** Returns every live Process of this Program. */
62
73
  list(): Promise<Process[]>;
63
74
  /** Returns the earliest-started live Process, or `null` when none exist. */
@@ -68,6 +79,10 @@ export interface ProgramProcess extends Omit<CoreProgramProcess, "list" | "first
68
79
  find(identityOrName: string): Promise<Process | null>;
69
80
  /** Creates one Process of this Program. */
70
81
  create(launch?: Launch): Promise<Process>;
82
+ /** Finds the named Process or atomically creates it with the same resolved launch. */
83
+ findOrCreate(launch: Launch & Readonly<{
84
+ name: string;
85
+ }>): Promise<Process>;
71
86
  }
72
87
  /** Server-visible Process handle. */
73
88
  export interface Process<Events extends object = {}> extends CoreProcess<Events> {
package/dist/domain.js CHANGED
@@ -43,8 +43,12 @@ class ProgramHandle extends ProgramBase {
43
43
  get name() { return this.record.name; }
44
44
  get version() { return this.record.version; }
45
45
  get description() { return this.record.description; }
46
- get server() { return this.record.server; }
47
- get client() { return this.record.client; }
46
+ get server() {
47
+ return this.record.server ? declaration(this.address, "server", this.record.server) : null;
48
+ }
49
+ get client() {
50
+ return this.record.client ? clientDeclaration(this.address, this.record.client) : null;
51
+ }
48
52
  get address() { return { identity: this.identity, reference: this.reference }; }
49
53
  update(record) {
50
54
  if (record.reference !== this.reference)
@@ -74,6 +78,29 @@ class ProgramHandle extends ProgramBase {
74
78
  await wire.request(["forget", this.address]);
75
79
  }
76
80
  }
81
+ function declaration(address, endpoint, record) {
82
+ return Object.freeze({
83
+ start: record.start,
84
+ hasService: () => record.hasService,
85
+ docs: () => endpointDocs(address, endpoint, record.hasService)
86
+ });
87
+ }
88
+ function clientDeclaration(address, record) {
89
+ return Object.freeze({
90
+ ...declaration(address, "client", record),
91
+ title: record.title,
92
+ size: record.size,
93
+ position: record.position,
94
+ layer: record.layer,
95
+ minimize: record.minimize
96
+ });
97
+ }
98
+ async function endpointDocs(address, endpoint, declared) {
99
+ if (!declared)
100
+ return null;
101
+ const answer = await wire.request(["endpoint-docs", address, endpoint]);
102
+ return answer[0];
103
+ }
77
104
  class ProgramProcessHandle {
78
105
  address;
79
106
  constructor(address, reference) {
@@ -98,6 +125,10 @@ class ProgramProcessHandle {
98
125
  const answer = await wire.request(["program-process-create", this.address, launch]);
99
126
  return process(answer[0]);
100
127
  }
128
+ async findOrCreate(launch) {
129
+ const answer = await wire.request(["program-process-find-or-create", this.address, launch]);
130
+ return process(answer[0]);
131
+ }
101
132
  async exitAll() {
102
133
  const answer = await wire.request(["program-process-exit-all", this.address]);
103
134
  return answer[0];
package/dist/host.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { DesktopWallpaper, Exit, FileWallpaper, Layer, Position, ServedFile, ClientServiceHandler, ServerServiceHandler, ServiceKey, ServiceRegistryEvents, Size, Subscribable, ThemeProperties, WritableTheme } from "@phreshos/core";
1
+ import type { DesktopWallpaper, Exit, FileWallpaper, Layer, Position, ServedFile, ClientServiceHandler, ServerServiceHandler, ServiceKey, 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<{
@@ -6,6 +6,8 @@ export type ServerDescription = Readonly<{
6
6
  location: string;
7
7
  /** Whether newly created Processes start this Server by default. */
8
8
  start?: boolean;
9
+ /** Absolute Markdown file documenting the Service this Server may expose. */
10
+ serviceDocs?: string;
9
11
  /** Command used to install the Server's production dependencies. */
10
12
  installCommand?: string;
11
13
  /** Command used to start the Server from its production directory. */
@@ -17,6 +19,8 @@ export type ClientDescription = Readonly<{
17
19
  location: string;
18
20
  /** Whether newly created Processes start this Client by default. */
19
21
  start?: boolean;
22
+ /** Absolute Markdown file documenting the Service this Client may expose. */
23
+ serviceDocs?: string;
20
24
  /** Default Window title. */
21
25
  title?: string;
22
26
  /** Default Window size. */
@@ -99,16 +103,6 @@ export interface HostProcess extends Subscribable<ProcessHostEvents, never> {
99
103
  list(): Promise<Process[]>;
100
104
  find(identity: string): Promise<Process | null>;
101
105
  }
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
- }
112
106
  /** Authoritative system capabilities available to a Server endpoint. */
113
107
  export interface Host {
114
108
  /** Observable system Theme authority. */
@@ -119,7 +113,13 @@ export interface Host {
119
113
  readonly desktopWallpaper: DesktopWallpaper;
120
114
  readonly program: HostProgram;
121
115
  readonly process: HostProcess;
122
- readonly service: HostService;
116
+ /** Returns a stable handle for one exact Service identity. */
117
+ service<ServiceEvents extends object = {}>(key: ServiceKey & {
118
+ endpoint: "server";
119
+ }): ServerServiceHandler<ServiceEvents>;
120
+ service<ServiceEvents extends object = {}>(key: ServiceKey & {
121
+ endpoint: "client";
122
+ }): ClientServiceHandler<ServiceEvents>;
123
123
  /** Publishes a value through the host and returns its public file metadata. */
124
124
  serve(value: unknown): Promise<ServedFile>;
125
125
  }
package/dist/host.js CHANGED
@@ -11,7 +11,7 @@ class ServerHost {
11
11
  desktopWallpaper = new ServerDesktopWallpaper();
12
12
  program = new ServerHostProgram();
13
13
  process = new ServerHostProcess();
14
- service = new ServerHostService();
14
+ service(key) { return prepareService(key); }
15
15
  serve(value) { return serve(value); }
16
16
  }
17
17
  class ServerHostProgram extends Events {
@@ -50,21 +50,6 @@ class ServerHostProcess extends Events {
50
50
  return answer[0] ? process(answer[0]) : null;
51
51
  }
52
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);
66
- }
67
- }
68
53
  function hostProcessEvent(event, values) {
69
54
  if (event === "endpointStart" || event === "endpointStop")
70
55
  return lifecycleEndpoint(values[1], values[2]);
package/dist/main.d.ts CHANGED
@@ -1,4 +1,4 @@
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";
1
+ export { host, type Host, type HostProcess, type HostProgram, 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";
package/dist/service.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type ClientServiceHandler, type ServerServiceDefinition, type ServerServiceHandler, type ServiceHandler, type ServiceKey } from "@phreshos/core";
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(definition: ServerServiceDefinition): Promise<void>;
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
@@ -63,10 +63,6 @@ class ServerHandler extends ServerServiceBase {
63
63
  async waitReady(timeout) {
64
64
  await wire.request(["service-wait-ready", this.key, timeout], timeout);
65
65
  }
66
- async docs() {
67
- const answer = await wire.request(["service-docs", this.key]);
68
- return answer[0];
69
- }
70
66
  }
71
67
  class ClientHandler extends ClientServiceBase {
72
68
  key;
@@ -98,8 +94,8 @@ export function prepareService(key) {
98
94
  : new ClientHandler(normalized);
99
95
  });
100
96
  }
101
- export async function enableCurrentService(definition) {
102
- await wire.request(["enable-service", definition]);
97
+ export async function enableCurrentService(name) {
98
+ await wire.request(["enable-service", name]);
103
99
  }
104
100
  export async function disableCurrentService() {
105
101
  await wire.request(["disable-service"]);
package/dist/wire.d.ts CHANGED
@@ -32,8 +32,6 @@ 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;
37
35
  private register;
38
36
  private unregister;
39
37
  private deliver;
package/dist/wire.js CHANGED
@@ -176,16 +176,6 @@ 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
- }
189
179
  register(kind, route, event, subject, impossible) {
190
180
  const subscription = randomUUID();
191
181
  if (impossible)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phreshos/server",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
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.9"
49
+ "@phreshos/core": "^0.1.11"
50
50
  },
51
51
  "dependencies": {
52
52
  "@msgpack/msgpack": "^3.1.3"
53
53
  },
54
54
  "devDependencies": {
55
- "@phreshos/core": "^0.1.9",
55
+ "@phreshos/core": "^0.1.11",
56
56
  "@types/node": "^26.2.0",
57
57
  "typescript": "^6.0.3"
58
58
  }