@inflatable-cookie/longhorn-tauri 0.7.0 → 0.7.1
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/dist/bridge-events.d.ts +43 -0
- package/dist/bridge-events.js +160 -0
- package/dist/bridge.d.ts +31 -0
- package/dist/bridge.js +59 -0
- package/dist/history-tree.d.ts +14 -0
- package/dist/history-tree.js +26 -0
- package/dist/history.d.ts +11 -0
- package/dist/history.js +18 -0
- package/dist/licence.d.ts +20 -0
- package/dist/licence.js +31 -0
- package/dist/native-content.d.ts +12 -0
- package/dist/native-content.js +22 -0
- package/dist/notifications.d.ts +10 -0
- package/dist/notifications.js +16 -0
- package/dist/operation.d.ts +11 -0
- package/dist/operation.js +18 -0
- package/dist/transport/events.d.ts +5 -0
- package/dist/transport/events.js +22 -0
- package/dist/transport/index.d.ts +12 -0
- package/dist/transport/index.js +59 -0
- package/dist/update.d.ts +24 -0
- package/dist/update.js +46 -0
- package/package.json +40 -37
- package/src/bridge-events.ts +0 -215
- package/src/bridge.ts +0 -93
- package/src/history-tree.ts +0 -33
- package/src/history.ts +0 -29
- package/src/licence.ts +0 -51
- package/src/native-content.ts +0 -37
- package/src/notifications.ts +0 -29
- package/src/operation.ts +0 -29
- package/src/transport/events.ts +0 -36
- package/src/transport/index.ts +0 -74
- package/src/update.ts +0 -73
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ConnectionFailureReporter, EventTransport, Unlisten } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type { BridgeCodec } from "@inflatable-cookie/longhorn/bridge";
|
|
3
|
+
import type { BridgeJobId, BridgeJobTerminalEvent, BridgeProgressEvent, BridgeRequestId, BridgeSessionId, DomainId } from "@inflatable-cookie/longhorn/bridge/protocol";
|
|
4
|
+
import type { BridgeStreamSource } from "@inflatable-cookie/longhorn/bridge/stream";
|
|
5
|
+
export declare const BRIDGE_DOMAIN_EVENT = "longhorn://bridge/domain";
|
|
6
|
+
export declare const BRIDGE_PROGRESS_EVENT = "longhorn://bridge/progress";
|
|
7
|
+
export declare const BRIDGE_TERMINAL_EVENT = "longhorn://bridge/terminal";
|
|
8
|
+
/**
|
|
9
|
+
* Event-capable stream source. `connectBridgeStream` installs `listen` before
|
|
10
|
+
* calling `loadSnapshot`, preserving the required subscription handshake.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TauriBridgeStreamSource implements BridgeStreamSource {
|
|
13
|
+
#private;
|
|
14
|
+
constructor(sessionId: BridgeSessionId, domainId: DomainId, transport?: EventTransport);
|
|
15
|
+
listen(listener: (value: unknown) => void): Promise<Unlisten>;
|
|
16
|
+
loadSnapshot(): Promise<unknown>;
|
|
17
|
+
}
|
|
18
|
+
export interface BridgeJobListeners<Progress, Success, Detail> {
|
|
19
|
+
readonly progressCodec: BridgeCodec<Progress>;
|
|
20
|
+
readonly successCodec: BridgeCodec<Success>;
|
|
21
|
+
readonly detailCodec: BridgeCodec<Detail>;
|
|
22
|
+
readonly progress?: (event: BridgeProgressEvent<Progress>) => void;
|
|
23
|
+
readonly terminal: (event: BridgeJobTerminalEvent<Success, Detail>) => void;
|
|
24
|
+
/**
|
|
25
|
+
* Reports a malformed event for this job or a teardown failure, mirroring
|
|
26
|
+
* `CheckedSnapshotConnection`. A malformed terminal event is the only way
|
|
27
|
+
* the job would otherwise never terminate for the consumer, so one parse
|
|
28
|
+
* failure reports `{ phase: "event" }` and tears both listeners down.
|
|
29
|
+
*/
|
|
30
|
+
readonly onFailure?: ConnectionFailureReporter;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Installs request/job-correlated progress and terminal listeners.
|
|
34
|
+
* Wrong-correlation messages are dropped before their payload is decoded, and
|
|
35
|
+
* post-terminal messages are dropped without decoding, so neither can fail
|
|
36
|
+
* this job or reach consumers.
|
|
37
|
+
*
|
|
38
|
+
* Contract 010 makes events projections, not durable delivery, and the bridge
|
|
39
|
+
* has no job-status query. A terminal that fires before its listener is
|
|
40
|
+
* registered (the jobId is only known once the job has started) is therefore
|
|
41
|
+
* not recovered here; see docs/knowledge/questions.md.
|
|
42
|
+
*/
|
|
43
|
+
export declare function listenTauriBridgeJob<Progress, Success, Detail>(requestId: BridgeRequestId, jobId: BridgeJobId, listeners: BridgeJobListeners<Progress, Success, Detail>, transport?: EventTransport): Promise<Unlisten>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { TauriEventTransport } from "@inflatable-cookie/longhorn-tauri/events";
|
|
2
|
+
import { parseBridgeJobTerminalEvent, parseBridgeProgressEvent, } from "@inflatable-cookie/longhorn/bridge";
|
|
3
|
+
import { BridgeJobTracker } from "@inflatable-cookie/longhorn/bridge";
|
|
4
|
+
import { TauriBridgeAdapter } from "./bridge.js";
|
|
5
|
+
export const BRIDGE_DOMAIN_EVENT = "longhorn://bridge/domain";
|
|
6
|
+
export const BRIDGE_PROGRESS_EVENT = "longhorn://bridge/progress";
|
|
7
|
+
export const BRIDGE_TERMINAL_EVENT = "longhorn://bridge/terminal";
|
|
8
|
+
const bridgeDelivery = { scope: "renderer-local" };
|
|
9
|
+
/**
|
|
10
|
+
* Event-capable stream source. `connectBridgeStream` installs `listen` before
|
|
11
|
+
* calling `loadSnapshot`, preserving the required subscription handshake.
|
|
12
|
+
*/
|
|
13
|
+
export class TauriBridgeStreamSource {
|
|
14
|
+
#transport;
|
|
15
|
+
#adapter;
|
|
16
|
+
#sessionId;
|
|
17
|
+
#domainId;
|
|
18
|
+
constructor(sessionId, domainId, transport = new TauriEventTransport()) {
|
|
19
|
+
this.#sessionId = sessionId;
|
|
20
|
+
this.#domainId = domainId;
|
|
21
|
+
this.#transport = transport;
|
|
22
|
+
this.#adapter = new TauriBridgeAdapter(transport);
|
|
23
|
+
}
|
|
24
|
+
listen(listener) {
|
|
25
|
+
return this.#transport.listen(BRIDGE_DOMAIN_EVENT, listener, bridgeDelivery);
|
|
26
|
+
}
|
|
27
|
+
loadSnapshot() {
|
|
28
|
+
return this.#adapter.resync(this.#sessionId, this.#domainId);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Installs request/job-correlated progress and terminal listeners.
|
|
33
|
+
* Wrong-correlation messages are dropped before their payload is decoded, and
|
|
34
|
+
* post-terminal messages are dropped without decoding, so neither can fail
|
|
35
|
+
* this job or reach consumers.
|
|
36
|
+
*
|
|
37
|
+
* Contract 010 makes events projections, not durable delivery, and the bridge
|
|
38
|
+
* has no job-status query. A terminal that fires before its listener is
|
|
39
|
+
* registered (the jobId is only known once the job has started) is therefore
|
|
40
|
+
* not recovered here; see docs/knowledge/questions.md.
|
|
41
|
+
*/
|
|
42
|
+
export async function listenTauriBridgeJob(requestId, jobId, listeners, transport = new TauriEventTransport()) {
|
|
43
|
+
const tracker = new BridgeJobTracker(requestId, jobId);
|
|
44
|
+
// Set once the job has failed or been closed. Nothing reaches the consumer
|
|
45
|
+
// after that, and a registration that completes later is released at once.
|
|
46
|
+
let stopped = false;
|
|
47
|
+
let registered = false;
|
|
48
|
+
const unlistens = [];
|
|
49
|
+
// Last registered, first released.
|
|
50
|
+
const teardown = async () => {
|
|
51
|
+
const pending = unlistens.splice(0).reverse();
|
|
52
|
+
const results = await Promise.allSettled(pending.map((unlisten) => Promise.resolve().then(() => unlisten())));
|
|
53
|
+
for (const result of results) {
|
|
54
|
+
if (result.status === "rejected") {
|
|
55
|
+
throw result.reason;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
const reportUnlistenFailure = (error) => {
|
|
60
|
+
try {
|
|
61
|
+
listeners.onFailure?.({ phase: "unlisten", error });
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// A secondary reporter failure cannot replace the original error.
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const notify = (callback) => {
|
|
68
|
+
try {
|
|
69
|
+
callback();
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
// A transport may deliver inline before returning its unlisten.
|
|
73
|
+
if (registered) {
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const fail = (error) => {
|
|
79
|
+
if (stopped) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
stopped = true;
|
|
83
|
+
void teardown().catch(reportUnlistenFailure);
|
|
84
|
+
notify(() => listeners.onFailure?.({ phase: "event", error }));
|
|
85
|
+
};
|
|
86
|
+
const adopt = async (unlisten) => {
|
|
87
|
+
if (!stopped) {
|
|
88
|
+
unlistens.push(unlisten);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
try {
|
|
92
|
+
await unlisten();
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
reportUnlistenFailure(error);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
// The channels are shared by every job, so admission comes before any
|
|
99
|
+
// job-specific decode: another job's payload cannot fail this one. A value
|
|
100
|
+
// from another request is refused on its request id alone. Identifiers that
|
|
101
|
+
// cannot be read as part of this request are malformed.
|
|
102
|
+
const admits = (value) => {
|
|
103
|
+
try {
|
|
104
|
+
return tracker.admits(value);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
fail(error);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const onProgress = (value) => {
|
|
112
|
+
if (stopped || tracker.isTerminal() || !admits(value)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
let event;
|
|
116
|
+
try {
|
|
117
|
+
event = parseBridgeProgressEvent(value, listeners.progressCodec);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
fail(error);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (tracker.classifyProgress(event) === "accept") {
|
|
124
|
+
notify(() => listeners.progress?.(event));
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const onTerminal = (value) => {
|
|
128
|
+
// After this job's terminal, input is not decoded at all: a late or
|
|
129
|
+
// malformed event cannot fail a job that has already settled.
|
|
130
|
+
if (stopped || tracker.isTerminal() || !admits(value)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
let event;
|
|
134
|
+
try {
|
|
135
|
+
event = parseBridgeJobTerminalEvent(value, listeners.successCodec, listeners.detailCodec);
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
fail(error);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (tracker.classifyTerminal(event) === "accept") {
|
|
142
|
+
notify(() => listeners.terminal(event));
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const close = async () => {
|
|
146
|
+
stopped = true;
|
|
147
|
+
await teardown();
|
|
148
|
+
};
|
|
149
|
+
try {
|
|
150
|
+
await adopt(await transport.listen(BRIDGE_PROGRESS_EVENT, onProgress, bridgeDelivery));
|
|
151
|
+
await adopt(await transport.listen(BRIDGE_TERMINAL_EVENT, onTerminal, bridgeDelivery));
|
|
152
|
+
registered = true;
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
stopped = true;
|
|
156
|
+
await teardown().catch(reportUnlistenFailure);
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
return close;
|
|
160
|
+
}
|
package/dist/bridge.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type { BridgeHelloRequest, BridgeSessionId, DomainId } from "@inflatable-cookie/longhorn/bridge/protocol";
|
|
3
|
+
import type { BridgeOperationAdapter, BridgeOperationDescriptor, BridgeSession } from "@inflatable-cookie/longhorn/bridge";
|
|
4
|
+
import { BridgeDomainClient } from "@inflatable-cookie/longhorn/bridge";
|
|
5
|
+
import type { BridgeNegotiationAdapter } from "@inflatable-cookie/longhorn/bridge";
|
|
6
|
+
export declare const BRIDGE_HELLO_COMMAND = "longhorn_bridge_hello";
|
|
7
|
+
export declare const BRIDGE_AUTHORITY_COMMAND = "longhorn_bridge_authority";
|
|
8
|
+
export declare const BRIDGE_QUERY_COMMAND = "longhorn_bridge_query";
|
|
9
|
+
export declare const BRIDGE_COMMAND_COMMAND = "longhorn_bridge_command";
|
|
10
|
+
export declare const BRIDGE_CANCEL_COMMAND = "longhorn_bridge_cancel";
|
|
11
|
+
export declare const BRIDGE_RESYNC_COMMAND = "longhorn_bridge_resync";
|
|
12
|
+
/**
|
|
13
|
+
* Generic bridge commands over the raw invoke-only Tauri edge.
|
|
14
|
+
*
|
|
15
|
+
* Domain routes and payload vocabulary arrive only through operation
|
|
16
|
+
* descriptors owned by adapted domain packages.
|
|
17
|
+
*/
|
|
18
|
+
export declare class TauriBridgeAdapter implements BridgeNegotiationAdapter, BridgeOperationAdapter {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(transport?: InvokeTransport);
|
|
21
|
+
negotiate(request: BridgeHelloRequest): Promise<unknown>;
|
|
22
|
+
authority(sessionId: BridgeSessionId): Promise<unknown>;
|
|
23
|
+
invoke<Request, Reply>(operation: BridgeOperationDescriptor<Request, Reply>, request: Request): Promise<unknown>;
|
|
24
|
+
resync(sessionId: BridgeSessionId, domainId: DomainId): Promise<unknown>;
|
|
25
|
+
}
|
|
26
|
+
export interface TauriBridgeConnection {
|
|
27
|
+
readonly session: BridgeSession;
|
|
28
|
+
readonly domain: BridgeDomainClient;
|
|
29
|
+
readonly adapter: TauriBridgeAdapter;
|
|
30
|
+
}
|
|
31
|
+
export declare function connectTauriBridge(request: BridgeHelloRequest, transport?: InvokeTransport): Promise<TauriBridgeConnection>;
|
package/dist/bridge.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { TauriTransport } from "@inflatable-cookie/longhorn-tauri";
|
|
2
|
+
import { BridgeDomainClient } from "@inflatable-cookie/longhorn/bridge";
|
|
3
|
+
import { BridgeSessionClient } from "@inflatable-cookie/longhorn/bridge";
|
|
4
|
+
export const BRIDGE_HELLO_COMMAND = "longhorn_bridge_hello";
|
|
5
|
+
export const BRIDGE_AUTHORITY_COMMAND = "longhorn_bridge_authority";
|
|
6
|
+
export const BRIDGE_QUERY_COMMAND = "longhorn_bridge_query";
|
|
7
|
+
export const BRIDGE_COMMAND_COMMAND = "longhorn_bridge_command";
|
|
8
|
+
export const BRIDGE_CANCEL_COMMAND = "longhorn_bridge_cancel";
|
|
9
|
+
export const BRIDGE_RESYNC_COMMAND = "longhorn_bridge_resync";
|
|
10
|
+
/**
|
|
11
|
+
* Generic bridge commands over the raw invoke-only Tauri edge.
|
|
12
|
+
*
|
|
13
|
+
* Domain routes and payload vocabulary arrive only through operation
|
|
14
|
+
* descriptors owned by adapted domain packages.
|
|
15
|
+
*/
|
|
16
|
+
export class TauriBridgeAdapter {
|
|
17
|
+
#transport;
|
|
18
|
+
constructor(transport = new TauriTransport()) {
|
|
19
|
+
this.#transport = transport;
|
|
20
|
+
}
|
|
21
|
+
negotiate(request) {
|
|
22
|
+
return this.#transport.invoke(BRIDGE_HELLO_COMMAND, { request });
|
|
23
|
+
}
|
|
24
|
+
authority(sessionId) {
|
|
25
|
+
return this.#transport.invoke(BRIDGE_AUTHORITY_COMMAND, { sessionId });
|
|
26
|
+
}
|
|
27
|
+
invoke(operation, request) {
|
|
28
|
+
return this.#transport.invoke(commandFor(operation), {
|
|
29
|
+
route: operation.route,
|
|
30
|
+
request,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
resync(sessionId, domainId) {
|
|
34
|
+
return this.#transport.invoke(BRIDGE_RESYNC_COMMAND, {
|
|
35
|
+
sessionId,
|
|
36
|
+
domainId,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/// Negotiates before exposing a Tauri-backed checked domain client.
|
|
41
|
+
export async function connectTauriBridge(request, transport) {
|
|
42
|
+
const adapter = new TauriBridgeAdapter(transport);
|
|
43
|
+
const session = await new BridgeSessionClient(adapter).connect(request);
|
|
44
|
+
return {
|
|
45
|
+
session,
|
|
46
|
+
domain: new BridgeDomainClient(session, adapter),
|
|
47
|
+
adapter,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function commandFor(operation) {
|
|
51
|
+
switch (operation.kind) {
|
|
52
|
+
case "query":
|
|
53
|
+
return BRIDGE_QUERY_COMMAND;
|
|
54
|
+
case "command":
|
|
55
|
+
return BRIDGE_COMMAND_COMMAND;
|
|
56
|
+
case "cancellation":
|
|
57
|
+
return BRIDGE_CANCEL_COMMAND;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type { ForkHistoryPort } from "@inflatable-cookie/longhorn/history-tree";
|
|
3
|
+
export declare const FORK_HISTORY_SNAPSHOT_COMMAND = "longhorn_history_tree_snapshot";
|
|
4
|
+
export declare const FORK_HISTORY_PATH_COMMAND = "longhorn_history_tree_path";
|
|
5
|
+
export declare const FORK_HISTORY_BRANCHES_COMMAND = "longhorn_history_tree_branches";
|
|
6
|
+
export declare const FORK_HISTORY_CONTINUATIONS_COMMAND = "longhorn_history_tree_continuations";
|
|
7
|
+
export declare const FORK_HISTORY_DELETE_COMMAND = "longhorn_history_tree_delete_continuation";
|
|
8
|
+
export declare const FORK_HISTORY_PRUNE_COMMAND = "longhorn_history_tree_prune";
|
|
9
|
+
export declare const FORK_HISTORY_NAVIGATE_COMMAND = "longhorn_history_tree_navigate";
|
|
10
|
+
export declare const FORK_HISTORY_CHANGED_EVENT = "longhorn://history-tree/changed";
|
|
11
|
+
export declare function createTauriForkHistoryPort(options: {
|
|
12
|
+
readonly transport: InvokeTransport;
|
|
13
|
+
readonly nextPlanId: () => string;
|
|
14
|
+
}): ForkHistoryPort;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
export const FORK_HISTORY_SNAPSHOT_COMMAND = "longhorn_history_tree_snapshot";
|
|
3
|
+
export const FORK_HISTORY_PATH_COMMAND = "longhorn_history_tree_path";
|
|
4
|
+
export const FORK_HISTORY_BRANCHES_COMMAND = "longhorn_history_tree_branches";
|
|
5
|
+
export const FORK_HISTORY_CONTINUATIONS_COMMAND = "longhorn_history_tree_continuations";
|
|
6
|
+
export const FORK_HISTORY_DELETE_COMMAND = "longhorn_history_tree_delete_continuation";
|
|
7
|
+
export const FORK_HISTORY_PRUNE_COMMAND = "longhorn_history_tree_prune";
|
|
8
|
+
export const FORK_HISTORY_NAVIGATE_COMMAND = "longhorn_history_tree_navigate";
|
|
9
|
+
export const FORK_HISTORY_CHANGED_EVENT = "longhorn://history-tree/changed";
|
|
10
|
+
export function createTauriForkHistoryPort(options) {
|
|
11
|
+
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
12
|
+
return {
|
|
13
|
+
snapshot: () => options.transport.invoke(FORK_HISTORY_SNAPSHOT_COMMAND, {}),
|
|
14
|
+
path: (command) => options.transport.invoke(FORK_HISTORY_PATH_COMMAND, { command }),
|
|
15
|
+
branches: (command) => options.transport.invoke(FORK_HISTORY_BRANCHES_COMMAND, { command }),
|
|
16
|
+
continuations: (command) => options.transport.invoke(FORK_HISTORY_CONTINUATIONS_COMMAND, { command }),
|
|
17
|
+
deleteContinuation: (command) => options.transport.invoke(FORK_HISTORY_DELETE_COMMAND, { command }),
|
|
18
|
+
prune: (command) => options.transport.invoke(FORK_HISTORY_PRUNE_COMMAND, { command }),
|
|
19
|
+
navigate: (command) => options.transport.invoke(FORK_HISTORY_NAVIGATE_COMMAND, { command }),
|
|
20
|
+
listen: events === undefined ? undefined : (listener) => listen(events, listener),
|
|
21
|
+
nextPlanId: options.nextPlanId,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function listen(events, listener) {
|
|
25
|
+
return events.listen(FORK_HISTORY_CHANGED_EVENT, listener);
|
|
26
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type { HistoryPort } from "@inflatable-cookie/longhorn/history";
|
|
3
|
+
export declare const HISTORY_SNAPSHOT_COMMAND = "longhorn_history_snapshot";
|
|
4
|
+
export declare const HISTORY_PAGE_COMMAND = "longhorn_history_page";
|
|
5
|
+
export declare const HISTORY_NAVIGATE_COMMAND = "longhorn_history_navigate";
|
|
6
|
+
export declare const HISTORY_CHANGED_EVENT = "longhorn://history/changed";
|
|
7
|
+
export interface TauriHistoryPortOptions {
|
|
8
|
+
readonly transport: InvokeTransport;
|
|
9
|
+
readonly nextPlanId: () => string;
|
|
10
|
+
}
|
|
11
|
+
export declare function createTauriHistoryPort(options: TauriHistoryPortOptions): HistoryPort;
|
package/dist/history.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
export const HISTORY_SNAPSHOT_COMMAND = "longhorn_history_snapshot";
|
|
3
|
+
export const HISTORY_PAGE_COMMAND = "longhorn_history_page";
|
|
4
|
+
export const HISTORY_NAVIGATE_COMMAND = "longhorn_history_navigate";
|
|
5
|
+
export const HISTORY_CHANGED_EVENT = "longhorn://history/changed";
|
|
6
|
+
export function createTauriHistoryPort(options) {
|
|
7
|
+
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
8
|
+
return {
|
|
9
|
+
snapshot: () => options.transport.invoke(HISTORY_SNAPSHOT_COMMAND, {}),
|
|
10
|
+
page: (command) => options.transport.invoke(HISTORY_PAGE_COMMAND, { command }),
|
|
11
|
+
navigate: (command) => options.transport.invoke(HISTORY_NAVIGATE_COMMAND, { command }),
|
|
12
|
+
listen: events === undefined ? undefined : (listener) => listenChanged(events, listener),
|
|
13
|
+
nextPlanId: options.nextPlanId,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async function listenChanged(transport, listener) {
|
|
17
|
+
return transport.listen(HISTORY_CHANGED_EVENT, listener);
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type { LicencePort } from "@inflatable-cookie/longhorn/licence";
|
|
3
|
+
export declare const LICENCE_SNAPSHOT_COMMAND = "longhorn_licence_snapshot";
|
|
4
|
+
export declare const LICENCE_ACTIVATE_COMMAND = "longhorn_licence_activate";
|
|
5
|
+
export declare const LICENCE_DEACTIVATE_COMMAND = "longhorn_licence_deactivate";
|
|
6
|
+
export declare const LICENCE_REFRESH_COMMAND = "longhorn_licence_refresh";
|
|
7
|
+
export declare const LICENCE_RELEASE_SEAT_COMMAND = "longhorn_licence_release_seat";
|
|
8
|
+
export declare const LICENCE_RENAME_SEAT_COMMAND = "longhorn_licence_rename_seat";
|
|
9
|
+
export declare const LICENCE_CHANGED_EVENT = "longhorn://licence/changed";
|
|
10
|
+
/**
|
|
11
|
+
* The licence seam.
|
|
12
|
+
*
|
|
13
|
+
* Six commands over four host capabilities: reading state, re-checking the
|
|
14
|
+
* lease, presenting a credential, and managing seats are different grants.
|
|
15
|
+
* Results are `unknown`, as every raw port's are — `LicenceClient` is what
|
|
16
|
+
* narrows them. Commands going out are typed, because this side builds those.
|
|
17
|
+
*/
|
|
18
|
+
export declare function createTauriLicencePort(options: {
|
|
19
|
+
readonly transport: InvokeTransport;
|
|
20
|
+
}): LicencePort;
|
package/dist/licence.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
export const LICENCE_SNAPSHOT_COMMAND = "longhorn_licence_snapshot";
|
|
3
|
+
export const LICENCE_ACTIVATE_COMMAND = "longhorn_licence_activate";
|
|
4
|
+
export const LICENCE_DEACTIVATE_COMMAND = "longhorn_licence_deactivate";
|
|
5
|
+
export const LICENCE_REFRESH_COMMAND = "longhorn_licence_refresh";
|
|
6
|
+
export const LICENCE_RELEASE_SEAT_COMMAND = "longhorn_licence_release_seat";
|
|
7
|
+
export const LICENCE_RENAME_SEAT_COMMAND = "longhorn_licence_rename_seat";
|
|
8
|
+
export const LICENCE_CHANGED_EVENT = "longhorn://licence/changed";
|
|
9
|
+
/**
|
|
10
|
+
* The licence seam.
|
|
11
|
+
*
|
|
12
|
+
* Six commands over four host capabilities: reading state, re-checking the
|
|
13
|
+
* lease, presenting a credential, and managing seats are different grants.
|
|
14
|
+
* Results are `unknown`, as every raw port's are — `LicenceClient` is what
|
|
15
|
+
* narrows them. Commands going out are typed, because this side builds those.
|
|
16
|
+
*/
|
|
17
|
+
export function createTauriLicencePort(options) {
|
|
18
|
+
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
19
|
+
return {
|
|
20
|
+
snapshot: () => options.transport.invoke(LICENCE_SNAPSHOT_COMMAND, {}),
|
|
21
|
+
activate: (command) => options.transport.invoke(LICENCE_ACTIVATE_COMMAND, { command }),
|
|
22
|
+
deactivate: (command) => options.transport.invoke(LICENCE_DEACTIVATE_COMMAND, { command }),
|
|
23
|
+
refresh: (command) => options.transport.invoke(LICENCE_REFRESH_COMMAND, { command }),
|
|
24
|
+
releaseSeat: (command) => options.transport.invoke(LICENCE_RELEASE_SEAT_COMMAND, { command }),
|
|
25
|
+
renameSeat: (command) => options.transport.invoke(LICENCE_RENAME_SEAT_COMMAND, { command }),
|
|
26
|
+
listen: events === undefined ? undefined : (listener) => listen(events, listener),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function listen(events, listener) {
|
|
30
|
+
return events.listen(LICENCE_CHANGED_EVENT, listener);
|
|
31
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type { NativeContentPort } from "@inflatable-cookie/longhorn/native-content";
|
|
3
|
+
export declare const NATIVE_CONTENT_CONNECT_COMMAND = "longhorn_native_content_connect";
|
|
4
|
+
export declare const NATIVE_CONTENT_SNAPSHOT_COMMAND = "longhorn_native_content_snapshot";
|
|
5
|
+
export declare const NATIVE_CONTENT_UPDATE_DESIRED_COMMAND = "longhorn_native_content_update_desired";
|
|
6
|
+
export declare const NATIVE_CONTENT_DECIDE_SIZE_COMMAND = "longhorn_native_content_decide_size";
|
|
7
|
+
export declare const NATIVE_CONTENT_CHANGED_EVENT = "longhorn://native-content/changed";
|
|
8
|
+
export interface TauriNativeContentPortOptions {
|
|
9
|
+
readonly transport: InvokeTransport;
|
|
10
|
+
readonly nextRequestId: () => string;
|
|
11
|
+
}
|
|
12
|
+
export declare function createTauriNativeContentPort(options: TauriNativeContentPortOptions): NativeContentPort;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
export const NATIVE_CONTENT_CONNECT_COMMAND = "longhorn_native_content_connect";
|
|
3
|
+
export const NATIVE_CONTENT_SNAPSHOT_COMMAND = "longhorn_native_content_snapshot";
|
|
4
|
+
export const NATIVE_CONTENT_UPDATE_DESIRED_COMMAND = "longhorn_native_content_update_desired";
|
|
5
|
+
export const NATIVE_CONTENT_DECIDE_SIZE_COMMAND = "longhorn_native_content_decide_size";
|
|
6
|
+
export const NATIVE_CONTENT_CHANGED_EVENT = "longhorn://native-content/changed";
|
|
7
|
+
export function createTauriNativeContentPort(options) {
|
|
8
|
+
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
9
|
+
return {
|
|
10
|
+
connect: (request) => options.transport.invoke(NATIVE_CONTENT_CONNECT_COMMAND, { request }),
|
|
11
|
+
snapshot: (request) => options.transport.invoke(NATIVE_CONTENT_SNAPSHOT_COMMAND, { request }),
|
|
12
|
+
updateDesired: (request) => options.transport.invoke(NATIVE_CONTENT_UPDATE_DESIRED_COMMAND, {
|
|
13
|
+
request,
|
|
14
|
+
}),
|
|
15
|
+
decideContentSize: (request) => options.transport.invoke(NATIVE_CONTENT_DECIDE_SIZE_COMMAND, { request }),
|
|
16
|
+
listen: events === undefined ? undefined : (listener) => listenChanged(events, listener),
|
|
17
|
+
nextRequestId: options.nextRequestId,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function listenChanged(transport, listener) {
|
|
21
|
+
return transport.listen(NATIVE_CONTENT_CHANGED_EVENT, listener);
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type { NotificationPort } from "@inflatable-cookie/longhorn/notifications";
|
|
3
|
+
export declare const NOTIFICATION_SNAPSHOT_COMMAND = "longhorn_notifications_snapshot";
|
|
4
|
+
export declare const NOTIFICATION_MUTATE_COMMAND = "longhorn_notifications_mutate";
|
|
5
|
+
export declare const NOTIFICATION_CHANGED_EVENT = "longhorn://notifications/changed";
|
|
6
|
+
export interface TauriNotificationPortOptions {
|
|
7
|
+
readonly transport: InvokeTransport;
|
|
8
|
+
readonly nextRequestId: () => string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createTauriNotificationPort(options: TauriNotificationPortOptions): NotificationPort;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
export const NOTIFICATION_SNAPSHOT_COMMAND = "longhorn_notifications_snapshot";
|
|
3
|
+
export const NOTIFICATION_MUTATE_COMMAND = "longhorn_notifications_mutate";
|
|
4
|
+
export const NOTIFICATION_CHANGED_EVENT = "longhorn://notifications/changed";
|
|
5
|
+
export function createTauriNotificationPort(options) {
|
|
6
|
+
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
7
|
+
return {
|
|
8
|
+
snapshot: (query) => options.transport.invoke(NOTIFICATION_SNAPSHOT_COMMAND, { query }),
|
|
9
|
+
mutate: (command) => options.transport.invoke(NOTIFICATION_MUTATE_COMMAND, { command }),
|
|
10
|
+
listen: events === undefined ? undefined : (listener) => listenChanged(events, listener),
|
|
11
|
+
nextRequestId: options.nextRequestId,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function listenChanged(transport, listener) {
|
|
15
|
+
return transport.listen(NOTIFICATION_CHANGED_EVENT, listener);
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type { OperationPort } from "@inflatable-cookie/longhorn/operation";
|
|
3
|
+
export declare const OPERATION_SNAPSHOT_COMMAND = "longhorn_operation_snapshot";
|
|
4
|
+
export declare const OPERATION_MUTATE_COMMAND = "longhorn_operation_mutate";
|
|
5
|
+
export declare const OPERATION_CANCEL_COMMAND = "longhorn_operation_cancel";
|
|
6
|
+
export declare const OPERATION_CHANGED_EVENT = "longhorn://operation/changed";
|
|
7
|
+
export interface TauriOperationPortOptions {
|
|
8
|
+
readonly transport: InvokeTransport;
|
|
9
|
+
readonly nextRequestId: () => string;
|
|
10
|
+
}
|
|
11
|
+
export declare function createTauriOperationPort(options: TauriOperationPortOptions): OperationPort;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
export const OPERATION_SNAPSHOT_COMMAND = "longhorn_operation_snapshot";
|
|
3
|
+
export const OPERATION_MUTATE_COMMAND = "longhorn_operation_mutate";
|
|
4
|
+
export const OPERATION_CANCEL_COMMAND = "longhorn_operation_cancel";
|
|
5
|
+
export const OPERATION_CHANGED_EVENT = "longhorn://operation/changed";
|
|
6
|
+
export function createTauriOperationPort(options) {
|
|
7
|
+
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
8
|
+
return {
|
|
9
|
+
snapshot: (query) => options.transport.invoke(OPERATION_SNAPSHOT_COMMAND, { query }),
|
|
10
|
+
mutate: (command) => options.transport.invoke(OPERATION_MUTATE_COMMAND, { command }),
|
|
11
|
+
cancel: (command) => options.transport.invoke(OPERATION_CANCEL_COMMAND, { command }),
|
|
12
|
+
listen: events === undefined ? undefined : (listener) => listenChanged(events, listener),
|
|
13
|
+
nextRequestId: options.nextRequestId,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function listenChanged(transport, listener) {
|
|
17
|
+
return transport.listen(OPERATION_CHANGED_EVENT, listener);
|
|
18
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { EventListenOptions, EventTransport, Unlisten } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import { TauriTransport } from "./index.js";
|
|
3
|
+
export declare class TauriEventTransport extends TauriTransport implements EventTransport {
|
|
4
|
+
listen(event: string, listener: (payload: unknown) => void, options?: EventListenOptions): Promise<Unlisten>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { listen } from "@tauri-apps/api/event";
|
|
2
|
+
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
|
3
|
+
import { TauriTransport } from "./index.js";
|
|
4
|
+
/// Optional raw Tauri invoke/listen edge.
|
|
5
|
+
export class TauriEventTransport extends TauriTransport {
|
|
6
|
+
async listen(event, listener, options) {
|
|
7
|
+
if (options?.scope === "renderer-local") {
|
|
8
|
+
const webview = window;
|
|
9
|
+
const receive = (message) => {
|
|
10
|
+
if ("detail" in message) {
|
|
11
|
+
listener(message.detail);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
webview.addEventListener(event, receive);
|
|
15
|
+
return () => webview.removeEventListener(event, receive);
|
|
16
|
+
}
|
|
17
|
+
const tauriOptions = options?.scope === "current-webview"
|
|
18
|
+
? { target: { kind: "WebviewWindow", label: getCurrentWebviewWindow().label } }
|
|
19
|
+
: undefined;
|
|
20
|
+
return listen(event, ({ payload }) => listener(payload), tauriOptions);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
/** An operational error returned by a Tauri host adapter. */
|
|
3
|
+
export declare class TauriHostError extends Error {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly retryable: boolean;
|
|
6
|
+
constructor(code: string, message: string, retryable: boolean);
|
|
7
|
+
}
|
|
8
|
+
export declare class TauriTransport implements InvokeTransport {
|
|
9
|
+
invoke(command: string, arguments_: Record<string, unknown>): Promise<unknown>;
|
|
10
|
+
/** Invokes a command with a channel for its live progress. */
|
|
11
|
+
invokeWithProgress(command: string, arguments_: Record<string, unknown>, listener: (event: unknown) => void): Promise<unknown>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Channel, invoke } from "@tauri-apps/api/core";
|
|
2
|
+
/** An operational error returned by a Tauri host adapter. */
|
|
3
|
+
export class TauriHostError extends Error {
|
|
4
|
+
code;
|
|
5
|
+
retryable;
|
|
6
|
+
constructor(code, message, retryable) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.retryable = retryable;
|
|
10
|
+
this.name = "TauriHostError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class TauriTransport {
|
|
14
|
+
async invoke(command, arguments_) {
|
|
15
|
+
try {
|
|
16
|
+
return await invoke(command, arguments_);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (isHostErrorEnvelope(error)) {
|
|
20
|
+
throw new TauriHostError(error.code, error.message, error.retryable);
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Invokes a command with a channel for its live progress. */
|
|
26
|
+
async invokeWithProgress(command, arguments_, listener) {
|
|
27
|
+
const onProgress = new Channel(listener);
|
|
28
|
+
try {
|
|
29
|
+
return await this.invoke(command, { ...arguments_, onProgress });
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
// A rejected invoke may never create a Rust channel to close the callback.
|
|
33
|
+
const internals = "__TAURI_INTERNALS__" in window && window.__TAURI_INTERNALS__;
|
|
34
|
+
if (hasCallbackCleanup(internals)) {
|
|
35
|
+
internals.unregisterCallback(onProgress.id);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function isHostErrorEnvelope(value) {
|
|
41
|
+
return (typeof value === "object" &&
|
|
42
|
+
value !== null &&
|
|
43
|
+
Object.keys(value).length === 3 &&
|
|
44
|
+
Object.hasOwn(value, "code") &&
|
|
45
|
+
Object.hasOwn(value, "message") &&
|
|
46
|
+
Object.hasOwn(value, "retryable") &&
|
|
47
|
+
"code" in value &&
|
|
48
|
+
typeof value.code === "string" &&
|
|
49
|
+
"message" in value &&
|
|
50
|
+
typeof value.message === "string" &&
|
|
51
|
+
"retryable" in value &&
|
|
52
|
+
typeof value.retryable === "boolean");
|
|
53
|
+
}
|
|
54
|
+
function hasCallbackCleanup(value) {
|
|
55
|
+
return (typeof value === "object" &&
|
|
56
|
+
value !== null &&
|
|
57
|
+
"unregisterCallback" in value &&
|
|
58
|
+
typeof value.unregisterCallback === "function");
|
|
59
|
+
}
|
package/dist/update.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
import type { UpdatePort } from "@inflatable-cookie/longhorn/update";
|
|
3
|
+
export declare const UPDATE_SNAPSHOT_COMMAND = "longhorn_update_snapshot";
|
|
4
|
+
export declare const UPDATE_CHECK_COMMAND = "longhorn_update_check";
|
|
5
|
+
export declare const UPDATE_SELECT_CHANNEL_COMMAND = "longhorn_update_select_channel";
|
|
6
|
+
export declare const UPDATE_DEFER_COMMAND = "longhorn_update_defer";
|
|
7
|
+
export declare const UPDATE_PREPARE_COMMAND = "longhorn_update_prepare";
|
|
8
|
+
export declare const UPDATE_APPLY_COMMAND = "longhorn_update_apply";
|
|
9
|
+
export declare const UPDATE_CANCEL_COMMAND = "longhorn_update_cancel";
|
|
10
|
+
export declare const UPDATE_CHANGED_EVENT = "longhorn://update/changed";
|
|
11
|
+
/**
|
|
12
|
+
* The update seam.
|
|
13
|
+
*
|
|
14
|
+
* Committed changes produce an invalidation hint. Live byte progress arrives
|
|
15
|
+
* on a channel owned by the prepare invocation.
|
|
16
|
+
*
|
|
17
|
+
* Results are `unknown`, as every other raw port's are. What comes back over a
|
|
18
|
+
* transport is untrusted until a validator says otherwise; `UpdateClient` is
|
|
19
|
+
* what narrows them. Commands going *out* are typed, because those this side
|
|
20
|
+
* constructs.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createTauriUpdatePort(options: {
|
|
23
|
+
readonly transport: InvokeTransport;
|
|
24
|
+
}): UpdatePort;
|