@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
package/dist/update.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
+
export const UPDATE_SNAPSHOT_COMMAND = "longhorn_update_snapshot";
|
|
3
|
+
export const UPDATE_CHECK_COMMAND = "longhorn_update_check";
|
|
4
|
+
export const UPDATE_SELECT_CHANNEL_COMMAND = "longhorn_update_select_channel";
|
|
5
|
+
export const UPDATE_DEFER_COMMAND = "longhorn_update_defer";
|
|
6
|
+
export const UPDATE_PREPARE_COMMAND = "longhorn_update_prepare";
|
|
7
|
+
export const UPDATE_APPLY_COMMAND = "longhorn_update_apply";
|
|
8
|
+
export const UPDATE_CANCEL_COMMAND = "longhorn_update_cancel";
|
|
9
|
+
export const UPDATE_CHANGED_EVENT = "longhorn://update/changed";
|
|
10
|
+
/**
|
|
11
|
+
* The update seam.
|
|
12
|
+
*
|
|
13
|
+
* Committed changes produce an invalidation hint. Live byte progress arrives
|
|
14
|
+
* on a channel owned by the prepare invocation.
|
|
15
|
+
*
|
|
16
|
+
* Results are `unknown`, as every other raw port's are. What comes back over a
|
|
17
|
+
* transport is untrusted until a validator says otherwise; `UpdateClient` is
|
|
18
|
+
* what narrows them. Commands going *out* are typed, because those this side
|
|
19
|
+
* constructs.
|
|
20
|
+
*/
|
|
21
|
+
export function createTauriUpdatePort(options) {
|
|
22
|
+
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
23
|
+
const transport = options.transport;
|
|
24
|
+
const progress = hasProgress(transport) ? transport : undefined;
|
|
25
|
+
return {
|
|
26
|
+
snapshot: () => transport.invoke(UPDATE_SNAPSHOT_COMMAND, {}),
|
|
27
|
+
check: (command) => options.transport.invoke(UPDATE_CHECK_COMMAND, { command }),
|
|
28
|
+
selectChannel: (command) => options.transport.invoke(UPDATE_SELECT_CHANNEL_COMMAND, { command }),
|
|
29
|
+
defer: (command) => options.transport.invoke(UPDATE_DEFER_COMMAND, { command }),
|
|
30
|
+
prepare: (command) => options.transport.invoke(UPDATE_PREPARE_COMMAND, { command }),
|
|
31
|
+
prepareWithProgress: progress === undefined
|
|
32
|
+
? undefined
|
|
33
|
+
: (command, listener) => progress.invokeWithProgress(UPDATE_PREPARE_COMMAND, { command }, listener),
|
|
34
|
+
apply: (command) => options.transport.invoke(UPDATE_APPLY_COMMAND, { command }),
|
|
35
|
+
cancel: (command) => options.transport.invoke(UPDATE_CANCEL_COMMAND, { command }),
|
|
36
|
+
listen: events === undefined
|
|
37
|
+
? undefined
|
|
38
|
+
: (listener) => listen(events, UPDATE_CHANGED_EVENT, listener),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function hasProgress(transport) {
|
|
42
|
+
return "invokeWithProgress" in transport && typeof transport.invokeWithProgress === "function";
|
|
43
|
+
}
|
|
44
|
+
function listen(events, event, listener) {
|
|
45
|
+
return events.listen(event, listener);
|
|
46
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inflatable-cookie/longhorn-tauri",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,72 +9,75 @@
|
|
|
9
9
|
},
|
|
10
10
|
"homepage": "https://github.com/inflatable-cookie/longhorn#readme",
|
|
11
11
|
"type": "module",
|
|
12
|
-
"types": "./
|
|
12
|
+
"types": "./dist/transport/index.d.ts",
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
|
-
"types": "./
|
|
16
|
-
"import": "./
|
|
17
|
-
"default": "./
|
|
15
|
+
"types": "./dist/transport/index.d.ts",
|
|
16
|
+
"import": "./dist/transport/index.js",
|
|
17
|
+
"default": "./dist/transport/index.js"
|
|
18
18
|
},
|
|
19
19
|
"./bridge": {
|
|
20
|
-
"types": "./
|
|
21
|
-
"import": "./
|
|
22
|
-
"default": "./
|
|
20
|
+
"types": "./dist/bridge.d.ts",
|
|
21
|
+
"import": "./dist/bridge.js",
|
|
22
|
+
"default": "./dist/bridge.js"
|
|
23
23
|
},
|
|
24
24
|
"./bridge-events": {
|
|
25
|
-
"types": "./
|
|
26
|
-
"import": "./
|
|
27
|
-
"default": "./
|
|
25
|
+
"types": "./dist/bridge-events.d.ts",
|
|
26
|
+
"import": "./dist/bridge-events.js",
|
|
27
|
+
"default": "./dist/bridge-events.js"
|
|
28
28
|
},
|
|
29
29
|
"./events": {
|
|
30
|
-
"types": "./
|
|
31
|
-
"import": "./
|
|
32
|
-
"default": "./
|
|
30
|
+
"types": "./dist/transport/events.d.ts",
|
|
31
|
+
"import": "./dist/transport/events.js",
|
|
32
|
+
"default": "./dist/transport/events.js"
|
|
33
33
|
},
|
|
34
34
|
"./history": {
|
|
35
|
-
"types": "./
|
|
36
|
-
"import": "./
|
|
37
|
-
"default": "./
|
|
35
|
+
"types": "./dist/history.d.ts",
|
|
36
|
+
"import": "./dist/history.js",
|
|
37
|
+
"default": "./dist/history.js"
|
|
38
38
|
},
|
|
39
39
|
"./history-tree": {
|
|
40
|
-
"types": "./
|
|
41
|
-
"import": "./
|
|
42
|
-
"default": "./
|
|
40
|
+
"types": "./dist/history-tree.d.ts",
|
|
41
|
+
"import": "./dist/history-tree.js",
|
|
42
|
+
"default": "./dist/history-tree.js"
|
|
43
43
|
},
|
|
44
44
|
"./licence": {
|
|
45
|
-
"types": "./
|
|
46
|
-
"import": "./
|
|
47
|
-
"default": "./
|
|
45
|
+
"types": "./dist/licence.d.ts",
|
|
46
|
+
"import": "./dist/licence.js",
|
|
47
|
+
"default": "./dist/licence.js"
|
|
48
48
|
},
|
|
49
49
|
"./native-content": {
|
|
50
|
-
"types": "./
|
|
51
|
-
"import": "./
|
|
52
|
-
"default": "./
|
|
50
|
+
"types": "./dist/native-content.d.ts",
|
|
51
|
+
"import": "./dist/native-content.js",
|
|
52
|
+
"default": "./dist/native-content.js"
|
|
53
53
|
},
|
|
54
54
|
"./notifications": {
|
|
55
|
-
"types": "./
|
|
56
|
-
"import": "./
|
|
57
|
-
"default": "./
|
|
55
|
+
"types": "./dist/notifications.d.ts",
|
|
56
|
+
"import": "./dist/notifications.js",
|
|
57
|
+
"default": "./dist/notifications.js"
|
|
58
58
|
},
|
|
59
59
|
"./operation": {
|
|
60
|
-
"types": "./
|
|
61
|
-
"import": "./
|
|
62
|
-
"default": "./
|
|
60
|
+
"types": "./dist/operation.d.ts",
|
|
61
|
+
"import": "./dist/operation.js",
|
|
62
|
+
"default": "./dist/operation.js"
|
|
63
63
|
},
|
|
64
64
|
"./package.json": "./package.json",
|
|
65
65
|
"./update": {
|
|
66
|
-
"types": "./
|
|
67
|
-
"import": "./
|
|
68
|
-
"default": "./
|
|
66
|
+
"types": "./dist/update.d.ts",
|
|
67
|
+
"import": "./dist/update.js",
|
|
68
|
+
"default": "./dist/update.js"
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
71
|
"files": [
|
|
72
|
-
"
|
|
72
|
+
"dist",
|
|
73
73
|
"README.md",
|
|
74
74
|
"LICENSE"
|
|
75
75
|
],
|
|
76
|
+
"scripts": {
|
|
77
|
+
"prepack": "bun ../../scripts/build-packages.ts longhorn-tauri"
|
|
78
|
+
},
|
|
76
79
|
"peerDependencies": {
|
|
77
|
-
"@inflatable-cookie/longhorn": "0.7.
|
|
80
|
+
"@inflatable-cookie/longhorn": "0.7.1",
|
|
78
81
|
"@tauri-apps/api": "^2.13.0"
|
|
79
82
|
},
|
|
80
83
|
"sideEffects": false,
|
package/src/bridge-events.ts
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ConnectionFailureReporter,
|
|
3
|
-
EventListenOptions,
|
|
4
|
-
EventTransport,
|
|
5
|
-
Unlisten,
|
|
6
|
-
} from "@inflatable-cookie/longhorn/core";
|
|
7
|
-
import { TauriEventTransport } from "@inflatable-cookie/longhorn-tauri/events";
|
|
8
|
-
|
|
9
|
-
import type { BridgeCodec } from "@inflatable-cookie/longhorn/bridge";
|
|
10
|
-
import {
|
|
11
|
-
parseBridgeJobTerminalEvent,
|
|
12
|
-
parseBridgeProgressEvent,
|
|
13
|
-
} from "@inflatable-cookie/longhorn/bridge";
|
|
14
|
-
import { BridgeJobTracker } from "@inflatable-cookie/longhorn/bridge";
|
|
15
|
-
import type {
|
|
16
|
-
BridgeJobId,
|
|
17
|
-
BridgeJobTerminalEvent,
|
|
18
|
-
BridgeProgressEvent,
|
|
19
|
-
BridgeRequestId,
|
|
20
|
-
BridgeSessionId,
|
|
21
|
-
DomainId,
|
|
22
|
-
} from "@inflatable-cookie/longhorn/bridge/protocol";
|
|
23
|
-
import type { BridgeStreamSource } from "@inflatable-cookie/longhorn/bridge/stream";
|
|
24
|
-
import { TauriBridgeAdapter } from "./bridge.ts";
|
|
25
|
-
|
|
26
|
-
export const BRIDGE_DOMAIN_EVENT = "longhorn://bridge/domain";
|
|
27
|
-
export const BRIDGE_PROGRESS_EVENT = "longhorn://bridge/progress";
|
|
28
|
-
export const BRIDGE_TERMINAL_EVENT = "longhorn://bridge/terminal";
|
|
29
|
-
const bridgeDelivery = { scope: "renderer-local" } satisfies EventListenOptions;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Event-capable stream source. `connectBridgeStream` installs `listen` before
|
|
33
|
-
* calling `loadSnapshot`, preserving the required subscription handshake.
|
|
34
|
-
*/
|
|
35
|
-
export class TauriBridgeStreamSource implements BridgeStreamSource {
|
|
36
|
-
readonly #transport: EventTransport;
|
|
37
|
-
readonly #adapter: TauriBridgeAdapter;
|
|
38
|
-
readonly #sessionId: BridgeSessionId;
|
|
39
|
-
readonly #domainId: DomainId;
|
|
40
|
-
|
|
41
|
-
constructor(
|
|
42
|
-
sessionId: BridgeSessionId,
|
|
43
|
-
domainId: DomainId,
|
|
44
|
-
transport: EventTransport = new TauriEventTransport(),
|
|
45
|
-
) {
|
|
46
|
-
this.#sessionId = sessionId;
|
|
47
|
-
this.#domainId = domainId;
|
|
48
|
-
this.#transport = transport;
|
|
49
|
-
this.#adapter = new TauriBridgeAdapter(transport);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
listen(listener: (value: unknown) => void): Promise<Unlisten> {
|
|
53
|
-
return this.#transport.listen(BRIDGE_DOMAIN_EVENT, listener, bridgeDelivery);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
loadSnapshot(): Promise<unknown> {
|
|
57
|
-
return this.#adapter.resync(this.#sessionId, this.#domainId);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface BridgeJobListeners<Progress, Success, Detail> {
|
|
62
|
-
readonly progressCodec: BridgeCodec<Progress>;
|
|
63
|
-
readonly successCodec: BridgeCodec<Success>;
|
|
64
|
-
readonly detailCodec: BridgeCodec<Detail>;
|
|
65
|
-
readonly progress?: (event: BridgeProgressEvent<Progress>) => void;
|
|
66
|
-
readonly terminal: (event: BridgeJobTerminalEvent<Success, Detail>) => void;
|
|
67
|
-
/**
|
|
68
|
-
* Reports a malformed event for this job 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 messages are dropped before their payload is decoded, and
|
|
79
|
-
* post-terminal messages are dropped without decoding, so neither can fail
|
|
80
|
-
* this job or reach consumers.
|
|
81
|
-
*
|
|
82
|
-
* Contract 010 makes events projections, not durable delivery, and the bridge
|
|
83
|
-
* has no job-status query. A terminal that fires before its listener is
|
|
84
|
-
* registered (the jobId is only known once the job has started) is therefore
|
|
85
|
-
* not recovered here; see docs/knowledge/questions.md.
|
|
86
|
-
*/
|
|
87
|
-
export async function listenTauriBridgeJob<Progress, Success, Detail>(
|
|
88
|
-
requestId: BridgeRequestId,
|
|
89
|
-
jobId: BridgeJobId,
|
|
90
|
-
listeners: BridgeJobListeners<Progress, Success, Detail>,
|
|
91
|
-
transport: EventTransport = new TauriEventTransport(),
|
|
92
|
-
): Promise<Unlisten> {
|
|
93
|
-
const tracker = new BridgeJobTracker(requestId, jobId);
|
|
94
|
-
// Set once the job has failed or been closed. Nothing reaches the consumer
|
|
95
|
-
// after that, and a registration that completes later is released at once.
|
|
96
|
-
let stopped = false;
|
|
97
|
-
let registered = false;
|
|
98
|
-
const unlistens: Array<Unlisten> = [];
|
|
99
|
-
|
|
100
|
-
// Last registered, first released.
|
|
101
|
-
const teardown = async (): Promise<void> => {
|
|
102
|
-
const pending = unlistens.splice(0).reverse();
|
|
103
|
-
const results = await Promise.allSettled(
|
|
104
|
-
pending.map((unlisten) => Promise.resolve().then(() => unlisten())),
|
|
105
|
-
);
|
|
106
|
-
for (const result of results) {
|
|
107
|
-
if (result.status === "rejected") {
|
|
108
|
-
throw result.reason;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const reportUnlistenFailure = (error: unknown): void => {
|
|
114
|
-
try {
|
|
115
|
-
listeners.onFailure?.({ phase: "unlisten", error });
|
|
116
|
-
} catch {
|
|
117
|
-
// A secondary reporter failure cannot replace the original error.
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const notify = (callback: () => void): void => {
|
|
122
|
-
try {
|
|
123
|
-
callback();
|
|
124
|
-
} catch (error) {
|
|
125
|
-
// A transport may deliver inline before returning its unlisten.
|
|
126
|
-
if (registered) {
|
|
127
|
-
throw error;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
const fail = (error: unknown): void => {
|
|
133
|
-
if (stopped) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
stopped = true;
|
|
137
|
-
void teardown().catch(reportUnlistenFailure);
|
|
138
|
-
notify(() => listeners.onFailure?.({ phase: "event", error }));
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const adopt = async (unlisten: Unlisten): Promise<void> => {
|
|
142
|
-
if (!stopped) {
|
|
143
|
-
unlistens.push(unlisten);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
try {
|
|
147
|
-
await unlisten();
|
|
148
|
-
} catch (error) {
|
|
149
|
-
reportUnlistenFailure(error);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
// The channels are shared by every job, so admission comes before any
|
|
154
|
-
// job-specific decode: another job's payload cannot fail this one. A value
|
|
155
|
-
// from another request is refused on its request id alone. Identifiers that
|
|
156
|
-
// cannot be read as part of this request are malformed.
|
|
157
|
-
const admits = (value: unknown): boolean => {
|
|
158
|
-
try {
|
|
159
|
-
return tracker.admits(value);
|
|
160
|
-
} catch (error) {
|
|
161
|
-
fail(error);
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const onProgress = (value: unknown): void => {
|
|
167
|
-
if (stopped || tracker.isTerminal() || !admits(value)) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
let event: BridgeProgressEvent<Progress>;
|
|
171
|
-
try {
|
|
172
|
-
event = parseBridgeProgressEvent(value, listeners.progressCodec);
|
|
173
|
-
} catch (error) {
|
|
174
|
-
fail(error);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
if (tracker.classifyProgress(event) === "accept") {
|
|
178
|
-
notify(() => listeners.progress?.(event));
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const onTerminal = (value: unknown): void => {
|
|
183
|
-
// After this job's terminal, input is not decoded at all: a late or
|
|
184
|
-
// malformed event cannot fail a job that has already settled.
|
|
185
|
-
if (stopped || tracker.isTerminal() || !admits(value)) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
let event: BridgeJobTerminalEvent<Success, Detail>;
|
|
189
|
-
try {
|
|
190
|
-
event = parseBridgeJobTerminalEvent(value, listeners.successCodec, listeners.detailCodec);
|
|
191
|
-
} catch (error) {
|
|
192
|
-
fail(error);
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
if (tracker.classifyTerminal(event) === "accept") {
|
|
196
|
-
notify(() => listeners.terminal(event));
|
|
197
|
-
}
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const close = async (): Promise<void> => {
|
|
201
|
-
stopped = true;
|
|
202
|
-
await teardown();
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
try {
|
|
206
|
-
await adopt(await transport.listen(BRIDGE_PROGRESS_EVENT, onProgress, bridgeDelivery));
|
|
207
|
-
await adopt(await transport.listen(BRIDGE_TERMINAL_EVENT, onTerminal, bridgeDelivery));
|
|
208
|
-
registered = true;
|
|
209
|
-
} catch (error) {
|
|
210
|
-
stopped = true;
|
|
211
|
-
await teardown().catch(reportUnlistenFailure);
|
|
212
|
-
throw error;
|
|
213
|
-
}
|
|
214
|
-
return close;
|
|
215
|
-
}
|
package/src/bridge.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
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
|
-
BridgeSession,
|
|
13
|
-
} from "@inflatable-cookie/longhorn/bridge";
|
|
14
|
-
import { BridgeDomainClient } from "@inflatable-cookie/longhorn/bridge";
|
|
15
|
-
import type { BridgeNegotiationAdapter } from "@inflatable-cookie/longhorn/bridge";
|
|
16
|
-
import { BridgeSessionClient } from "@inflatable-cookie/longhorn/bridge";
|
|
17
|
-
|
|
18
|
-
export const BRIDGE_HELLO_COMMAND = "longhorn_bridge_hello";
|
|
19
|
-
export const BRIDGE_AUTHORITY_COMMAND = "longhorn_bridge_authority";
|
|
20
|
-
export const BRIDGE_QUERY_COMMAND = "longhorn_bridge_query";
|
|
21
|
-
export const BRIDGE_COMMAND_COMMAND = "longhorn_bridge_command";
|
|
22
|
-
export const BRIDGE_CANCEL_COMMAND = "longhorn_bridge_cancel";
|
|
23
|
-
export const BRIDGE_RESYNC_COMMAND = "longhorn_bridge_resync";
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Generic bridge commands over the raw invoke-only Tauri edge.
|
|
27
|
-
*
|
|
28
|
-
* Domain routes and payload vocabulary arrive only through operation
|
|
29
|
-
* descriptors owned by adapted domain packages.
|
|
30
|
-
*/
|
|
31
|
-
export class TauriBridgeAdapter implements BridgeNegotiationAdapter, BridgeOperationAdapter {
|
|
32
|
-
readonly #transport: InvokeTransport;
|
|
33
|
-
|
|
34
|
-
constructor(transport: InvokeTransport = new TauriTransport()) {
|
|
35
|
-
this.#transport = transport;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
negotiate(request: BridgeHelloRequest): Promise<unknown> {
|
|
39
|
-
return this.#transport.invoke(BRIDGE_HELLO_COMMAND, { request });
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
authority(sessionId: BridgeSessionId): Promise<unknown> {
|
|
43
|
-
return this.#transport.invoke(BRIDGE_AUTHORITY_COMMAND, { sessionId });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
invoke<Request, Reply>(
|
|
47
|
-
operation: BridgeOperationDescriptor<Request, Reply>,
|
|
48
|
-
request: Request,
|
|
49
|
-
): Promise<unknown> {
|
|
50
|
-
return this.#transport.invoke(commandFor(operation), {
|
|
51
|
-
route: operation.route,
|
|
52
|
-
request,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
resync(sessionId: BridgeSessionId, domainId: DomainId): Promise<unknown> {
|
|
57
|
-
return this.#transport.invoke(BRIDGE_RESYNC_COMMAND, {
|
|
58
|
-
sessionId,
|
|
59
|
-
domainId,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface TauriBridgeConnection {
|
|
65
|
-
readonly session: BridgeSession;
|
|
66
|
-
readonly domain: BridgeDomainClient;
|
|
67
|
-
readonly adapter: TauriBridgeAdapter;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/// Negotiates before exposing a Tauri-backed checked domain client.
|
|
71
|
-
export async function connectTauriBridge(
|
|
72
|
-
request: BridgeHelloRequest,
|
|
73
|
-
transport?: InvokeTransport,
|
|
74
|
-
): Promise<TauriBridgeConnection> {
|
|
75
|
-
const adapter = new TauriBridgeAdapter(transport);
|
|
76
|
-
const session = await new BridgeSessionClient(adapter).connect(request);
|
|
77
|
-
return {
|
|
78
|
-
session,
|
|
79
|
-
domain: new BridgeDomainClient(session, adapter),
|
|
80
|
-
adapter,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function commandFor<Request, Reply>(operation: BridgeOperationDescriptor<Request, Reply>): string {
|
|
85
|
-
switch (operation.kind) {
|
|
86
|
-
case "query":
|
|
87
|
-
return BRIDGE_QUERY_COMMAND;
|
|
88
|
-
case "command":
|
|
89
|
-
return BRIDGE_COMMAND_COMMAND;
|
|
90
|
-
case "cancellation":
|
|
91
|
-
return BRIDGE_CANCEL_COMMAND;
|
|
92
|
-
}
|
|
93
|
-
}
|
package/src/history-tree.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
-
import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
3
|
-
import type { ForkHistoryPort } from "@inflatable-cookie/longhorn/history-tree";
|
|
4
|
-
export const FORK_HISTORY_SNAPSHOT_COMMAND = "longhorn_history_tree_snapshot";
|
|
5
|
-
export const FORK_HISTORY_PATH_COMMAND = "longhorn_history_tree_path";
|
|
6
|
-
export const FORK_HISTORY_BRANCHES_COMMAND = "longhorn_history_tree_branches";
|
|
7
|
-
export const FORK_HISTORY_CONTINUATIONS_COMMAND = "longhorn_history_tree_continuations";
|
|
8
|
-
export const FORK_HISTORY_DELETE_COMMAND = "longhorn_history_tree_delete_continuation";
|
|
9
|
-
export const FORK_HISTORY_PRUNE_COMMAND = "longhorn_history_tree_prune";
|
|
10
|
-
export const FORK_HISTORY_NAVIGATE_COMMAND = "longhorn_history_tree_navigate";
|
|
11
|
-
export const FORK_HISTORY_CHANGED_EVENT = "longhorn://history-tree/changed";
|
|
12
|
-
export function createTauriForkHistoryPort(options: {
|
|
13
|
-
readonly transport: InvokeTransport;
|
|
14
|
-
readonly nextPlanId: () => string;
|
|
15
|
-
}): ForkHistoryPort {
|
|
16
|
-
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
17
|
-
return {
|
|
18
|
-
snapshot: () => options.transport.invoke(FORK_HISTORY_SNAPSHOT_COMMAND, {}),
|
|
19
|
-
path: (command) => options.transport.invoke(FORK_HISTORY_PATH_COMMAND, { command }),
|
|
20
|
-
branches: (command) => options.transport.invoke(FORK_HISTORY_BRANCHES_COMMAND, { command }),
|
|
21
|
-
continuations: (command) =>
|
|
22
|
-
options.transport.invoke(FORK_HISTORY_CONTINUATIONS_COMMAND, { command }),
|
|
23
|
-
deleteContinuation: (command) =>
|
|
24
|
-
options.transport.invoke(FORK_HISTORY_DELETE_COMMAND, { command }),
|
|
25
|
-
prune: (command) => options.transport.invoke(FORK_HISTORY_PRUNE_COMMAND, { command }),
|
|
26
|
-
navigate: (command) => options.transport.invoke(FORK_HISTORY_NAVIGATE_COMMAND, { command }),
|
|
27
|
-
listen: events === undefined ? undefined : (listener) => listen(events, listener),
|
|
28
|
-
nextPlanId: options.nextPlanId,
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function listen(events: EventTransport, listener: (event: unknown) => void) {
|
|
32
|
-
return events.listen(FORK_HISTORY_CHANGED_EVENT, listener);
|
|
33
|
-
}
|
package/src/history.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
-
import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
3
|
-
|
|
4
|
-
import type { HistoryPort } from "@inflatable-cookie/longhorn/history";
|
|
5
|
-
|
|
6
|
-
export const HISTORY_SNAPSHOT_COMMAND = "longhorn_history_snapshot";
|
|
7
|
-
export const HISTORY_PAGE_COMMAND = "longhorn_history_page";
|
|
8
|
-
export const HISTORY_NAVIGATE_COMMAND = "longhorn_history_navigate";
|
|
9
|
-
export const HISTORY_CHANGED_EVENT = "longhorn://history/changed";
|
|
10
|
-
|
|
11
|
-
export interface TauriHistoryPortOptions {
|
|
12
|
-
readonly transport: InvokeTransport;
|
|
13
|
-
readonly nextPlanId: () => string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function createTauriHistoryPort(options: TauriHistoryPortOptions): HistoryPort {
|
|
17
|
-
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
18
|
-
return {
|
|
19
|
-
snapshot: () => options.transport.invoke(HISTORY_SNAPSHOT_COMMAND, {}),
|
|
20
|
-
page: (command) => options.transport.invoke(HISTORY_PAGE_COMMAND, { command }),
|
|
21
|
-
navigate: (command) => options.transport.invoke(HISTORY_NAVIGATE_COMMAND, { command }),
|
|
22
|
-
listen: events === undefined ? undefined : (listener) => listenChanged(events, listener),
|
|
23
|
-
nextPlanId: options.nextPlanId,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
async function listenChanged(transport: EventTransport, listener: (event: unknown) => void) {
|
|
28
|
-
return transport.listen(HISTORY_CHANGED_EVENT, listener);
|
|
29
|
-
}
|
package/src/licence.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
-
import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
3
|
-
import type {
|
|
4
|
-
LicenceActivateCommand,
|
|
5
|
-
LicenceDeactivateCommand,
|
|
6
|
-
LicencePort,
|
|
7
|
-
LicenceRefreshCommand,
|
|
8
|
-
LicenceReleaseSeatCommand,
|
|
9
|
-
LicenceRenameSeatCommand,
|
|
10
|
-
LicenceUnlisten,
|
|
11
|
-
} from "@inflatable-cookie/longhorn/licence";
|
|
12
|
-
export const LICENCE_SNAPSHOT_COMMAND = "longhorn_licence_snapshot";
|
|
13
|
-
export const LICENCE_ACTIVATE_COMMAND = "longhorn_licence_activate";
|
|
14
|
-
export const LICENCE_DEACTIVATE_COMMAND = "longhorn_licence_deactivate";
|
|
15
|
-
export const LICENCE_REFRESH_COMMAND = "longhorn_licence_refresh";
|
|
16
|
-
export const LICENCE_RELEASE_SEAT_COMMAND = "longhorn_licence_release_seat";
|
|
17
|
-
export const LICENCE_RENAME_SEAT_COMMAND = "longhorn_licence_rename_seat";
|
|
18
|
-
export const LICENCE_CHANGED_EVENT = "longhorn://licence/changed";
|
|
19
|
-
/**
|
|
20
|
-
* The licence seam.
|
|
21
|
-
*
|
|
22
|
-
* Six commands over four host capabilities: reading state, re-checking the
|
|
23
|
-
* lease, presenting a credential, and managing seats are different grants.
|
|
24
|
-
* Results are `unknown`, as every raw port's are — `LicenceClient` is what
|
|
25
|
-
* narrows them. Commands going out are typed, because this side builds those.
|
|
26
|
-
*/
|
|
27
|
-
export function createTauriLicencePort(options: {
|
|
28
|
-
readonly transport: InvokeTransport;
|
|
29
|
-
}): LicencePort {
|
|
30
|
-
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
31
|
-
return {
|
|
32
|
-
snapshot: () => options.transport.invoke(LICENCE_SNAPSHOT_COMMAND, {}),
|
|
33
|
-
activate: (command: LicenceActivateCommand) =>
|
|
34
|
-
options.transport.invoke(LICENCE_ACTIVATE_COMMAND, { command }),
|
|
35
|
-
deactivate: (command: LicenceDeactivateCommand) =>
|
|
36
|
-
options.transport.invoke(LICENCE_DEACTIVATE_COMMAND, { command }),
|
|
37
|
-
refresh: (command: LicenceRefreshCommand) =>
|
|
38
|
-
options.transport.invoke(LICENCE_REFRESH_COMMAND, { command }),
|
|
39
|
-
releaseSeat: (command: LicenceReleaseSeatCommand) =>
|
|
40
|
-
options.transport.invoke(LICENCE_RELEASE_SEAT_COMMAND, { command }),
|
|
41
|
-
renameSeat: (command: LicenceRenameSeatCommand) =>
|
|
42
|
-
options.transport.invoke(LICENCE_RENAME_SEAT_COMMAND, { command }),
|
|
43
|
-
listen: events === undefined ? undefined : (listener) => listen(events, listener),
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function listen(
|
|
47
|
-
events: EventTransport,
|
|
48
|
-
listener: (event: unknown) => void,
|
|
49
|
-
): Promise<LicenceUnlisten> {
|
|
50
|
-
return events.listen(LICENCE_CHANGED_EVENT, listener);
|
|
51
|
-
}
|
package/src/native-content.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
-
import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
3
|
-
|
|
4
|
-
import type { NativeContentPort } from "@inflatable-cookie/longhorn/native-content";
|
|
5
|
-
|
|
6
|
-
export const NATIVE_CONTENT_CONNECT_COMMAND = "longhorn_native_content_connect";
|
|
7
|
-
export const NATIVE_CONTENT_SNAPSHOT_COMMAND = "longhorn_native_content_snapshot";
|
|
8
|
-
export const NATIVE_CONTENT_UPDATE_DESIRED_COMMAND = "longhorn_native_content_update_desired";
|
|
9
|
-
export const NATIVE_CONTENT_DECIDE_SIZE_COMMAND = "longhorn_native_content_decide_size";
|
|
10
|
-
export const NATIVE_CONTENT_CHANGED_EVENT = "longhorn://native-content/changed";
|
|
11
|
-
|
|
12
|
-
export interface TauriNativeContentPortOptions {
|
|
13
|
-
readonly transport: InvokeTransport;
|
|
14
|
-
readonly nextRequestId: () => string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function createTauriNativeContentPort(
|
|
18
|
-
options: TauriNativeContentPortOptions,
|
|
19
|
-
): NativeContentPort {
|
|
20
|
-
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
21
|
-
return {
|
|
22
|
-
connect: (request) => options.transport.invoke(NATIVE_CONTENT_CONNECT_COMMAND, { request }),
|
|
23
|
-
snapshot: (request) => options.transport.invoke(NATIVE_CONTENT_SNAPSHOT_COMMAND, { request }),
|
|
24
|
-
updateDesired: (request) =>
|
|
25
|
-
options.transport.invoke(NATIVE_CONTENT_UPDATE_DESIRED_COMMAND, {
|
|
26
|
-
request,
|
|
27
|
-
}),
|
|
28
|
-
decideContentSize: (request) =>
|
|
29
|
-
options.transport.invoke(NATIVE_CONTENT_DECIDE_SIZE_COMMAND, { request }),
|
|
30
|
-
listen: events === undefined ? undefined : (listener) => listenChanged(events, listener),
|
|
31
|
-
nextRequestId: options.nextRequestId,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function listenChanged(transport: EventTransport, listener: (event: unknown) => void) {
|
|
36
|
-
return transport.listen(NATIVE_CONTENT_CHANGED_EVENT, listener);
|
|
37
|
-
}
|
package/src/notifications.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { isEventTransport } from "@inflatable-cookie/longhorn/core";
|
|
2
|
-
import type { EventTransport, InvokeTransport } from "@inflatable-cookie/longhorn/core";
|
|
3
|
-
|
|
4
|
-
import type { NotificationPort } from "@inflatable-cookie/longhorn/notifications";
|
|
5
|
-
|
|
6
|
-
export const NOTIFICATION_SNAPSHOT_COMMAND = "longhorn_notifications_snapshot";
|
|
7
|
-
export const NOTIFICATION_MUTATE_COMMAND = "longhorn_notifications_mutate";
|
|
8
|
-
export const NOTIFICATION_CHANGED_EVENT = "longhorn://notifications/changed";
|
|
9
|
-
|
|
10
|
-
export interface TauriNotificationPortOptions {
|
|
11
|
-
readonly transport: InvokeTransport;
|
|
12
|
-
readonly nextRequestId: () => string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function createTauriNotificationPort(
|
|
16
|
-
options: TauriNotificationPortOptions,
|
|
17
|
-
): NotificationPort {
|
|
18
|
-
const events = isEventTransport(options.transport) ? options.transport : undefined;
|
|
19
|
-
return {
|
|
20
|
-
snapshot: (query) => options.transport.invoke(NOTIFICATION_SNAPSHOT_COMMAND, { query }),
|
|
21
|
-
mutate: (command) => options.transport.invoke(NOTIFICATION_MUTATE_COMMAND, { command }),
|
|
22
|
-
listen: events === undefined ? undefined : (listener) => listenChanged(events, listener),
|
|
23
|
-
nextRequestId: options.nextRequestId,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function listenChanged(transport: EventTransport, listener: (event: unknown) => void) {
|
|
28
|
-
return transport.listen(NOTIFICATION_CHANGED_EVENT, listener);
|
|
29
|
-
}
|