@phreshos/server 0.1.11 → 0.1.13
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 +34 -4
- package/dist/channel.d.ts +2 -2
- package/dist/channel.js +1 -1
- package/dist/domain.d.ts +24 -4
- package/dist/domain.js +33 -2
- package/dist/host.d.ts +13 -12
- package/dist/host.js +1 -16
- package/dist/main.d.ts +3 -2
- package/dist/main.js +2 -1
- package/dist/service.d.ts +28 -2
- package/dist/service.js +31 -9
- package/dist/wire.d.ts +0 -2
- package/dist/wire.js +0 -10
- package/package.json +3 -3
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,44 @@ 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
|
-
`
|
|
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.
|
|
156
|
+
|
|
157
|
+
Server-side Service handles can create their dedicated providing Process and
|
|
158
|
+
wait for readiness without reproducing Program-specific launch rules:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
await serverService.createAndWaitReady()
|
|
162
|
+
await clientService.createAndWaitReady({ minimize: true })
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Both readiness operations accept an optional timeout directly and expose an
|
|
166
|
+
immutable timed view. A direct argument on the timed view takes precedence:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
await service.waitReady(10_000)
|
|
170
|
+
await service.timeout(5_000).waitReady()
|
|
171
|
+
await service.timeout(5_000).waitReady(10_000)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The System owns the single deadline across Process creation, Endpoint startup,
|
|
175
|
+
and Service readiness. The creation capability exists only in the Server SDK.
|
|
146
176
|
|
|
147
177
|
`program.icon()` requests a guaranteed PNG `Blob` in `small`, `medium`, or
|
|
148
178
|
`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
|
|
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
|
|
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(
|
|
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,6 +1,7 @@
|
|
|
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
|
|
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
|
+
import { type ClientServiceHandler, type ServerServiceHandler } from "./service.js";
|
|
4
5
|
export interface HandleAddress {
|
|
5
6
|
identity: string;
|
|
6
7
|
reference: string;
|
|
@@ -13,6 +14,17 @@ export interface ProgramArea extends CoreProgramArea {
|
|
|
13
14
|
resolve(...path: string[]): Promise<string>;
|
|
14
15
|
}
|
|
15
16
|
/** Client-safe Program data transported by the authoritative host. */
|
|
17
|
+
export interface EndpointDeclarationRecord {
|
|
18
|
+
start: boolean;
|
|
19
|
+
hasService: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface ClientDeclarationRecord extends EndpointDeclarationRecord {
|
|
22
|
+
title: string | null;
|
|
23
|
+
size: Size | null;
|
|
24
|
+
position: Position | null;
|
|
25
|
+
layer: ClientDeclaration["layer"];
|
|
26
|
+
minimize: boolean | null;
|
|
27
|
+
}
|
|
16
28
|
export interface ProgramRecord {
|
|
17
29
|
reference: string;
|
|
18
30
|
identity: string;
|
|
@@ -20,8 +32,8 @@ export interface ProgramRecord {
|
|
|
20
32
|
name: string;
|
|
21
33
|
version: string | null;
|
|
22
34
|
description: string | null;
|
|
23
|
-
server:
|
|
24
|
-
client:
|
|
35
|
+
server: EndpointDeclarationRecord | null;
|
|
36
|
+
client: ClientDeclarationRecord | null;
|
|
25
37
|
}
|
|
26
38
|
/** Process data transported with every Endpoint reference. */
|
|
27
39
|
export interface ProcessRecord {
|
|
@@ -57,7 +69,7 @@ export interface Program<Events extends object = {}> extends Omit<CoreProgram<Ev
|
|
|
57
69
|
fork(identity: string): Promise<Program>;
|
|
58
70
|
}
|
|
59
71
|
/** Server-visible Process operations scoped to one Program. */
|
|
60
|
-
export interface ProgramProcess extends Omit<CoreProgramProcess, "list" | "first" | "last" | "find" | "create"> {
|
|
72
|
+
export interface ProgramProcess extends Omit<CoreProgramProcess, "list" | "first" | "last" | "find" | "create" | "findOrCreate"> {
|
|
61
73
|
/** Returns every live Process of this Program. */
|
|
62
74
|
list(): Promise<Process[]>;
|
|
63
75
|
/** Returns the earliest-started live Process, or `null` when none exist. */
|
|
@@ -68,6 +80,10 @@ export interface ProgramProcess extends Omit<CoreProgramProcess, "list" | "first
|
|
|
68
80
|
find(identityOrName: string): Promise<Process | null>;
|
|
69
81
|
/** Creates one Process of this Program. */
|
|
70
82
|
create(launch?: Launch): Promise<Process>;
|
|
83
|
+
/** Finds the named Process or atomically creates it with the same resolved launch. */
|
|
84
|
+
findOrCreate(launch: Launch & Readonly<{
|
|
85
|
+
name: string;
|
|
86
|
+
}>): Promise<Process>;
|
|
71
87
|
}
|
|
72
88
|
/** Server-visible Process handle. */
|
|
73
89
|
export interface Process<Events extends object = {}> extends CoreProcess<Events> {
|
|
@@ -89,6 +105,8 @@ export interface Endpoint<Events extends object = {}> extends CoreEndpoint<Event
|
|
|
89
105
|
export interface Server<Events extends object = {}> extends CoreServer<Events> {
|
|
90
106
|
/** Returns the Process that owns this Server. */
|
|
91
107
|
process(): Promise<Process>;
|
|
108
|
+
/** Returns the Service currently exposed by this Server Endpoint. */
|
|
109
|
+
service<ServiceEvents extends object = {}>(): Promise<ServerServiceHandler<ServiceEvents> | null>;
|
|
92
110
|
}
|
|
93
111
|
/** Server-visible Client handle. */
|
|
94
112
|
export interface Client<Events extends object = {}> extends CoreClient<Events> {
|
|
@@ -96,6 +114,8 @@ export interface Client<Events extends object = {}> extends CoreClient<Events> {
|
|
|
96
114
|
readonly window: Window;
|
|
97
115
|
/** Returns the Process that owns this Client. */
|
|
98
116
|
process(): Promise<Process>;
|
|
117
|
+
/** Returns the Service currently exposed by this Client Endpoint. */
|
|
118
|
+
service<ServiceEvents extends object = {}>(): Promise<ClientServiceHandler<ServiceEvents> | null>;
|
|
99
119
|
}
|
|
100
120
|
/** Server-visible Client-owned Window capability. */
|
|
101
121
|
export type Window = CoreWindow;
|
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() {
|
|
47
|
-
|
|
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,5 @@
|
|
|
1
|
-
import type { DesktopWallpaper, Exit, FileWallpaper, Layer, Position, ServedFile,
|
|
1
|
+
import type { DesktopWallpaper, Exit, FileWallpaper, Layer, Position, ServedFile, ServiceKey, Size, Subscribable, ThemeProperties, WritableTheme } from "@phreshos/core";
|
|
2
|
+
import type { ClientServiceHandler, ServerServiceHandler } from "./service.js";
|
|
2
3
|
import { type Client, type Process, type Program, type Server } from "./domain.js";
|
|
3
4
|
/** Resolved production description for a Program's Server. */
|
|
4
5
|
export type ServerDescription = Readonly<{
|
|
@@ -6,6 +7,8 @@ export type ServerDescription = Readonly<{
|
|
|
6
7
|
location: string;
|
|
7
8
|
/** Whether newly created Processes start this Server by default. */
|
|
8
9
|
start?: boolean;
|
|
10
|
+
/** Absolute Markdown file documenting the Service this Server may expose. */
|
|
11
|
+
serviceDocs?: string;
|
|
9
12
|
/** Command used to install the Server's production dependencies. */
|
|
10
13
|
installCommand?: string;
|
|
11
14
|
/** Command used to start the Server from its production directory. */
|
|
@@ -17,6 +20,8 @@ export type ClientDescription = Readonly<{
|
|
|
17
20
|
location: string;
|
|
18
21
|
/** Whether newly created Processes start this Client by default. */
|
|
19
22
|
start?: boolean;
|
|
23
|
+
/** Absolute Markdown file documenting the Service this Client may expose. */
|
|
24
|
+
serviceDocs?: string;
|
|
20
25
|
/** Default Window title. */
|
|
21
26
|
title?: string;
|
|
22
27
|
/** Default Window size. */
|
|
@@ -99,16 +104,6 @@ export interface HostProcess extends Subscribable<ProcessHostEvents, never> {
|
|
|
99
104
|
list(): Promise<Process[]>;
|
|
100
105
|
find(identity: string): Promise<Process | null>;
|
|
101
106
|
}
|
|
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
107
|
/** Authoritative system capabilities available to a Server endpoint. */
|
|
113
108
|
export interface Host {
|
|
114
109
|
/** Observable system Theme authority. */
|
|
@@ -119,7 +114,13 @@ export interface Host {
|
|
|
119
114
|
readonly desktopWallpaper: DesktopWallpaper;
|
|
120
115
|
readonly program: HostProgram;
|
|
121
116
|
readonly process: HostProcess;
|
|
122
|
-
|
|
117
|
+
/** Returns a stable handle for one exact Service identity. */
|
|
118
|
+
service<ServiceEvents extends object = {}>(key: ServiceKey & {
|
|
119
|
+
endpoint: "server";
|
|
120
|
+
}): ServerServiceHandler<ServiceEvents>;
|
|
121
|
+
service<ServiceEvents extends object = {}>(key: ServiceKey & {
|
|
122
|
+
endpoint: "client";
|
|
123
|
+
}): ClientServiceHandler<ServiceEvents>;
|
|
123
124
|
/** Publishes a value through the host and returns its public file metadata. */
|
|
124
125
|
serve(value: unknown): Promise<ServedFile>;
|
|
125
126
|
}
|
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
|
|
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,7 +1,8 @@
|
|
|
1
|
-
export { host, type Host, type HostProcess, type HostProgram, type
|
|
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";
|
|
5
|
-
export { ClientServiceHandler, ServerServiceHandler,
|
|
5
|
+
export { ClientServiceHandler, ServerServiceHandler, type TimedClientServiceHandler, type TimedServerServiceHandler } from "./service.js";
|
|
6
|
+
export { ServiceHandler, type ClientServiceChannel, type ServerServiceChannel, type ServiceChannel, type ServiceKey, type ServiceLifecycleEvents } from "@phreshos/core";
|
|
6
7
|
export { Client, Endpoint, Process, Program, Server, type Window, type ProgramArea, type ProgramProcess } from "./domain.js";
|
|
7
8
|
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/main.js
CHANGED
|
@@ -2,5 +2,6 @@ export { host } from "./host.js";
|
|
|
2
2
|
export { current } from "./current.js";
|
|
3
3
|
export {} from "./channel.js";
|
|
4
4
|
export {} from "./startup.js";
|
|
5
|
-
export { ClientServiceHandler, ServerServiceHandler
|
|
5
|
+
export { ClientServiceHandler, ServerServiceHandler } from "./service.js";
|
|
6
|
+
export { ServiceHandler } from "@phreshos/core";
|
|
6
7
|
export { Client, Endpoint, Process, Program, Server } from "./domain.js";
|
package/dist/service.d.ts
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ClientServiceHandler as CoreClientServiceHandler, ServerServiceHandler as CoreServerServiceHandler, type LaunchClient, type ServiceHandler, type ServiceKey, type Timeoutable } from "@phreshos/core";
|
|
2
2
|
import type { HandleAddress } from "./domain.js";
|
|
3
|
+
/** Timed view of a Server Endpoint Service available through the Server SDK. */
|
|
4
|
+
export interface TimedServerServiceHandler {
|
|
5
|
+
waitReady(timeout?: number): Promise<void>;
|
|
6
|
+
createAndWaitReady(timeout?: number): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/** Timed view of a Client Endpoint Service available through the Server SDK. */
|
|
9
|
+
export interface TimedClientServiceHandler {
|
|
10
|
+
waitReady(timeout?: number): Promise<void>;
|
|
11
|
+
createAndWaitReady(client?: LaunchClient, timeout?: number): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/** Server-SDK handle for a Service provided by a Server Endpoint. */
|
|
14
|
+
export declare class ServerServiceHandler<Events extends object = {}> extends CoreServerServiceHandler<Events> {
|
|
15
|
+
protected constructor();
|
|
16
|
+
}
|
|
17
|
+
export interface ServerServiceHandler<Events extends object = {}> extends Timeoutable<TimedServerServiceHandler> {
|
|
18
|
+
createAndWaitReady(timeout?: number): Promise<void>;
|
|
19
|
+
timeout(milliseconds: number): TimedServerServiceHandler;
|
|
20
|
+
}
|
|
21
|
+
/** Server-SDK handle for a Service provided by a Client Endpoint. */
|
|
22
|
+
export declare class ClientServiceHandler<Events extends object = {}> extends CoreClientServiceHandler<Events> {
|
|
23
|
+
protected constructor();
|
|
24
|
+
}
|
|
25
|
+
export interface ClientServiceHandler<Events extends object = {}> extends Timeoutable<TimedClientServiceHandler> {
|
|
26
|
+
createAndWaitReady(client?: LaunchClient, timeout?: number): Promise<void>;
|
|
27
|
+
timeout(milliseconds: number): TimedClientServiceHandler;
|
|
28
|
+
}
|
|
3
29
|
export declare function prepareService<EventsMap extends object = {}>(key: ServiceKey & {
|
|
4
30
|
endpoint: "server";
|
|
5
31
|
}): ServerServiceHandler<EventsMap>;
|
|
@@ -7,7 +33,7 @@ export declare function prepareService<EventsMap extends object = {}>(key: Servi
|
|
|
7
33
|
endpoint: "client";
|
|
8
34
|
}): ClientServiceHandler<EventsMap>;
|
|
9
35
|
export declare function prepareService(key: ServiceKey): ServiceHandler;
|
|
10
|
-
export declare function enableCurrentService(
|
|
36
|
+
export declare function enableCurrentService(name: string): Promise<void>;
|
|
11
37
|
export declare function disableCurrentService(): Promise<void>;
|
|
12
38
|
export declare function endpointService<EventsMap extends object = {}>(target: HandleAddress | null, endpoint: "server"): Promise<ServerServiceHandler<EventsMap> | null>;
|
|
13
39
|
export declare function endpointService<EventsMap extends object = {}>(target: HandleAddress | null, endpoint: "client"): Promise<ClientServiceHandler<EventsMap> | null>;
|
package/dist/service.js
CHANGED
|
@@ -5,8 +5,14 @@ import Events from "./events.js";
|
|
|
5
5
|
import HandleRegistry from "./handle-registry.js";
|
|
6
6
|
import wire from "./wire.js";
|
|
7
7
|
const handles = new HandleRegistry();
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
/** Server-SDK handle for a Service provided by a Server Endpoint. */
|
|
9
|
+
export class ServerServiceHandler extends CoreServerServiceHandler {
|
|
10
|
+
constructor() { super(); }
|
|
11
|
+
}
|
|
12
|
+
/** Server-SDK handle for a Service provided by a Client Endpoint. */
|
|
13
|
+
export class ClientServiceHandler extends CoreClientServiceHandler {
|
|
14
|
+
constructor() { super(); }
|
|
15
|
+
}
|
|
10
16
|
class ServerChannelHandle extends Events {
|
|
11
17
|
key;
|
|
12
18
|
constructor(key) {
|
|
@@ -45,7 +51,7 @@ class ClientChannelHandle extends Events {
|
|
|
45
51
|
super(...serviceEvents(key, "channel"));
|
|
46
52
|
}
|
|
47
53
|
}
|
|
48
|
-
class ServerHandler extends
|
|
54
|
+
class ServerHandler extends ServerServiceHandler {
|
|
49
55
|
key;
|
|
50
56
|
name;
|
|
51
57
|
channel;
|
|
@@ -63,12 +69,17 @@ class ServerHandler extends ServerServiceBase {
|
|
|
63
69
|
async waitReady(timeout) {
|
|
64
70
|
await wire.request(["service-wait-ready", this.key, timeout], timeout);
|
|
65
71
|
}
|
|
66
|
-
async
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
async createAndWaitReady(timeout) {
|
|
73
|
+
await wire.request(["service-create-and-wait-ready", this.key, undefined, timeout], timeout);
|
|
74
|
+
}
|
|
75
|
+
timeout(milliseconds) {
|
|
76
|
+
return Object.freeze({
|
|
77
|
+
waitReady: (timeout) => this.waitReady(timeout ?? milliseconds),
|
|
78
|
+
createAndWaitReady: (timeout) => this.createAndWaitReady(timeout ?? milliseconds)
|
|
79
|
+
});
|
|
69
80
|
}
|
|
70
81
|
}
|
|
71
|
-
class ClientHandler extends
|
|
82
|
+
class ClientHandler extends ClientServiceHandler {
|
|
72
83
|
key;
|
|
73
84
|
name;
|
|
74
85
|
channel;
|
|
@@ -86,6 +97,17 @@ class ClientHandler extends ClientServiceBase {
|
|
|
86
97
|
async waitReady(timeout) {
|
|
87
98
|
await wire.request(["service-wait-ready", this.key, timeout], timeout);
|
|
88
99
|
}
|
|
100
|
+
async createAndWaitReady(client, timeout) {
|
|
101
|
+
await wire.request(["service-create-and-wait-ready", this.key, client, timeout], timeout);
|
|
102
|
+
}
|
|
103
|
+
timeout(milliseconds) {
|
|
104
|
+
return Object.freeze({
|
|
105
|
+
waitReady: (timeout) => this.waitReady(timeout ?? milliseconds),
|
|
106
|
+
createAndWaitReady: (client, timeout) => {
|
|
107
|
+
return this.createAndWaitReady(client, timeout ?? milliseconds);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
89
111
|
}
|
|
90
112
|
export function prepareService(key) {
|
|
91
113
|
if (!isServiceKey(key))
|
|
@@ -98,8 +120,8 @@ export function prepareService(key) {
|
|
|
98
120
|
: new ClientHandler(normalized);
|
|
99
121
|
});
|
|
100
122
|
}
|
|
101
|
-
export async function enableCurrentService(
|
|
102
|
-
await wire.request(["enable-service",
|
|
123
|
+
export async function enableCurrentService(name) {
|
|
124
|
+
await wire.request(["enable-service", name]);
|
|
103
125
|
}
|
|
104
126
|
export async function disableCurrentService() {
|
|
105
127
|
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.
|
|
3
|
+
"version": "0.1.13",
|
|
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.11"
|
|
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.11",
|
|
56
56
|
"@types/node": "^26.2.0",
|
|
57
57
|
"typescript": "^6.0.3"
|
|
58
58
|
}
|