@inflatable-cookie/longhorn-tauri 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 inflatable-cookie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # @inflatable-cookie/longhorn-tauri
2
+
3
+ The Tauri host edge: `invoke`/`listen` transport plus the per-domain adapters
4
+ that bind a Longhorn client to a Tauri command surface. Peers on
5
+ `@inflatable-cookie/longhorn` and `@tauri-apps/api`.
6
+
7
+ ```sh
8
+ effigy check:ts
9
+ effigy test:ts
10
+ ```
11
+
12
+ The root is the transport itself, and `/events` its event edge. Everything else
13
+ is one domain's host adapter:
14
+
15
+ - `/bridge`, `/bridge-events` — typed bridge over the Tauri command surface
16
+ - `/history`, `/history-tree`, `/native-content`, `/notifications`, `/operation`
17
+
18
+ Each adapter is a thin port construction over the framework-neutral client in
19
+ `@inflatable-cookie/longhorn`. It holds no domain logic, which is what lets a
20
+ second host — GPUI — supply the same ports without reimplementing a domain.
21
+
22
+ Contract 020 governs that boundary. `tests/boundary.test.ts` enforces the half
23
+ of it that lives here: the package reaches the framework only through published
24
+ specifiers, never by relative path into the sibling.
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "@inflatable-cookie/longhorn-tauri",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/inflatable-cookie/longhorn.git",
8
+ "directory": "packages/longhorn-tauri"
9
+ },
10
+ "homepage": "https://github.com/inflatable-cookie/longhorn#readme",
11
+ "type": "module",
12
+ "types": "./src/transport/index.ts",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./src/transport/index.ts",
16
+ "import": "./src/transport/index.ts",
17
+ "default": "./src/transport/index.ts"
18
+ },
19
+ "./bridge": {
20
+ "types": "./src/bridge.ts",
21
+ "import": "./src/bridge.ts",
22
+ "default": "./src/bridge.ts"
23
+ },
24
+ "./bridge-events": {
25
+ "types": "./src/bridge-events.ts",
26
+ "import": "./src/bridge-events.ts",
27
+ "default": "./src/bridge-events.ts"
28
+ },
29
+ "./events": {
30
+ "types": "./src/transport/events.ts",
31
+ "import": "./src/transport/events.ts",
32
+ "default": "./src/transport/events.ts"
33
+ },
34
+ "./history": {
35
+ "types": "./src/history.ts",
36
+ "import": "./src/history.ts",
37
+ "default": "./src/history.ts"
38
+ },
39
+ "./history-tree": {
40
+ "types": "./src/history-tree.ts",
41
+ "import": "./src/history-tree.ts",
42
+ "default": "./src/history-tree.ts"
43
+ },
44
+ "./licence": {
45
+ "types": "./src/licence.ts",
46
+ "import": "./src/licence.ts",
47
+ "default": "./src/licence.ts"
48
+ },
49
+ "./native-content": {
50
+ "types": "./src/native-content.ts",
51
+ "import": "./src/native-content.ts",
52
+ "default": "./src/native-content.ts"
53
+ },
54
+ "./notifications": {
55
+ "types": "./src/notifications.ts",
56
+ "import": "./src/notifications.ts",
57
+ "default": "./src/notifications.ts"
58
+ },
59
+ "./operation": {
60
+ "types": "./src/operation.ts",
61
+ "import": "./src/operation.ts",
62
+ "default": "./src/operation.ts"
63
+ },
64
+ "./package.json": "./package.json",
65
+ "./update": {
66
+ "types": "./src/update.ts",
67
+ "import": "./src/update.ts",
68
+ "default": "./src/update.ts"
69
+ }
70
+ },
71
+ "files": [
72
+ "src",
73
+ "README.md",
74
+ "LICENSE"
75
+ ],
76
+ "peerDependencies": {
77
+ "@inflatable-cookie/longhorn": "0.1.0",
78
+ "@tauri-apps/api": "^2.10.1"
79
+ },
80
+ "sideEffects": false,
81
+ "publishConfig": {
82
+ "access": "public"
83
+ }
84
+ }
@@ -0,0 +1,154 @@
1
+ import type {
2
+ ConnectionFailureReporter,
3
+ EventTransport,
4
+ Unlisten,
5
+ } from "@inflatable-cookie/longhorn/core";
6
+ import { TauriEventTransport } from "@inflatable-cookie/longhorn-tauri/events";
7
+
8
+ import type { BridgeCodec } from "@inflatable-cookie/longhorn/bridge";
9
+ import {
10
+ parseBridgeJobTerminalEvent,
11
+ parseBridgeProgressEvent,
12
+ } from "@inflatable-cookie/longhorn/bridge";
13
+ import { BridgeJobTracker } from "@inflatable-cookie/longhorn/bridge";
14
+ import type {
15
+ BridgeJobId,
16
+ BridgeJobTerminalEvent,
17
+ BridgeProgressEvent,
18
+ BridgeRequestId,
19
+ BridgeSessionId,
20
+ DomainId,
21
+ } from "@inflatable-cookie/longhorn/bridge/protocol";
22
+ import type { BridgeStreamSource } from "@inflatable-cookie/longhorn/bridge/stream";
23
+ import { TauriBridgeAdapter } from "./bridge.ts";
24
+
25
+ export const BRIDGE_DOMAIN_EVENT = "longhorn://bridge/domain";
26
+ export const BRIDGE_PROGRESS_EVENT = "longhorn://bridge/progress";
27
+ export const BRIDGE_TERMINAL_EVENT = "longhorn://bridge/terminal";
28
+
29
+ /**
30
+ * Event-capable stream source. `connectBridgeStream` installs `listen` before
31
+ * calling `loadSnapshot`, preserving the required subscription handshake.
32
+ */
33
+ export class TauriBridgeStreamSource implements BridgeStreamSource {
34
+ readonly #transport: EventTransport;
35
+ readonly #adapter: TauriBridgeAdapter;
36
+ readonly #sessionId: BridgeSessionId;
37
+ readonly #domainId: DomainId;
38
+
39
+ constructor(
40
+ sessionId: BridgeSessionId,
41
+ domainId: DomainId,
42
+ transport: EventTransport = new TauriEventTransport(),
43
+ ) {
44
+ this.#sessionId = sessionId;
45
+ this.#domainId = domainId;
46
+ this.#transport = transport;
47
+ this.#adapter = new TauriBridgeAdapter(transport);
48
+ }
49
+
50
+ listen(listener: (value: unknown) => void): Promise<Unlisten> {
51
+ return this.#transport.listen(BRIDGE_DOMAIN_EVENT, listener);
52
+ }
53
+
54
+ loadSnapshot(): Promise<unknown> {
55
+ return this.#adapter.resync(this.#sessionId, this.#domainId);
56
+ }
57
+ }
58
+
59
+ export interface BridgeJobListeners<Progress, Success, Detail> {
60
+ readonly progressCodec: BridgeCodec<Progress>;
61
+ readonly successCodec: BridgeCodec<Success>;
62
+ readonly detailCodec: BridgeCodec<Detail>;
63
+ readonly progress?: (event: BridgeProgressEvent<Progress>) => void;
64
+ readonly terminal: (
65
+ event: BridgeJobTerminalEvent<Success, Detail>,
66
+ ) => void;
67
+ /**
68
+ * Reports a malformed event or a teardown failure, mirroring
69
+ * `CheckedSnapshotConnection`. A malformed terminal event is the only way
70
+ * the job would otherwise never terminate for the consumer, so one parse
71
+ * failure reports `{ phase: "event" }` and tears both listeners down.
72
+ */
73
+ readonly onFailure?: ConnectionFailureReporter;
74
+ }
75
+
76
+ /**
77
+ * Installs request/job-correlated progress and terminal listeners.
78
+ * Wrong-correlation and post-terminal messages never reach consumers.
79
+ */
80
+ export async function listenTauriBridgeJob<Progress, Success, Detail>(
81
+ requestId: BridgeRequestId,
82
+ jobId: BridgeJobId,
83
+ listeners: BridgeJobListeners<Progress, Success, Detail>,
84
+ transport: EventTransport = new TauriEventTransport(),
85
+ ): Promise<Unlisten> {
86
+ const tracker = new BridgeJobTracker(requestId, jobId);
87
+ let failed = false;
88
+ let disposeProgress: Unlisten | undefined;
89
+ let disposeTerminal: Unlisten | undefined;
90
+
91
+ const close = async (): Promise<void> => {
92
+ const pending = [disposeTerminal, disposeProgress].filter(
93
+ (unlisten): unlisten is Unlisten => unlisten !== undefined,
94
+ );
95
+ disposeTerminal = undefined;
96
+ disposeProgress = undefined;
97
+ const results = await Promise.allSettled(pending.map((unlisten) => unlisten()));
98
+ for (const result of results) {
99
+ if (result.status === "rejected") throw result.reason;
100
+ }
101
+ };
102
+
103
+ const report = (error: unknown): void => {
104
+ if (failed) return;
105
+ failed = true;
106
+ listeners.onFailure?.({ phase: "event", error });
107
+ void close().catch((teardownError) => {
108
+ listeners.onFailure?.({ phase: "unlisten", error: teardownError });
109
+ });
110
+ };
111
+
112
+ disposeProgress = await transport.listen(
113
+ BRIDGE_PROGRESS_EVENT,
114
+ (value) => {
115
+ if (failed) return;
116
+ try {
117
+ const event = parseBridgeProgressEvent(
118
+ value,
119
+ listeners.progressCodec,
120
+ );
121
+ if (tracker.classifyProgress(event) === "accept") {
122
+ listeners.progress?.(event);
123
+ }
124
+ } catch (error) {
125
+ report(error);
126
+ }
127
+ },
128
+ );
129
+ try {
130
+ disposeTerminal = await transport.listen(
131
+ BRIDGE_TERMINAL_EVENT,
132
+ (value) => {
133
+ if (failed) return;
134
+ try {
135
+ const event = parseBridgeJobTerminalEvent(
136
+ value,
137
+ listeners.successCodec,
138
+ listeners.detailCodec,
139
+ );
140
+ if (tracker.classifyTerminal(event) === "accept") {
141
+ listeners.terminal(event);
142
+ }
143
+ } catch (error) {
144
+ report(error);
145
+ }
146
+ },
147
+ );
148
+ } catch (error) {
149
+ await disposeProgress();
150
+ disposeProgress = undefined;
151
+ throw error;
152
+ }
153
+ return close;
154
+ }
package/src/bridge.ts ADDED
@@ -0,0 +1,100 @@
1
+ import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
2
+ import { TauriTransport } from "@inflatable-cookie/longhorn-tauri";
3
+
4
+ import type {
5
+ BridgeHelloRequest,
6
+ BridgeSessionId,
7
+ DomainId,
8
+ } from "@inflatable-cookie/longhorn/bridge/protocol";
9
+ import type {
10
+ BridgeOperationAdapter,
11
+ BridgeOperationDescriptor,
12
+ } from "@inflatable-cookie/longhorn/bridge";
13
+ import {
14
+ BridgeDomainClient,
15
+ } from "@inflatable-cookie/longhorn/bridge";
16
+ import type { BridgeNegotiationAdapter } from "@inflatable-cookie/longhorn/bridge";
17
+ import {
18
+ BridgeSession,
19
+ BridgeSessionClient,
20
+ } from "@inflatable-cookie/longhorn/bridge";
21
+
22
+ export const BRIDGE_HELLO_COMMAND = "longhorn_bridge_hello";
23
+ export const BRIDGE_AUTHORITY_COMMAND = "longhorn_bridge_authority";
24
+ export const BRIDGE_QUERY_COMMAND = "longhorn_bridge_query";
25
+ export const BRIDGE_COMMAND_COMMAND = "longhorn_bridge_command";
26
+ export const BRIDGE_CANCEL_COMMAND = "longhorn_bridge_cancel";
27
+ export const BRIDGE_RESYNC_COMMAND = "longhorn_bridge_resync";
28
+
29
+ /**
30
+ * Generic bridge commands over the raw invoke-only Tauri edge.
31
+ *
32
+ * Domain routes and payload vocabulary arrive only through operation
33
+ * descriptors owned by adapted domain packages.
34
+ */
35
+ export class TauriBridgeAdapter
36
+ implements BridgeNegotiationAdapter, BridgeOperationAdapter {
37
+ readonly #transport: InvokeTransport;
38
+
39
+ constructor(transport: InvokeTransport = new TauriTransport()) {
40
+ this.#transport = transport;
41
+ }
42
+
43
+ negotiate(request: BridgeHelloRequest): Promise<unknown> {
44
+ return this.#transport.invoke(BRIDGE_HELLO_COMMAND, { request });
45
+ }
46
+
47
+ authority(sessionId: BridgeSessionId): Promise<unknown> {
48
+ return this.#transport.invoke(BRIDGE_AUTHORITY_COMMAND, { sessionId });
49
+ }
50
+
51
+ invoke<Request, Reply>(
52
+ operation: BridgeOperationDescriptor<Request, Reply>,
53
+ request: Request,
54
+ ): Promise<unknown> {
55
+ return this.#transport.invoke(commandFor(operation), {
56
+ route: operation.route,
57
+ request,
58
+ });
59
+ }
60
+
61
+ resync(sessionId: BridgeSessionId, domainId: DomainId): Promise<unknown> {
62
+ return this.#transport.invoke(BRIDGE_RESYNC_COMMAND, {
63
+ sessionId,
64
+ domainId,
65
+ });
66
+ }
67
+ }
68
+
69
+ export interface TauriBridgeConnection {
70
+ readonly session: BridgeSession;
71
+ readonly domain: BridgeDomainClient;
72
+ readonly adapter: TauriBridgeAdapter;
73
+ }
74
+
75
+ /// Negotiates before exposing a Tauri-backed checked domain client.
76
+ export async function connectTauriBridge(
77
+ request: BridgeHelloRequest,
78
+ transport?: InvokeTransport,
79
+ ): Promise<TauriBridgeConnection> {
80
+ const adapter = new TauriBridgeAdapter(transport);
81
+ const session = await new BridgeSessionClient(adapter).connect(request);
82
+ return {
83
+ session,
84
+ domain: new BridgeDomainClient(session, adapter),
85
+ adapter,
86
+ };
87
+ }
88
+
89
+ function commandFor<Request, Reply>(
90
+ operation: BridgeOperationDescriptor<Request, Reply>,
91
+ ): string {
92
+ switch (operation.kind) {
93
+ case "query":
94
+ return BRIDGE_QUERY_COMMAND;
95
+ case "command":
96
+ return BRIDGE_COMMAND_COMMAND;
97
+ case "cancellation":
98
+ return BRIDGE_CANCEL_COMMAND;
99
+ }
100
+ }
@@ -0,0 +1,25 @@
1
+ import { isEventTransport, type EventTransport, type InvokeTransport } from "@inflatable-cookie/longhorn/core";
2
+ import type { ForkHistoryPort } from "@inflatable-cookie/longhorn/history-tree";
3
+ export const FORK_HISTORY_SNAPSHOT_COMMAND = "longhorn_history_tree_snapshot";
4
+ export const FORK_HISTORY_PATH_COMMAND = "longhorn_history_tree_path";
5
+ export const FORK_HISTORY_BRANCHES_COMMAND = "longhorn_history_tree_branches";
6
+ export const FORK_HISTORY_CONTINUATIONS_COMMAND = "longhorn_history_tree_continuations";
7
+ export const FORK_HISTORY_DELETE_COMMAND = "longhorn_history_tree_delete_continuation";
8
+ export const FORK_HISTORY_PRUNE_COMMAND = "longhorn_history_tree_prune";
9
+ export const FORK_HISTORY_NAVIGATE_COMMAND = "longhorn_history_tree_navigate";
10
+ export const FORK_HISTORY_CHANGED_EVENT = "longhorn://history-tree/changed";
11
+ export function createTauriForkHistoryPort(options: { readonly transport: InvokeTransport; readonly nextPlanId: () => string }): ForkHistoryPort {
12
+ const events = isEventTransport(options.transport) ? options.transport : undefined;
13
+ return {
14
+ snapshot: () => options.transport.invoke(FORK_HISTORY_SNAPSHOT_COMMAND, {}),
15
+ path: (command) => options.transport.invoke(FORK_HISTORY_PATH_COMMAND, { command }),
16
+ branches: (command) => options.transport.invoke(FORK_HISTORY_BRANCHES_COMMAND, { command }),
17
+ continuations: (command) => options.transport.invoke(FORK_HISTORY_CONTINUATIONS_COMMAND, { command }),
18
+ deleteContinuation: (command) => options.transport.invoke(FORK_HISTORY_DELETE_COMMAND, { command }),
19
+ prune: (command) => options.transport.invoke(FORK_HISTORY_PRUNE_COMMAND, { command }),
20
+ navigate: (command) => options.transport.invoke(FORK_HISTORY_NAVIGATE_COMMAND, { command }),
21
+ listen: events === undefined ? undefined : (listener) => listen(events, listener),
22
+ nextPlanId: options.nextPlanId,
23
+ };
24
+ }
25
+ function listen(events: EventTransport, listener: (event: unknown) => void) { return events.listen(FORK_HISTORY_CHANGED_EVENT, listener); }
package/src/history.ts ADDED
@@ -0,0 +1,44 @@
1
+ import {
2
+ isEventTransport,
3
+ type EventTransport,
4
+ type InvokeTransport,
5
+ } from "@inflatable-cookie/longhorn/core";
6
+
7
+ import type { HistoryPort } from "@inflatable-cookie/longhorn/history";
8
+
9
+ export const HISTORY_SNAPSHOT_COMMAND = "longhorn_history_snapshot";
10
+ export const HISTORY_PAGE_COMMAND = "longhorn_history_page";
11
+ export const HISTORY_NAVIGATE_COMMAND = "longhorn_history_navigate";
12
+ export const HISTORY_CHANGED_EVENT = "longhorn://history/changed";
13
+
14
+ export interface TauriHistoryPortOptions {
15
+ readonly transport: InvokeTransport;
16
+ readonly nextPlanId: () => string;
17
+ }
18
+
19
+ export function createTauriHistoryPort(
20
+ options: TauriHistoryPortOptions,
21
+ ): HistoryPort {
22
+ const events = isEventTransport(options.transport)
23
+ ? options.transport
24
+ : undefined;
25
+ return {
26
+ snapshot: () => options.transport.invoke(HISTORY_SNAPSHOT_COMMAND, {}),
27
+ page: (command) =>
28
+ options.transport.invoke(HISTORY_PAGE_COMMAND, { command }),
29
+ navigate: (command) =>
30
+ options.transport.invoke(HISTORY_NAVIGATE_COMMAND, { command }),
31
+ listen:
32
+ events === undefined
33
+ ? undefined
34
+ : (listener) => listenChanged(events, listener),
35
+ nextPlanId: options.nextPlanId,
36
+ };
37
+ }
38
+
39
+ async function listenChanged(
40
+ transport: EventTransport,
41
+ listener: (event: unknown) => void,
42
+ ) {
43
+ return transport.listen(HISTORY_CHANGED_EVENT, listener);
44
+ }
package/src/licence.ts ADDED
@@ -0,0 +1,38 @@
1
+ import { isEventTransport, type EventTransport, type InvokeTransport } from "@inflatable-cookie/longhorn/core";
2
+ import type {
3
+ LicenceActivateCommand,
4
+ LicenceDeactivateCommand,
5
+ LicencePort,
6
+ LicenceRefreshCommand,
7
+ LicenceReleaseSeatCommand,
8
+ LicenceRenameSeatCommand,
9
+ LicenceUnlisten,
10
+ } from "@inflatable-cookie/longhorn/licence";
11
+ export const LICENCE_SNAPSHOT_COMMAND = "longhorn_licence_snapshot";
12
+ export const LICENCE_ACTIVATE_COMMAND = "longhorn_licence_activate";
13
+ export const LICENCE_DEACTIVATE_COMMAND = "longhorn_licence_deactivate";
14
+ export const LICENCE_REFRESH_COMMAND = "longhorn_licence_refresh";
15
+ export const LICENCE_RELEASE_SEAT_COMMAND = "longhorn_licence_release_seat";
16
+ export const LICENCE_RENAME_SEAT_COMMAND = "longhorn_licence_rename_seat";
17
+ export const LICENCE_CHANGED_EVENT = "longhorn://licence/changed";
18
+ /**
19
+ * The licence seam.
20
+ *
21
+ * Six commands over four host capabilities: reading state, re-checking the
22
+ * lease, presenting a credential, and managing seats are different grants.
23
+ * Results are `unknown`, as every raw port's are — `LicenceClient` is what
24
+ * narrows them. Commands going out are typed, because this side builds those.
25
+ */
26
+ export function createTauriLicencePort(options: { readonly transport: InvokeTransport }): LicencePort {
27
+ const events = isEventTransport(options.transport) ? options.transport : undefined;
28
+ return {
29
+ snapshot: () => options.transport.invoke(LICENCE_SNAPSHOT_COMMAND, {}),
30
+ activate: (command: LicenceActivateCommand) => options.transport.invoke(LICENCE_ACTIVATE_COMMAND, { command }),
31
+ deactivate: (command: LicenceDeactivateCommand) => options.transport.invoke(LICENCE_DEACTIVATE_COMMAND, { command }),
32
+ refresh: (command: LicenceRefreshCommand) => options.transport.invoke(LICENCE_REFRESH_COMMAND, { command }),
33
+ releaseSeat: (command: LicenceReleaseSeatCommand) => options.transport.invoke(LICENCE_RELEASE_SEAT_COMMAND, { command }),
34
+ renameSeat: (command: LicenceRenameSeatCommand) => options.transport.invoke(LICENCE_RENAME_SEAT_COMMAND, { command }),
35
+ listen: events === undefined ? undefined : (listener) => listen(events, listener),
36
+ };
37
+ }
38
+ function listen(events: EventTransport, listener: (event: unknown) => void): Promise<LicenceUnlisten> { return events.listen(LICENCE_CHANGED_EVENT, listener); }
@@ -0,0 +1,55 @@
1
+ import {
2
+ isEventTransport,
3
+ type EventTransport,
4
+ type InvokeTransport,
5
+ } from "@inflatable-cookie/longhorn/core";
6
+
7
+ import type { NativeContentPort } from "@inflatable-cookie/longhorn/native-content";
8
+
9
+ export const NATIVE_CONTENT_CONNECT_COMMAND =
10
+ "longhorn_native_content_connect";
11
+ export const NATIVE_CONTENT_SNAPSHOT_COMMAND =
12
+ "longhorn_native_content_snapshot";
13
+ export const NATIVE_CONTENT_UPDATE_DESIRED_COMMAND =
14
+ "longhorn_native_content_update_desired";
15
+ export const NATIVE_CONTENT_DECIDE_SIZE_COMMAND =
16
+ "longhorn_native_content_decide_size";
17
+ export const NATIVE_CONTENT_CHANGED_EVENT =
18
+ "longhorn://native-content/changed";
19
+
20
+ export interface TauriNativeContentPortOptions {
21
+ readonly transport: InvokeTransport;
22
+ readonly nextRequestId: () => string;
23
+ }
24
+
25
+ export function createTauriNativeContentPort(
26
+ options: TauriNativeContentPortOptions,
27
+ ): NativeContentPort {
28
+ const events = isEventTransport(options.transport)
29
+ ? options.transport
30
+ : undefined;
31
+ return {
32
+ connect: (request) =>
33
+ options.transport.invoke(NATIVE_CONTENT_CONNECT_COMMAND, { request }),
34
+ snapshot: (request) =>
35
+ options.transport.invoke(NATIVE_CONTENT_SNAPSHOT_COMMAND, { request }),
36
+ updateDesired: (request) =>
37
+ options.transport.invoke(NATIVE_CONTENT_UPDATE_DESIRED_COMMAND, {
38
+ request,
39
+ }),
40
+ decideContentSize: (request) =>
41
+ options.transport.invoke(NATIVE_CONTENT_DECIDE_SIZE_COMMAND, { request }),
42
+ listen:
43
+ events === undefined
44
+ ? undefined
45
+ : (listener) => listenChanged(events, listener),
46
+ nextRequestId: options.nextRequestId,
47
+ };
48
+ }
49
+
50
+ function listenChanged(
51
+ transport: EventTransport,
52
+ listener: (event: unknown) => void,
53
+ ) {
54
+ return transport.listen(NATIVE_CONTENT_CHANGED_EVENT, listener);
55
+ }
@@ -0,0 +1,26 @@
1
+ import { isEventTransport, type EventTransport, type InvokeTransport } from "@inflatable-cookie/longhorn/core";
2
+
3
+ import type { NotificationPort } from "@inflatable-cookie/longhorn/notifications";
4
+
5
+ export const NOTIFICATION_SNAPSHOT_COMMAND = "longhorn_notifications_snapshot";
6
+ export const NOTIFICATION_MUTATE_COMMAND = "longhorn_notifications_mutate";
7
+ export const NOTIFICATION_CHANGED_EVENT = "longhorn://notifications/changed";
8
+
9
+ export interface TauriNotificationPortOptions {
10
+ readonly transport: InvokeTransport;
11
+ readonly nextRequestId: () => string;
12
+ }
13
+
14
+ export function createTauriNotificationPort(options: TauriNotificationPortOptions): NotificationPort {
15
+ const events = isEventTransport(options.transport) ? options.transport : undefined;
16
+ return {
17
+ snapshot: (query) => options.transport.invoke(NOTIFICATION_SNAPSHOT_COMMAND, { query }),
18
+ mutate: (command) => options.transport.invoke(NOTIFICATION_MUTATE_COMMAND, { command }),
19
+ listen: events === undefined ? undefined : (listener) => listenChanged(events, listener),
20
+ nextRequestId: options.nextRequestId,
21
+ };
22
+ }
23
+
24
+ function listenChanged(transport: EventTransport, listener: (event: unknown) => void) {
25
+ return transport.listen(NOTIFICATION_CHANGED_EVENT, listener);
26
+ }
@@ -0,0 +1,45 @@
1
+ import {
2
+ isEventTransport,
3
+ type EventTransport,
4
+ type InvokeTransport,
5
+ } from "@inflatable-cookie/longhorn/core";
6
+
7
+ import type { OperationPort } from "@inflatable-cookie/longhorn/operation";
8
+
9
+ export const OPERATION_SNAPSHOT_COMMAND = "longhorn_operation_snapshot";
10
+ export const OPERATION_MUTATE_COMMAND = "longhorn_operation_mutate";
11
+ export const OPERATION_CANCEL_COMMAND = "longhorn_operation_cancel";
12
+ export const OPERATION_CHANGED_EVENT = "longhorn://operation/changed";
13
+
14
+ export interface TauriOperationPortOptions {
15
+ readonly transport: InvokeTransport;
16
+ readonly nextRequestId: () => string;
17
+ }
18
+
19
+ export function createTauriOperationPort(
20
+ options: TauriOperationPortOptions,
21
+ ): OperationPort {
22
+ const events = isEventTransport(options.transport)
23
+ ? options.transport
24
+ : undefined;
25
+ return {
26
+ snapshot: (query) =>
27
+ options.transport.invoke(OPERATION_SNAPSHOT_COMMAND, { query }),
28
+ mutate: (command) =>
29
+ options.transport.invoke(OPERATION_MUTATE_COMMAND, { command }),
30
+ cancel: (command) =>
31
+ options.transport.invoke(OPERATION_CANCEL_COMMAND, { command }),
32
+ listen:
33
+ events === undefined
34
+ ? undefined
35
+ : (listener) => listenChanged(events, listener),
36
+ nextRequestId: options.nextRequestId,
37
+ };
38
+ }
39
+
40
+ function listenChanged(
41
+ transport: EventTransport,
42
+ listener: (event: unknown) => void,
43
+ ) {
44
+ return transport.listen(OPERATION_CHANGED_EVENT, listener);
45
+ }
@@ -0,0 +1,17 @@
1
+ import { listen } from "@tauri-apps/api/event";
2
+
3
+ import type { EventTransport, Unlisten } from "@inflatable-cookie/longhorn/core";
4
+
5
+ import { TauriTransport } from "./index.ts";
6
+
7
+ /// Optional raw Tauri invoke/listen edge.
8
+ export class TauriEventTransport
9
+ extends TauriTransport
10
+ implements EventTransport {
11
+ listen(
12
+ event: string,
13
+ listener: (payload: unknown) => void,
14
+ ): Promise<Unlisten> {
15
+ return listen(event, ({ payload }) => listener(payload));
16
+ }
17
+ }
@@ -0,0 +1,12 @@
1
+ import { invoke } from "@tauri-apps/api/core";
2
+
3
+ import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
4
+
5
+ export class TauriTransport implements InvokeTransport {
6
+ invoke(
7
+ command: string,
8
+ arguments_: Record<string, unknown>,
9
+ ): Promise<unknown> {
10
+ return invoke(command, arguments_);
11
+ }
12
+ }
package/src/update.ts ADDED
@@ -0,0 +1,40 @@
1
+ import { isEventTransport, type EventTransport, type InvokeTransport } from "@inflatable-cookie/longhorn/core";
2
+ import type {
3
+ UpdateCheckCommand,
4
+ UpdateDeferCommand,
5
+ UpdateInstallCommand,
6
+ UpdatePort,
7
+ UpdateSelectChannelCommand,
8
+ UpdateUnlisten,
9
+ } from "@inflatable-cookie/longhorn/update";
10
+ export const UPDATE_SNAPSHOT_COMMAND = "longhorn_update_snapshot";
11
+ export const UPDATE_CHECK_COMMAND = "longhorn_update_check";
12
+ export const UPDATE_SELECT_CHANNEL_COMMAND = "longhorn_update_select_channel";
13
+ export const UPDATE_DEFER_COMMAND = "longhorn_update_defer";
14
+ export const UPDATE_INSTALL_COMMAND = "longhorn_update_install";
15
+ export const UPDATE_CHANGED_EVENT = "longhorn://update/changed";
16
+ /**
17
+ * The update seam.
18
+ *
19
+ * Four commands and a read, mirroring `UpdateController`. Each is its own
20
+ * invoke because each is its own capability on the host side: reading state,
21
+ * reaching the network, changing what this install follows, and replacing the
22
+ * running application are four different grants.
23
+ *
24
+ * Results are `unknown`, as every other raw port's are. What comes back over a
25
+ * transport is untrusted until a validator says otherwise; `UpdateClient` is
26
+ * what narrows them. Commands going *out* are typed, because those this side
27
+ * constructs.
28
+ */
29
+ export function createTauriUpdatePort(options: { readonly transport: InvokeTransport }): UpdatePort {
30
+ const events = isEventTransport(options.transport) ? options.transport : undefined;
31
+ return {
32
+ snapshot: () => options.transport.invoke(UPDATE_SNAPSHOT_COMMAND, {}),
33
+ check: (command) => options.transport.invoke(UPDATE_CHECK_COMMAND, { command }),
34
+ selectChannel: (command) => options.transport.invoke(UPDATE_SELECT_CHANNEL_COMMAND, { command }),
35
+ defer: (command) => options.transport.invoke(UPDATE_DEFER_COMMAND, { command }),
36
+ install: (command) => options.transport.invoke(UPDATE_INSTALL_COMMAND, { command }),
37
+ listen: events === undefined ? undefined : (listener) => listen(events, listener),
38
+ };
39
+ }
40
+ function listen(events: EventTransport, listener: (event: unknown) => void): Promise<UpdateUnlisten> { return events.listen(UPDATE_CHANGED_EVENT, listener); }