@phreshos/server 0.1.20 → 0.1.21
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 +4 -2
- package/dist/system.d.ts +10 -3
- package/dist/wire.d.ts +1 -0
- package/dist/wire.js +17 -3
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -42,11 +42,13 @@ await system.appearance.update({
|
|
|
42
42
|
void bytes
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
Its JavaScript entry point adapts the
|
|
45
|
+
Its JavaScript entry point adapts the Server runtime boundary to these contracts.
|
|
46
46
|
The SDK owns callbacks, waits, queues, and their cleanup; the boundary owns
|
|
47
47
|
only the forwarding registrations requested by the SDK.
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
The same SDK works in either supported Server runtime: a child process uses its
|
|
50
|
+
IPC channel, while a System-owned Worker uses its parent port. Importing the SDK
|
|
51
|
+
injects no message into either runtime. The endpoint may
|
|
50
52
|
announce its readiness outward, but identity, Theme, Process, readiness,
|
|
51
53
|
lifecycle, and application values enter only in response to an explicit request
|
|
52
54
|
or a live registration made by Program code.
|
package/dist/system.d.ts
CHANGED
|
@@ -3,16 +3,23 @@ import type { ClientServiceHandler, ServerServiceHandler } from "./service.js";
|
|
|
3
3
|
import { type Client, type Process, type Program, type Server } from "./domain.js";
|
|
4
4
|
import { type Storage } from "./storage.js";
|
|
5
5
|
/** Resolved production description for a Program's Server. */
|
|
6
|
-
|
|
6
|
+
type ServerDescriptionBase = Readonly<{
|
|
7
7
|
/** Absolute directory containing the production Server files. */
|
|
8
8
|
location: string;
|
|
9
9
|
/** Whether newly created Processes start this Server by default. */
|
|
10
10
|
start?: boolean;
|
|
11
11
|
/** Command used to install the Server's production dependencies. */
|
|
12
12
|
installCommand?: string;
|
|
13
|
-
/** Command used to start the Server from its production directory. */
|
|
14
|
-
startCommand: string;
|
|
15
13
|
}>;
|
|
14
|
+
export type ServerDescription = ServerDescriptionBase & (Readonly<{
|
|
15
|
+
/** Command used to start an isolated Server process. */
|
|
16
|
+
startCommand: string;
|
|
17
|
+
entryFile?: never;
|
|
18
|
+
}> | Readonly<{
|
|
19
|
+
startCommand?: never;
|
|
20
|
+
/** JavaScript module loaded as a worker owned by the System. */
|
|
21
|
+
entryFile: string;
|
|
22
|
+
}>);
|
|
16
23
|
/** Resolved production description for a Program's Client and initial Window. */
|
|
17
24
|
export type ClientDescription = Readonly<{
|
|
18
25
|
/** Absolute directory containing the production Client files. */
|
package/dist/wire.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ declare class Wire {
|
|
|
14
14
|
private readonly waiting;
|
|
15
15
|
private readonly impossible;
|
|
16
16
|
private identityPromise;
|
|
17
|
+
private readonly transport;
|
|
17
18
|
constructor();
|
|
18
19
|
send(route: string, ...values: unknown[]): void;
|
|
19
20
|
request(values: unknown[], timeout?: number): Promise<unknown>;
|
package/dist/wire.js
CHANGED
|
@@ -2,6 +2,7 @@ import { randomUUID } from "node:crypto";
|
|
|
2
2
|
import Deadline from "./deadline.js";
|
|
3
3
|
import { defaultTimeout } from "./events.js";
|
|
4
4
|
import { deserialize, serialize } from "./messagepack.js";
|
|
5
|
+
import { parentPort } from "node:worker_threads";
|
|
5
6
|
/** The server endpoint's sole IPC adapter. */
|
|
6
7
|
class Wire {
|
|
7
8
|
pending = new Map();
|
|
@@ -12,8 +13,9 @@ class Wire {
|
|
|
12
13
|
waiting = new Map();
|
|
13
14
|
impossible = new Map();
|
|
14
15
|
identityPromise = null;
|
|
16
|
+
transport = endpointTransport();
|
|
15
17
|
constructor() {
|
|
16
|
-
|
|
18
|
+
this.transport.onMessage(message => {
|
|
17
19
|
if (!(message instanceof Uint8Array))
|
|
18
20
|
return;
|
|
19
21
|
let decoded;
|
|
@@ -50,10 +52,10 @@ class Wire {
|
|
|
50
52
|
}
|
|
51
53
|
this.deliver(route, values);
|
|
52
54
|
});
|
|
53
|
-
|
|
55
|
+
this.transport.send(serialize(["boundary", "ready"]));
|
|
54
56
|
}
|
|
55
57
|
send(route, ...values) {
|
|
56
|
-
|
|
58
|
+
this.transport.send(serialize([route, ...values]));
|
|
57
59
|
}
|
|
58
60
|
request(values, timeout = defaultTimeout) {
|
|
59
61
|
return this.requestWithin(values, new Deadline(timeout));
|
|
@@ -337,6 +339,18 @@ class Wire {
|
|
|
337
339
|
stream.wake = null;
|
|
338
340
|
}
|
|
339
341
|
}
|
|
342
|
+
function endpointTransport() {
|
|
343
|
+
const worker = parentPort;
|
|
344
|
+
if (worker)
|
|
345
|
+
return {
|
|
346
|
+
onMessage: listener => worker.on("message", listener),
|
|
347
|
+
send: message => worker.postMessage(message)
|
|
348
|
+
};
|
|
349
|
+
return {
|
|
350
|
+
onMessage: listener => { process.on("message", listener); },
|
|
351
|
+
send: message => { process.send?.(message); }
|
|
352
|
+
};
|
|
353
|
+
}
|
|
340
354
|
const maximumStreamQueue = 256;
|
|
341
355
|
function failed(error) {
|
|
342
356
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phreshos/server",
|
|
3
|
-
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "The SDK used by a Program's server endpoint.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -42,17 +42,18 @@
|
|
|
42
42
|
"check": "tsc --noEmit",
|
|
43
43
|
"build": "node --run clean && tsc --noEmit false --outDir dist --rootDir source",
|
|
44
44
|
"verify:package": "node scripts/verify-package.mjs",
|
|
45
|
-
"verify": "node
|
|
45
|
+
"verify:worker": "node scripts/verify-worker.mjs",
|
|
46
|
+
"verify": "node --run check && node --run build && node --run verify:worker && node --run verify:package",
|
|
46
47
|
"prepack": "node --run build"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
|
-
"@phreshos/core": "^0.1.
|
|
50
|
+
"@phreshos/core": "^0.1.20"
|
|
50
51
|
},
|
|
51
52
|
"dependencies": {
|
|
52
53
|
"@msgpack/msgpack": "^3.1.3"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
|
|
56
|
+
"@phreshos/core": "^0.1.20",
|
|
56
57
|
"@types/node": "^26.2.0",
|
|
57
58
|
"typescript": "^6.0.3"
|
|
58
59
|
}
|