@phreshos/core 0.1.0

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.
Files changed (53) hide show
  1. package/README.md +159 -0
  2. package/dist/askable.d.ts +22 -0
  3. package/dist/askable.js +0 -0
  4. package/dist/channel.d.ts +20 -0
  5. package/dist/channel.js +0 -0
  6. package/dist/client.d.ts +19 -0
  7. package/dist/client.js +7 -0
  8. package/dist/config.d.ts +81 -0
  9. package/dist/config.js +9 -0
  10. package/dist/endpoint.d.ts +70 -0
  11. package/dist/endpoint.js +4 -0
  12. package/dist/launch.d.ts +35 -0
  13. package/dist/launch.js +2 -0
  14. package/dist/main.d.ts +16 -0
  15. package/dist/main.js +16 -0
  16. package/dist/outcome.d.ts +8 -0
  17. package/dist/outcome.js +0 -0
  18. package/dist/process.d.ts +58 -0
  19. package/dist/process.js +4 -0
  20. package/dist/program.d.ts +96 -0
  21. package/dist/program.js +4 -0
  22. package/dist/publishable.d.ts +21 -0
  23. package/dist/publishable.js +0 -0
  24. package/dist/served-file.d.ts +11 -0
  25. package/dist/served-file.js +0 -0
  26. package/dist/server.d.ts +42 -0
  27. package/dist/server.js +7 -0
  28. package/dist/sql.d.ts +17 -0
  29. package/dist/sql.js +0 -0
  30. package/dist/storage.d.ts +49 -0
  31. package/dist/storage.js +0 -0
  32. package/dist/subscribable.d.ts +72 -0
  33. package/dist/subscribable.js +0 -0
  34. package/dist/window.d.ts +60 -0
  35. package/dist/window.js +4 -0
  36. package/package.json +27 -0
  37. package/source/askable.ts +26 -0
  38. package/source/channel.ts +28 -0
  39. package/source/client.ts +29 -0
  40. package/source/config.ts +104 -0
  41. package/source/endpoint.ts +95 -0
  42. package/source/launch.ts +43 -0
  43. package/source/main.ts +65 -0
  44. package/source/outcome.ts +4 -0
  45. package/source/process.ts +77 -0
  46. package/source/program.ts +130 -0
  47. package/source/publishable.ts +33 -0
  48. package/source/served-file.ts +14 -0
  49. package/source/server.ts +58 -0
  50. package/source/sql.ts +36 -0
  51. package/source/storage.ts +66 -0
  52. package/source/subscribable.ts +94 -0
  53. package/source/window.ts +82 -0
package/README.md ADDED
@@ -0,0 +1,159 @@
1
+ # `@phreshos/core`
2
+
3
+ The Core SDK defines the domain objects and types shared by the client and
4
+ server SDKs. It contains no transport or subscription implementation.
5
+
6
+ ## Package status
7
+
8
+ This package is one component of a larger architecture that is still under
9
+ active testing. The architecture's components will be released in stages as
10
+ their contracts and integrations are verified.
11
+
12
+ `@phreshos/core` is not intended to be used on its own. It defines the shared
13
+ contracts consumed by the environment SDKs and does not provide a runtime
14
+ implementation by itself.
15
+
16
+ `Subscribable` is the independent receiving capability. It provides the
17
+ contracts for `subscribe()`, `waitFor()`, `events()`, and `observe()`.
18
+ `Publishable` independently provides `publish()`. `Askable` extends
19
+ `Publishable` with `ask()`, because every target that can be asked can also be
20
+ published to. A type may implement or compose only the capabilities it needs;
21
+ being able to publish does not imply being able to subscribe.
22
+
23
+ Finite asynchronous operations use a ten-second SDK deadline by default.
24
+ `Askable.timeout()` creates an immutable deadline view for `ask()` only;
25
+ `waitFor()` and `waitReady()` accept a deadline directly. `events()` is a
26
+ long-lived iterator with a bounded queue rather than a timed request. An ask's
27
+ single deadline covers both waiting for its current Server incarnation to
28
+ become ready and waiting for the eventual answer.
29
+
30
+ Every persistent registration returns its only cleanup function:
31
+
32
+ ```ts
33
+ const stop = target.subscribe("event", handler)
34
+ stop()
35
+ ```
36
+
37
+ There are no separate `unsubscribe()` or `unobserve()` methods and no
38
+ one-time subscription operation. Observation APIs such as `observeAsks()` and
39
+ `observeAnswers()` follow the same returned-cleanup rule.
40
+
41
+ ```ts
42
+ import type { Subscribable } from "@phreshos/core"
43
+
44
+ type Events = {
45
+ exit: {
46
+ status: string
47
+ code: number
48
+ }
49
+ }
50
+
51
+ declare const target: Subscribable<Events>
52
+
53
+ target.subscribe("exit", message => {
54
+ message.status
55
+ message.code
56
+ })
57
+ ```
58
+
59
+ Known messages are inferred from the target. An explicit generic or callback
60
+ annotation may narrow that message, but an incompatible replacement is a type
61
+ error. `observe()` receives a `Capture` containing only the facts guaranteed by
62
+ every Subscribable: `event` and `message`. It makes no assumption about a
63
+ sender or destination.
64
+
65
+ An unparameterized Channel or traffic surface accepts application-defined event
66
+ names with an `unknown` payload. Supplying an event map narrows both the names
67
+ and their payloads; names outside that map are then rejected.
68
+
69
+ `events()` applies the same message inference and narrowing rules and exposes a
70
+ named event as an `AsyncIterableIterator`.
71
+
72
+ `Endpoint` is the shared base of Server and Client and composes only
73
+ `Publishable`. It is an address and lifecycle-control handle, never a receiving
74
+ surface. Server additionally composes `Askable`. Every event explicitly
75
+ addressed to the executing Endpoint enters only through its contextual
76
+ `Channel`, whose `ChannelMessage` contains the otherwise unknown sender. An
77
+ environment may narrow that reference to `Endpoint | null` when its isolation
78
+ boundary deliberately hides foreign identities.
79
+
80
+ Broad inspection is deliberately separated as `endpoint.traffic`. The Endpoint
81
+ handle already identifies the source, so ordinary traffic messages contain only
82
+ the unknown destination and payload. Every traffic surface exposes
83
+ `observeAsks()` because either Endpoint kind may originate a question. A
84
+ Server's traffic additionally exposes `observeAnswers()`, because only a Server
85
+ can originate an answer. These captures include their event, correlation ID,
86
+ destination, and question payload or answer `Outcome`.
87
+
88
+ Every Endpoint exposes `exists()`, `start()`, and `stop()`. Endpoint lifecycle
89
+ is observed through the owning Process's `serverStart`, `serverStop`,
90
+ `clientStart`, and `clientStop` events rather than through Endpoint
91
+ subscriptions.
92
+
93
+ `Server` and `Client` are public, logic-free Endpoint specializations. Server
94
+ adds one-payload `ask()` and answer traffic observation. Client returns its owned
95
+ Window. Window returns its owning Client, preserving navigation in both
96
+ directions without introducing host or transport knowledge.
97
+
98
+ Program and Process complete the ownership hierarchy. Every public domain
99
+ object remains a real runtime class for identity and `instanceof`, while the
100
+ capabilities it implements are independent interfaces. Constructors are public
101
+ and logic-free during this contract phase; all methods remain declarations
102
+ until an environment SDK supplies their implementation.
103
+ Core also owns the common launch, geometry, lifecycle-message, ChannelMessage,
104
+ ChannelCapture, TrafficMessage, and TrafficCapture types used by both
105
+ environments.
106
+
107
+ Process parentage belongs to `Process`, not to contextual SDK state.
108
+ Each live Process retains only a handle to its immediate parent.
109
+ `process.parent()` returns `null` when no accessible parent handle exists. It
110
+ does not preserve historical lineage: calling it through an exited Process
111
+ handle, or after the retained parent has disappeared, rejects because the
112
+ represented Process does not exist. A future `current.parent()` may flatten
113
+ this operation, but does not own the relationship.
114
+
115
+ Client traversal is structurally confined to its current Program. A
116
+ cross-Program parent handle is never supplied to the client, so traversal stops
117
+ at `null`. A fabricated or otherwise unauthorized Process handle is
118
+ indistinguishable from a nonexistent Process and every operation through it
119
+ rejects accordingly.
120
+
121
+ ## Program configuration
122
+
123
+ Core is also the single source of truth for the authoring contract consumed by
124
+ the CLI. `defineConfig()` provides contextual typing for `phresh.config.ts` and
125
+ returns the description unchanged:
126
+
127
+ ```ts
128
+ import { defineConfig } from "@phreshos/core"
129
+
130
+ export default defineConfig({
131
+ identity: "my-program",
132
+ server: {
133
+ location: "./dist/server",
134
+ startCommand: "node main.js",
135
+ development: {
136
+ startCommand: "node --watch --import tsx source/server/main.ts"
137
+ }
138
+ },
139
+ client: {
140
+ location: "./dist/client",
141
+ development: {
142
+ url: "http://localhost:5173/",
143
+ startCommand: "npm run dev"
144
+ }
145
+ }
146
+ })
147
+ ```
148
+
149
+ The declaration must contain a Server, a Client, or both. Development settings
150
+ remain authoring metadata; the CLI derives the appropriate runtime description
151
+ for each mode.
152
+
153
+ ## Program-owned resources
154
+
155
+ Every Program exposes the same storage contracts in both environments:
156
+ filesystem-like `data` and `cache`, a key-value `store`, read-only SQL `logs`,
157
+ and a writable SQLite `database`. The Server SDK refines its filesystem areas
158
+ with `path()` and safe `resolve()` access; these host filesystem paths are
159
+ structurally absent from the Client SDK.
@@ -0,0 +1,22 @@
1
+ import type { Publishable } from "./publishable.js";
2
+ /** An immutable Askable view using one caller-selected deadline. */
3
+ export interface TimedAskable {
4
+ /** Sends one question and waits within the selected deadline. */
5
+ ask<Answer = unknown, Payload = unknown>(event: string, payload: Payload): Promise<Answer>;
6
+ }
7
+ /** A publishing target that can also receive a question and return an answer. */
8
+ export interface Askable<Events extends object = {}, Fallback = unknown> extends Publishable<Events, Fallback> {
9
+ /**
10
+ * Sends one question payload to this target and waits for its answer.
11
+ *
12
+ * The SDK uses a ten-second deadline by default. It sends the question only
13
+ * after the current Server incarnation becomes ready. The operation rejects
14
+ * immediately when that Server is absent, and also rejects if the incarnation
15
+ * stops before readiness or before answering. One SDK deadline covers both
16
+ * readiness and the answer. The boundary cannot infer whether an answerer
17
+ * exists, so a ready unanswered question waits for that deadline.
18
+ */
19
+ ask<Answer = unknown, Payload = unknown>(event: string, payload: Payload): Promise<Answer>;
20
+ /** Returns an immutable view whose `ask()` uses this deadline in milliseconds. */
21
+ timeout(milliseconds: number): TimedAskable;
22
+ }
File without changes
@@ -0,0 +1,20 @@
1
+ import type { Endpoint } from "./endpoint.js";
2
+ import type { Captures, Subscribable } from "./subscribable.js";
3
+ /** One application value arriving through the current Endpoint's Channel. */
4
+ export type ChannelMessage<Payload = unknown, From = Endpoint> = Readonly<{
5
+ /** Endpoint that sent the message, or `null` when its identity is outside this boundary. */
6
+ from: From;
7
+ /** Single value supplied by the publisher. */
8
+ payload: Payload;
9
+ }>;
10
+ /** Applies the sender envelope to every application event accepted here. */
11
+ export type ChannelEvents<Events extends object, From = Endpoint> = {
12
+ readonly [Event in keyof Events]: ChannelMessage<Events[Event], From>;
13
+ };
14
+ type ChannelFallback<Events extends object, From> = keyof Events extends never ? ChannelMessage<unknown, From> : never;
15
+ /** Every application event observable through a Channel. */
16
+ export type ChannelCapture<Events extends object = {}, From = Endpoint> = Captures<ChannelEvents<Events, From>, ChannelFallback<Events, From>>;
17
+ /** Events explicitly accepted by the current Endpoint. */
18
+ export interface Channel<Events extends object = {}, From = Endpoint> extends Subscribable<ChannelEvents<Events, From>, ChannelFallback<Events, From>> {
19
+ }
20
+ export {};
File without changes
@@ -0,0 +1,19 @@
1
+ import { Endpoint, type EndpointTraffic } from "./endpoint.js";
2
+ import type { LaunchClient } from "./launch.js";
3
+ import type { Server } from "./server.js";
4
+ import type { Window } from "./window.js";
5
+ /** Broad communication originating from one Client. */
6
+ export interface ClientTraffic<Events extends object = {}, To = Endpoint, AskTo = Server> extends EndpointTraffic<Events, To, AskTo> {
7
+ }
8
+ /** The client Endpoint of a Process. */
9
+ export declare class Client<Events extends object = {}> extends Endpoint<Events> {
10
+ constructor();
11
+ }
12
+ export interface Client<Events extends object = {}> {
13
+ /** Broad communication originating from this Client. */
14
+ readonly traffic: ClientTraffic<Events>;
15
+ /** Starts a fresh Client and Window using optional Process-local overrides. */
16
+ start(overrides?: LaunchClient): Promise<void>;
17
+ /** Returns the Window owned by this live Client. */
18
+ window(): Promise<Window>;
19
+ }
package/dist/client.js ADDED
@@ -0,0 +1,7 @@
1
+ import { Endpoint } from "./endpoint.js";
2
+ /** The client Endpoint of a Process. */
3
+ export class Client extends Endpoint {
4
+ constructor() {
5
+ super();
6
+ }
7
+ }
@@ -0,0 +1,81 @@
1
+ import type { Layer, Position, Size } from "./launch.js";
2
+ /** Development settings for a Program's Server. */
3
+ export type ServerDevelopment = Readonly<{
4
+ /** Command that starts the development Server from the project directory. */
5
+ startCommand: string;
6
+ }>;
7
+ /** Development settings for a Program's Client. */
8
+ export type ClientDevelopment = Readonly<{
9
+ /** HTTP(S) URL served by the Client's development server. */
10
+ url: string;
11
+ /** Optional command that starts the Client's development server. */
12
+ startCommand?: string;
13
+ }>;
14
+ /** Authoring declaration for a Program's Server. */
15
+ export type ServerConfig = Readonly<{
16
+ /** Production directory containing the Server. */
17
+ location: string;
18
+ /** Whether a default Process starts its Server. Defaults to `true`. */
19
+ start?: boolean;
20
+ /** Optional preparation command run from {@link location} while installing. */
21
+ installCommand?: string;
22
+ /** Command that starts the production Server from {@link location}. */
23
+ startCommand: string;
24
+ /** Settings used only by the development command. */
25
+ development?: ServerDevelopment;
26
+ }>;
27
+ /** Authoring declaration for a Program's Client and initial Window. */
28
+ export type ClientConfig = Readonly<{
29
+ /** Production directory containing the Client and its `index.html`. */
30
+ location: string;
31
+ /** Whether a default Process starts its Client. Defaults to `true`. */
32
+ start?: boolean;
33
+ /** Initial Window title. Defaults to the Program name. */
34
+ title?: string;
35
+ /** Initial Window size. */
36
+ size?: Size;
37
+ /** Initial Window position. */
38
+ position?: Position;
39
+ /** Structurally isolated desktop layer containing the Window. */
40
+ layer?: Layer;
41
+ /** Whether the Window initially opens minimized. */
42
+ minimize?: boolean;
43
+ /** Settings used only by the development command. */
44
+ development?: ClientDevelopment;
45
+ }>;
46
+ type Description = Readonly<{
47
+ /** Stable public identity written in kebab-case. */
48
+ identity: string;
49
+ /** Human-readable Program name. Defaults to {@link identity}. */
50
+ name?: string;
51
+ /** Program version shown to people and included in packages. */
52
+ version?: string;
53
+ /** Short human-readable explanation of what the Program does. */
54
+ description?: string;
55
+ /** Markdown file that officially introduces the Program's API. */
56
+ apiDocs?: string;
57
+ /** Directory containing the Program's sized icons. */
58
+ icons?: string;
59
+ /** Command run before production start, installation, and packaging. */
60
+ buildCommand?: string;
61
+ }>;
62
+ /**
63
+ * The authoring description read from `phresh.config.ts`.
64
+ *
65
+ * A Program must declare a Server, a Client, or both.
66
+ */
67
+ export type Config = Description & (Readonly<{
68
+ server: ServerConfig;
69
+ client?: ClientConfig;
70
+ }> | Readonly<{
71
+ server?: ServerConfig;
72
+ client: ClientConfig;
73
+ }>);
74
+ /**
75
+ * Defines a Program authoring description with contextual typing.
76
+ *
77
+ * This helper performs no work and returns the supplied description unchanged.
78
+ * The CLI validates and derives it for development, production, or packaging.
79
+ */
80
+ export declare function defineConfig<const Description extends Config>(config: Description): Description;
81
+ export {};
package/dist/config.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Defines a Program authoring description with contextual typing.
3
+ *
4
+ * This helper performs no work and returns the supplied description unchanged.
5
+ * The CLI validates and derives it for development, production, or packaging.
6
+ */
7
+ export function defineConfig(config) {
8
+ return config;
9
+ }
@@ -0,0 +1,70 @@
1
+ import type { Process } from "./process.js";
2
+ import type { Publishable } from "./publishable.js";
3
+ import type { Server } from "./server.js";
4
+ import type { Captures, Cleanup, Subscribable } from "./subscribable.js";
5
+ /** One application value observed in traffic originating from an Endpoint. */
6
+ export type TrafficMessage<Payload = unknown, To = Endpoint> = Readonly<{
7
+ /** Destination Endpoint, or `null` when its identity is outside this boundary. */
8
+ to: To;
9
+ /** Single value supplied by the publisher. */
10
+ payload: Payload;
11
+ }>;
12
+ /** Applies destination metadata to every observed ordinary event. */
13
+ export type TrafficEvents<Events extends object, To = Endpoint> = {
14
+ readonly [Event in keyof Events]: TrafficMessage<Events[Event], To>;
15
+ };
16
+ type TrafficFallback<Events extends object, To> = keyof Events extends never ? TrafficMessage<unknown, To> : never;
17
+ /** One question sent by this Endpoint to a Server. */
18
+ export type AskMessage<Payload = unknown, To = Server> = Readonly<{
19
+ /** Destination Server, or `null` when its identity is outside this boundary. */
20
+ to: To;
21
+ /** Single question value supplied by the asker. */
22
+ payload: Payload;
23
+ }>;
24
+ /** One observed question sent by this Endpoint. */
25
+ export type AskCapture<Payload = unknown, To = Server> = Readonly<{
26
+ /** Event addressed by the question. */
27
+ event: string;
28
+ /** Correlation identity shared with the eventual answer. */
29
+ questionId: string;
30
+ /** Question destination and payload. */
31
+ message: AskMessage<Payload, To>;
32
+ }>;
33
+ /** A callback that observes questions sent by this Endpoint. */
34
+ export type AskObserver<Payload = unknown, To = Server> = (capture: AskCapture<Payload, To>) => unknown;
35
+ /** Every ordinary publication observable in traffic from one Endpoint. */
36
+ export type TrafficCapture<Events extends object = {}, To = Endpoint> = Captures<TrafficEvents<Events, To>, TrafficFallback<Events, To>>;
37
+ /** Broad communication originating from one Endpoint, regardless of destination. */
38
+ export interface EndpointTraffic<Events extends object = {}, To = Endpoint, AskTo = Server> extends Subscribable<TrafficEvents<Events, To>, TrafficFallback<Events, To>> {
39
+ /** Observes questions originating from this Endpoint. */
40
+ observeAsks<Payload = unknown>(observer: AskObserver<Payload, AskTo>): Cleanup;
41
+ }
42
+ /** The shared Process endpoint represented by Server and Client. */
43
+ export declare class Endpoint<Events extends object = {}> {
44
+ constructor();
45
+ }
46
+ export interface Endpoint<Events extends object = {}> extends Publishable {
47
+ /** Broad communication originating from this Endpoint. */
48
+ readonly traffic: EndpointTraffic<Events>;
49
+ /** Returns the Process that owns this Endpoint. */
50
+ process(): Process;
51
+ /** Returns whether this Endpoint currently has a live incarnation. */
52
+ exists(): Promise<boolean>;
53
+ /**
54
+ * Starts a fresh incarnation without waiting for Server readiness.
55
+ *
56
+ * Rejects when the Process is gone or inaccessible, the Program did not
57
+ * declare this endpoint kind, the Endpoint is already starting or live, or
58
+ * creation fails.
59
+ */
60
+ start(): Promise<void>;
61
+ /**
62
+ * Stops the current incarnation and destroys its boundary-owned resources.
63
+ *
64
+ * Rejects when the Process is gone or inaccessible, the Endpoint is already
65
+ * stopping or absent, this is the Process's final live Endpoint, or stopping
66
+ * fails. Stopping never exits the Process implicitly.
67
+ */
68
+ stop(): Promise<void>;
69
+ }
70
+ export {};
@@ -0,0 +1,4 @@
1
+ /** The shared Process endpoint represented by Server and Client. */
2
+ export class Endpoint {
3
+ constructor() { }
4
+ }
@@ -0,0 +1,35 @@
1
+ /** A pixel count or a relative linear expression. */
2
+ export type Value = number | string;
3
+ /** A Window's top-left position. */
4
+ export type Position = Readonly<{
5
+ /** Horizontal position. */
6
+ x: Value;
7
+ /** Vertical position. */
8
+ y: Value;
9
+ }>;
10
+ /** A Window's width and height. */
11
+ export type Size = Readonly<{
12
+ /** Window width. */
13
+ width: Value;
14
+ /** Window height. */
15
+ height: Value;
16
+ }>;
17
+ /** A structurally isolated desktop layer. */
18
+ export type Layer = "window" | "under" | "over";
19
+ /** Every structurally isolated desktop layer. */
20
+ export declare const layers: readonly Layer[];
21
+ /** Per-Process overrides used when starting a Client and its Window. */
22
+ export type LaunchClient = Readonly<{
23
+ size?: Size;
24
+ position?: Position;
25
+ layer?: Layer;
26
+ location?: string;
27
+ minimize?: boolean;
28
+ }>;
29
+ /** Initial endpoint selection and immutable options for one Process. */
30
+ export type Launch = Readonly<{
31
+ name?: string;
32
+ server?: boolean;
33
+ client?: boolean | LaunchClient;
34
+ options?: Readonly<Record<string, string>>;
35
+ }>;
package/dist/launch.js ADDED
@@ -0,0 +1,2 @@
1
+ /** Every structurally isolated desktop layer. */
2
+ export const layers = ["window", "under", "over"];
package/dist/main.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export { type Message, type Cleanup, type Capture, type Captures, type EventMessage, type EventName, type EventObserver, type EventOptions, type EventSubscriber, type Subscribable } from "./subscribable.js";
2
+ export { type Publishable } from "./publishable.js";
3
+ export { type Askable, type TimedAskable } from "./askable.js";
4
+ export { type Outcome } from "./outcome.js";
5
+ export { type ServedFile } from "./served-file.js";
6
+ export { type DirectoryStat, type EntryStat, type FileStat, type OtherStat, type ProgramArea, type ProgramStore } from "./storage.js";
7
+ export { type LogKind, type LogRecord, type LogSource, type ProgramSql } from "./sql.js";
8
+ export { Endpoint, type AskCapture, type AskMessage, type AskObserver, type EndpointTraffic, type TrafficCapture, type TrafficEvents, type TrafficMessage } from "./endpoint.js";
9
+ export { type Channel, type ChannelCapture, type ChannelEvents, type ChannelMessage } from "./channel.js";
10
+ export { Server, type AnswerCapture, type AnswerMessage, type AnswerObserver, type ServerTraffic } from "./server.js";
11
+ export { Client, type ClientTraffic } from "./client.js";
12
+ export { Process, type Exit, type ProcessEvents } from "./process.js";
13
+ export { Program, type ClientDeclaration, type EndpointDeclaration, type ProgramEvents, type ProgramProcessExit, type ProgramServerStop } from "./program.js";
14
+ export { Window, type WindowEvents, type WindowState } from "./window.js";
15
+ export { layers, type Launch, type LaunchClient, type Layer, type Position, type Size, type Value } from "./launch.js";
16
+ export { defineConfig, type ClientConfig, type ClientDevelopment, type Config, type ServerConfig, type ServerDevelopment } from "./config.js";
package/dist/main.js ADDED
@@ -0,0 +1,16 @@
1
+ export {} from "./subscribable.js";
2
+ export {} from "./publishable.js";
3
+ export {} from "./askable.js";
4
+ export {} from "./outcome.js";
5
+ export {} from "./served-file.js";
6
+ export {} from "./storage.js";
7
+ export {} from "./sql.js";
8
+ export { Endpoint } from "./endpoint.js";
9
+ export {} from "./channel.js";
10
+ export { Server } from "./server.js";
11
+ export { Client } from "./client.js";
12
+ export { Process } from "./process.js";
13
+ export { Program } from "./program.js";
14
+ export { Window } from "./window.js";
15
+ export { layers } from "./launch.js";
16
+ export { defineConfig } from "./config.js";
@@ -0,0 +1,8 @@
1
+ /** The transport-neutral result of an operation that may fail. */
2
+ export type Outcome<Result = unknown> = Readonly<{
3
+ success: true;
4
+ result: Result;
5
+ }> | Readonly<{
6
+ success: false;
7
+ error: string;
8
+ }>;
File without changes
@@ -0,0 +1,58 @@
1
+ import type { Client } from "./client.js";
2
+ import type { Program } from "./program.js";
3
+ import type { Server } from "./server.js";
4
+ import type { Subscribable } from "./subscribable.js";
5
+ /** How an operating-system-backed endpoint or Process finished. */
6
+ export type Exit = Readonly<{
7
+ /** Whether the endpoint exited normally or was terminated by a signal. */
8
+ status: "exited" | "signaled";
9
+ /** Numeric exit code, or `null` when no code was reported. */
10
+ code: number | null;
11
+ /** Signal name, or `null` when no signal ended it. */
12
+ signal: string | null;
13
+ }>;
14
+ /** Lifecycle events emitted by one Process. */
15
+ export type ProcessEvents = {
16
+ /** The Server entered a new live incarnation. */
17
+ serverStart: undefined;
18
+ /** The Server incarnation ended. */
19
+ serverStop: Omit<Exit, "status">;
20
+ /** The authoritative Client state was created. */
21
+ clientStart: undefined;
22
+ /** The authoritative Client state ended. */
23
+ clientStop: undefined;
24
+ /** The complete Process ended. */
25
+ exit: Exit;
26
+ };
27
+ /** One live execution of a Program. */
28
+ export declare class Process<Events extends object = {}> {
29
+ constructor();
30
+ }
31
+ export interface Process<Events extends object = {}> extends Subscribable<ProcessEvents & Events, never> {
32
+ /** Immutable runtime identity. */
33
+ readonly identity: string;
34
+ /** Optional meaningful name unique among this Program's live Processes. */
35
+ readonly name: string | null;
36
+ /** Instant at which this Process was created. */
37
+ readonly startedAt: Date;
38
+ /** Permanent handle to this Process's Server. */
39
+ readonly server: Server;
40
+ /** Permanent handle to this Process's Client. */
41
+ readonly client: Client;
42
+ /** Returns the Program that owns this Process. */
43
+ program(): Program;
44
+ /**
45
+ * Returns the Process whose `createProcess()` call created this Process.
46
+ *
47
+ * Returns `null` when this Process has no accessible parent handle. Rejects
48
+ * when this Process or its retained parent no longer exists. Client
49
+ * environments never expose a parent belonging to another Program.
50
+ */
51
+ parent(): Promise<Process | null>;
52
+ /** Returns one immutable launch option. */
53
+ option(name: string): Promise<string | undefined>;
54
+ /** Ends the complete Process and all live Endpoints. */
55
+ exit(): Promise<void>;
56
+ /** Returns whether this Process has ended. */
57
+ exited(): Promise<boolean>;
58
+ }
@@ -0,0 +1,4 @@
1
+ /** One live execution of a Program. */
2
+ export class Process {
3
+ constructor() { }
4
+ }
@@ -0,0 +1,96 @@
1
+ import type { Launch, Layer, Position, Size } from "./launch.js";
2
+ import type { Exit, Process } from "./process.js";
3
+ import type { ProgramSql } from "./sql.js";
4
+ import type { ProgramArea, ProgramStore } from "./storage.js";
5
+ import type { Subscribable } from "./subscribable.js";
6
+ /** Resolved declaration shared by Server and Client endpoint kinds. */
7
+ export type EndpointDeclaration = Readonly<{
8
+ /** Whether a default Process starts this declared Endpoint. */
9
+ start: boolean;
10
+ }>;
11
+ /** Resolved Client declaration and its default Window state. */
12
+ export type ClientDeclaration = EndpointDeclaration & Readonly<{
13
+ /** Default Window title, or `null` when the system supplies it. */
14
+ title: string | null;
15
+ /** Default Window size, or `null` when the system supplies it. */
16
+ size: Size | null;
17
+ /** Default Window position, or `null` when the system supplies it. */
18
+ position: Position | null;
19
+ /** Default Window layer, or `null` for the system default. */
20
+ layer: Layer | null;
21
+ /** Default minimized state, or `null` for the system default. */
22
+ minimize: boolean | null;
23
+ }>;
24
+ export type ProgramProcessExit = Exit & Readonly<{
25
+ /** Process that ended. */
26
+ process: Process;
27
+ }>;
28
+ export type ProgramServerStop = Omit<Exit, "status"> & Readonly<{
29
+ /** Process whose Server incarnation ended. */
30
+ process: Process;
31
+ }>;
32
+ /** Lifecycle events scoped to one Program. */
33
+ export type ProgramEvents = {
34
+ /** One Process's Server entered a new live incarnation. */
35
+ serverStart: Process;
36
+ /** One Process's Server incarnation ended. */
37
+ serverStop: ProgramServerStop;
38
+ /** One Process's Client state was created. */
39
+ clientStart: Process;
40
+ /** One Process's Client state ended. */
41
+ clientStop: Process;
42
+ /** A Process entered this Program's runtime set. */
43
+ processCreate: Process;
44
+ /** A Process left this Program's runtime set. */
45
+ processExit: ProgramProcessExit;
46
+ /** This Program left the runtime registry. */
47
+ forget: undefined;
48
+ /** This Program left the installed state. */
49
+ uninstall: Readonly<{
50
+ everythingRemoved: boolean;
51
+ }>;
52
+ };
53
+ /** The stable domain root from which Processes are created. */
54
+ export declare class Program<Events extends object = {}> {
55
+ constructor();
56
+ }
57
+ export interface Program<Events extends object = {}> extends Subscribable<ProgramEvents & Events, never> {
58
+ /** Stable public identity. */
59
+ readonly identity: string;
60
+ /** Human-readable name. */
61
+ readonly name: string;
62
+ /** Declared version, or `null`. */
63
+ readonly version: string | null;
64
+ /** Declared description, or `null`. */
65
+ readonly description: string | null;
66
+ /** Server declaration, or `null` when this Program cannot start one. */
67
+ readonly server: EndpointDeclaration | null;
68
+ /** Client declaration, or `null` when this Program cannot start one. */
69
+ readonly client: ClientDeclaration | null;
70
+ /** Persistent filesystem data shared by every Process of this Program. */
71
+ readonly data: ProgramArea;
72
+ /** Disposable filesystem data shared by every Process of this Program. */
73
+ readonly cache: ProgramArea;
74
+ /** Persistent key-value storage shared by every Process of this Program. */
75
+ readonly store: ProgramStore;
76
+ /** Read-only SQL access to captured Client and Server output. */
77
+ readonly logs: ProgramSql;
78
+ /** Writable SQLite database owned by this Program. */
79
+ readonly database: ProgramSql;
80
+ /** Returns every live Process of this Program available to this SDK. */
81
+ processes(): Promise<Process[]>;
82
+ /** Finds a live Process by identity or Program-local name. */
83
+ getProcess(identityOrName: string): Promise<Process | null>;
84
+ /** Creates one Process of this Program. */
85
+ createProcess(launch?: Launch): Promise<Process>;
86
+ /** Returns the official Markdown API entry point, or `null`. */
87
+ apiDocs(): Promise<string | null>;
88
+ /** Returns whether this Program currently has an installed form. */
89
+ installed(): Promise<boolean>;
90
+ /** Removes this Program's installed form. */
91
+ uninstall(everything?: boolean): Promise<void>;
92
+ /** Ends all Processes and removes this Program from the runtime registry. */
93
+ forget(): Promise<void>;
94
+ /** Ends every live Process and returns their identities. */
95
+ exitAll(): Promise<string[]>;
96
+ }
@@ -0,0 +1,4 @@
1
+ /** The stable domain root from which Processes are created. */
2
+ export class Program {
3
+ constructor() { }
4
+ }