@opentray/spec 0.2.0 → 0.3.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/README.md +1 -1
- package/dist/index.d.mts +39 -32
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +9 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Shared TypeScript protocol and contract package for OpenTray.
|
|
|
6
6
|
|
|
7
7
|
- Define JSON-RPC payload shapes.
|
|
8
8
|
- Define broker protocol version and endpoint identity helpers.
|
|
9
|
-
- Define public `
|
|
9
|
+
- Define public `Space`, `Tray`, `Session`, and extension contract types.
|
|
10
10
|
- Keep protocol types reusable by the `opentray` package and official extensions.
|
|
11
11
|
|
|
12
12
|
This package must stay platform-neutral and must not import native implementation packages.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
//#region src/index.d.ts
|
|
2
|
-
type
|
|
2
|
+
type SessionId = string;
|
|
3
3
|
type RequestId = string;
|
|
4
|
-
type
|
|
4
|
+
type SpaceId = string;
|
|
5
5
|
type TrayId = string;
|
|
6
6
|
type MenuItemId = number;
|
|
7
|
+
/** @deprecated Use `SessionId`. */
|
|
8
|
+
type LeaseId = SessionId;
|
|
9
|
+
/** @deprecated Use `SpaceId`. */
|
|
10
|
+
type SurfaceId = SpaceId;
|
|
7
11
|
declare const PROTOCOL_VERSION = 1;
|
|
8
12
|
interface BrokerEndpointIdentity {
|
|
9
13
|
packageVersion: string;
|
|
@@ -22,16 +26,19 @@ declare const formatBrokerEndpointName: (identity: BrokerEndpointIdentity) => st
|
|
|
22
26
|
declare const formatBrokerStateRoot: (homeDir: string, identity: BrokerEndpointIdentity) => string;
|
|
23
27
|
declare const formatUnixSocketPath: (homeDir: string, identity: BrokerEndpointIdentity) => string;
|
|
24
28
|
declare const formatWindowsPipeName: (identity: BrokerEndpointIdentity) => string;
|
|
25
|
-
interface
|
|
26
|
-
|
|
29
|
+
interface SpaceOptions {
|
|
30
|
+
id?: SpaceId;
|
|
27
31
|
title?: string;
|
|
28
32
|
icon?: Icon;
|
|
29
33
|
default?: boolean;
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
/** @deprecated Use `SpaceOptions`. */
|
|
36
|
+
type SurfaceOptions = SpaceOptions;
|
|
37
|
+
interface SpaceRef {
|
|
38
|
+
spaceId: SpaceId;
|
|
34
39
|
}
|
|
40
|
+
/** @deprecated Use `SpaceRef`. */
|
|
41
|
+
type SurfaceRef = SpaceRef;
|
|
35
42
|
interface TrayOptions {
|
|
36
43
|
trayId?: TrayId;
|
|
37
44
|
appId?: string;
|
|
@@ -95,27 +102,27 @@ interface Rect {
|
|
|
95
102
|
type MouseButton = "left" | "right" | "middle";
|
|
96
103
|
type TrayEvent = {
|
|
97
104
|
type: "ready";
|
|
98
|
-
|
|
105
|
+
spaceId: SpaceId;
|
|
99
106
|
} | {
|
|
100
107
|
type: "menuClick";
|
|
101
|
-
|
|
108
|
+
spaceId: SpaceId;
|
|
102
109
|
trayId: TrayId;
|
|
103
110
|
itemId: MenuItemId;
|
|
104
111
|
} | {
|
|
105
112
|
type: "trayClick";
|
|
106
|
-
|
|
113
|
+
spaceId: SpaceId;
|
|
107
114
|
button: MouseButton;
|
|
108
115
|
x: number;
|
|
109
116
|
y: number;
|
|
110
117
|
} | {
|
|
111
118
|
type: "trayDoubleClick";
|
|
112
|
-
|
|
119
|
+
spaceId: SpaceId;
|
|
113
120
|
button: MouseButton;
|
|
114
121
|
x: number;
|
|
115
122
|
y: number;
|
|
116
123
|
};
|
|
117
124
|
interface ExtensionScope {
|
|
118
|
-
|
|
125
|
+
spaceId: SpaceId;
|
|
119
126
|
trayId?: TrayId;
|
|
120
127
|
ext: string;
|
|
121
128
|
}
|
|
@@ -125,7 +132,7 @@ interface ExtensionEnvelope<TData = unknown> {
|
|
|
125
132
|
}
|
|
126
133
|
interface DaemonSessionHealth {
|
|
127
134
|
sessionId: number;
|
|
128
|
-
|
|
135
|
+
internalLeaseId?: SessionId;
|
|
129
136
|
initialized: boolean;
|
|
130
137
|
}
|
|
131
138
|
interface DaemonHealth {
|
|
@@ -144,56 +151,56 @@ type ClientFrame = {
|
|
|
144
151
|
type: "exit";
|
|
145
152
|
};
|
|
146
153
|
type ClientRequestFrame = ({
|
|
147
|
-
type: "create-
|
|
154
|
+
type: "create-space";
|
|
148
155
|
requestId: RequestId;
|
|
149
|
-
} &
|
|
150
|
-
type: "resolve-default-
|
|
156
|
+
} & SpaceOptions) | {
|
|
157
|
+
type: "resolve-default-space";
|
|
151
158
|
requestId: RequestId;
|
|
152
159
|
} | {
|
|
153
160
|
type: "create-tray";
|
|
154
161
|
requestId: RequestId;
|
|
155
|
-
|
|
162
|
+
space: SpaceRef;
|
|
156
163
|
tray: TrayOptions;
|
|
157
164
|
} | {
|
|
158
165
|
type: "destroy-tray";
|
|
159
166
|
requestId: RequestId;
|
|
160
|
-
|
|
167
|
+
spaceId: SpaceId;
|
|
161
168
|
trayId: TrayId;
|
|
162
169
|
} | {
|
|
163
170
|
type: "set-tray-menu";
|
|
164
171
|
requestId: RequestId;
|
|
165
|
-
|
|
172
|
+
spaceId: SpaceId;
|
|
166
173
|
trayId: TrayId;
|
|
167
174
|
menu: Menu;
|
|
168
175
|
} | {
|
|
169
176
|
type: "set-tray-icon";
|
|
170
177
|
requestId: RequestId;
|
|
171
|
-
|
|
178
|
+
spaceId: SpaceId;
|
|
172
179
|
trayId: TrayId;
|
|
173
180
|
icon: Icon;
|
|
174
181
|
} | {
|
|
175
182
|
type: "set-tray-tooltip";
|
|
176
183
|
requestId: RequestId;
|
|
177
|
-
|
|
184
|
+
spaceId: SpaceId;
|
|
178
185
|
trayId: TrayId;
|
|
179
186
|
tooltip: Tooltip;
|
|
180
187
|
} | {
|
|
181
188
|
type: "load-ext";
|
|
182
189
|
requestId: RequestId;
|
|
183
|
-
|
|
190
|
+
spaceId: SpaceId;
|
|
184
191
|
name: string;
|
|
185
192
|
path: string;
|
|
186
193
|
} | {
|
|
187
194
|
type: "ext-command";
|
|
188
195
|
requestId: RequestId;
|
|
189
|
-
|
|
196
|
+
spaceId: SpaceId;
|
|
190
197
|
trayId: TrayId;
|
|
191
198
|
ext: string;
|
|
192
199
|
data: unknown;
|
|
193
200
|
} | {
|
|
194
201
|
type: "unload-ext";
|
|
195
202
|
requestId: RequestId;
|
|
196
|
-
|
|
203
|
+
spaceId: SpaceId;
|
|
197
204
|
name: string;
|
|
198
205
|
} | {
|
|
199
206
|
type: "health";
|
|
@@ -203,19 +210,19 @@ type ServerFrame = {
|
|
|
203
210
|
type: "ready";
|
|
204
211
|
protocolVersion: number;
|
|
205
212
|
brokerVersion: string;
|
|
206
|
-
|
|
213
|
+
sessionId: SessionId;
|
|
207
214
|
} | {
|
|
208
|
-
type: "
|
|
215
|
+
type: "space-created";
|
|
209
216
|
requestId: RequestId;
|
|
210
|
-
|
|
217
|
+
space: SpaceRef;
|
|
211
218
|
} | {
|
|
212
|
-
type: "default-
|
|
219
|
+
type: "default-space";
|
|
213
220
|
requestId: RequestId;
|
|
214
|
-
|
|
221
|
+
space: SpaceRef;
|
|
215
222
|
} | {
|
|
216
223
|
type: "tray-created";
|
|
217
224
|
requestId: RequestId;
|
|
218
|
-
|
|
225
|
+
spaceId: SpaceId;
|
|
219
226
|
trayId: TrayId;
|
|
220
227
|
} | {
|
|
221
228
|
type: "ack";
|
|
@@ -229,7 +236,7 @@ type ServerFrame = {
|
|
|
229
236
|
event: TrayEvent;
|
|
230
237
|
} | {
|
|
231
238
|
type: "ext-event";
|
|
232
|
-
|
|
239
|
+
spaceId: SpaceId;
|
|
233
240
|
trayId: TrayId;
|
|
234
241
|
ext: string;
|
|
235
242
|
data: unknown;
|
|
@@ -247,5 +254,5 @@ interface ParseResult<T> {
|
|
|
247
254
|
declare const parseServerFrame: (line: string) => ParseResult<ServerFrame>;
|
|
248
255
|
declare const isServerFrame: (value: unknown) => value is ServerFrame;
|
|
249
256
|
//#endregion
|
|
250
|
-
export { BrokerEndpointIdentity, BrokerEndpointIdentityOptions, ClientFrame, ClientRequestFrame, DaemonHealth, DaemonSessionHealth, ExtensionEnvelope, ExtensionScope, Icon, LeaseId, Menu, MenuItem, MenuItemId, MouseButton, PROTOCOL_VERSION, ParseResult, Rect, RequestId, ServerFrame, SurfaceId, SurfaceOptions, SurfaceRef, Tooltip, TrayEvent, TrayId, TrayOptions, createBrokerEndpointIdentity, formatBrokerEndpointName, formatBrokerStateRoot, formatUnixSocketPath, formatWindowsPipeName, isServerFrame, isSupportedProtocolVersion, parseServerFrame };
|
|
257
|
+
export { BrokerEndpointIdentity, BrokerEndpointIdentityOptions, ClientFrame, ClientRequestFrame, DaemonHealth, DaemonSessionHealth, ExtensionEnvelope, ExtensionScope, Icon, LeaseId, Menu, MenuItem, MenuItemId, MouseButton, PROTOCOL_VERSION, ParseResult, Rect, RequestId, ServerFrame, SessionId, SpaceId, SpaceOptions, SpaceRef, SurfaceId, SurfaceOptions, SurfaceRef, Tooltip, TrayEvent, TrayId, TrayOptions, createBrokerEndpointIdentity, formatBrokerEndpointName, formatBrokerStateRoot, formatUnixSocketPath, formatWindowsPipeName, isServerFrame, isSupportedProtocolVersion, parseServerFrame };
|
|
251
258
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";KAAY,
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";KAAY,SAAA;AAAA,KACA,SAAA;AAAA,KACA,OAAA;AAAA,KACA,MAAA;AAAA,KACA,UAAA;AAJS;AAAA,KAOT,OAAA,GAAU,SAAS;;KAEnB,SAAA,GAAY,OAAO;AAAA,cAElB,gBAAA;AAAA,UAEI,sBAAA;EACf,cAAA;EACA,eAAe;AAAA;AAAA,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AQ,GAAA;EAAa,IAAA;AAAA;EAClE,IAAA;EAAe,SAAA,GAAY,SAAA;EAAW,IAAA;EAAc,OAAA;AAAA;AAAA,UAEzC,WAAA;EACf,EAAA;EACA,KAAA,GAAQ,CAAC;EACT,KAAA;AAAA;AAAA,cAGW,gBAAA,GAAoB,IAAA,aAAe,WAAW,CAAC,WAAA;AAAA,cAkB/C,aAAA,GAAiB,KAAA,cAAiB,KAAA,IAAS,WA2CvD"}
|
package/dist/index.mjs
CHANGED
|
@@ -51,14 +51,14 @@ const isRecord = (value) => typeof value === "object" && value !== null && !Arra
|
|
|
51
51
|
const isServerFrame = (value) => {
|
|
52
52
|
if (!isRecord(value) || typeof value.type !== "string") return false;
|
|
53
53
|
switch (value.type) {
|
|
54
|
-
case "ready": return typeof value.protocolVersion === "number" && typeof value.brokerVersion === "string" && typeof value.
|
|
55
|
-
case "
|
|
56
|
-
case "default-
|
|
57
|
-
case "tray-created": return typeof value.requestId === "string" && typeof value.
|
|
54
|
+
case "ready": return typeof value.protocolVersion === "number" && typeof value.brokerVersion === "string" && typeof value.sessionId === "string";
|
|
55
|
+
case "space-created": return typeof value.requestId === "string" && isRecord(value.space);
|
|
56
|
+
case "default-space": return typeof value.requestId === "string" && isRecord(value.space);
|
|
57
|
+
case "tray-created": return typeof value.requestId === "string" && typeof value.spaceId === "string" && typeof value.trayId === "string";
|
|
58
58
|
case "ack": return typeof value.requestId === "string";
|
|
59
59
|
case "daemon-health": return typeof value.requestId === "string" && isDaemonHealth(value.health);
|
|
60
60
|
case "event": return isTrayEvent(value.event);
|
|
61
|
-
case "ext-event": return typeof value.
|
|
61
|
+
case "ext-event": return typeof value.spaceId === "string" && typeof value.trayId === "string" && typeof value.ext === "string";
|
|
62
62
|
case "error": return (value.requestId === void 0 || typeof value.requestId === "string") && typeof value.code === "string" && typeof value.message === "string";
|
|
63
63
|
default: return false;
|
|
64
64
|
}
|
|
@@ -67,14 +67,14 @@ const isDaemonHealth = (value) => {
|
|
|
67
67
|
if (!isRecord(value)) return false;
|
|
68
68
|
return typeof value.pid === "number" && typeof value.packageVersion === "string" && typeof value.protocolVersion === "number" && typeof value.endpoint === "string" && typeof value.sessionCount === "number" && Array.isArray(value.sessions) && value.sessions.every(isDaemonSessionHealth);
|
|
69
69
|
};
|
|
70
|
-
const isDaemonSessionHealth = (value) => isRecord(value) && typeof value.sessionId === "number" && (value.
|
|
70
|
+
const isDaemonSessionHealth = (value) => isRecord(value) && typeof value.sessionId === "number" && (value.internalLeaseId === void 0 || typeof value.internalLeaseId === "string") && typeof value.initialized === "boolean";
|
|
71
71
|
const isTrayEvent = (value) => {
|
|
72
72
|
if (!isRecord(value) || typeof value.type !== "string") return false;
|
|
73
73
|
switch (value.type) {
|
|
74
|
-
case "ready": return typeof value.
|
|
75
|
-
case "menuClick": return typeof value.
|
|
74
|
+
case "ready": return typeof value.spaceId === "string";
|
|
75
|
+
case "menuClick": return typeof value.spaceId === "string" && typeof value.trayId === "string" && typeof value.itemId === "number";
|
|
76
76
|
case "trayClick":
|
|
77
|
-
case "trayDoubleClick": return typeof value.
|
|
77
|
+
case "trayDoubleClick": return typeof value.spaceId === "string" && isMouseButton(value.button) && typeof value.x === "number" && typeof value.y === "number";
|
|
78
78
|
default: return false;
|
|
79
79
|
}
|
|
80
80
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export type LeaseId = string;\nexport type RequestId = string;\nexport type SurfaceId = string;\nexport type TrayId = string;\nexport type MenuItemId = number;\n\nexport const PROTOCOL_VERSION = 1;\n\nexport interface BrokerEndpointIdentity {\n packageVersion: string;\n protocolVersion: number;\n}\n\nexport interface BrokerEndpointIdentityOptions {\n packageVersion: string;\n protocolVersion?: number;\n}\n\nexport const createBrokerEndpointIdentity = ({\n packageVersion,\n protocolVersion = PROTOCOL_VERSION,\n}: BrokerEndpointIdentityOptions): BrokerEndpointIdentity => {\n assertEndpointComponent(packageVersion, \"packageVersion\");\n if (!Number.isInteger(protocolVersion) || protocolVersion <= 0) {\n throw new Error(`protocolVersion must be a positive integer: ${protocolVersion}`);\n }\n\n return {\n packageVersion,\n protocolVersion,\n };\n};\n\nexport const isSupportedProtocolVersion = (protocolVersion: number): boolean =>\n protocolVersion === PROTOCOL_VERSION;\n\nexport const formatBrokerEndpointName = (identity: BrokerEndpointIdentity): string => {\n assertEndpointIdentity(identity);\n return `opentray-${identity.packageVersion}-p${identity.protocolVersion}`;\n};\n\nexport const formatBrokerStateRoot = (homeDir: string, identity: BrokerEndpointIdentity): string => {\n assertEndpointIdentity(identity);\n if (homeDir.length === 0) {\n throw new Error(\"homeDir must not be empty\");\n }\n\n const normalizedHome = homeDir.replace(/[\\\\/]+$/u, \"\");\n return `${normalizedHome}/.opentray/${identity.packageVersion}`;\n};\n\nexport const formatUnixSocketPath = (homeDir: string, identity: BrokerEndpointIdentity): string =>\n `${formatBrokerStateRoot(homeDir, identity)}/opentray-p${identity.protocolVersion}.sock`;\n\nexport const formatWindowsPipeName = (identity: BrokerEndpointIdentity): string =>\n `\\\\\\\\.\\\\pipe\\\\${formatBrokerEndpointName(identity)}`;\n\nconst endpointComponentPattern = /^[0-9A-Za-z._+-]+$/u;\n\nconst assertEndpointIdentity = (identity: BrokerEndpointIdentity): void => {\n assertEndpointComponent(identity.packageVersion, \"packageVersion\");\n if (!Number.isInteger(identity.protocolVersion) || identity.protocolVersion <= 0) {\n throw new Error(`protocolVersion must be a positive integer: ${identity.protocolVersion}`);\n }\n};\n\nconst assertEndpointComponent = (value: string, name: string): void => {\n if (value.length === 0) {\n throw new Error(`${name} must not be empty`);\n }\n if (!endpointComponentPattern.test(value)) {\n throw new Error(`${name} contains invalid endpoint characters: ${value}`);\n }\n};\n\nexport interface SurfaceOptions {\n appId: string;\n title?: string;\n icon?: Icon;\n default?: boolean;\n}\n\nexport interface SurfaceRef {\n surfaceId: SurfaceId;\n appId: string;\n}\n\nexport interface TrayOptions {\n trayId?: TrayId;\n appId?: string;\n title?: string;\n tooltip?: Tooltip;\n icon: Icon;\n menu?: Menu;\n}\n\nexport interface Tooltip {\n title: string;\n description: string;\n}\n\nexport interface Menu {\n items: MenuItem[];\n}\n\nexport type MenuItem =\n | {\n type: \"item\";\n id: MenuItemId;\n title: string;\n enabled?: boolean;\n shortcut?: string;\n }\n | {\n type: \"check\";\n id: MenuItemId;\n title: string;\n enabled?: boolean;\n checked?: boolean;\n }\n | {\n type: \"radio\";\n id: MenuItemId;\n title: string;\n enabled?: boolean;\n checked?: boolean;\n group: number;\n }\n | {\n type: \"separator\";\n }\n | {\n type: \"submenu\";\n title: string;\n enabled?: boolean;\n items: MenuItem[];\n };\n\nexport type Icon =\n | { type: \"rgba\"; data: Uint8Array | number[]; width: number; height: number }\n | { type: \"encoded\"; data: Uint8Array | number[] }\n | { type: \"file\"; path: string };\n\nexport interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport type MouseButton = \"left\" | \"right\" | \"middle\";\n\nexport type TrayEvent =\n | { type: \"ready\"; surfaceId: SurfaceId }\n | { type: \"menuClick\"; surfaceId: SurfaceId; trayId: TrayId; itemId: MenuItemId }\n | { type: \"trayClick\"; surfaceId: SurfaceId; button: MouseButton; x: number; y: number }\n | { type: \"trayDoubleClick\"; surfaceId: SurfaceId; button: MouseButton; x: number; y: number };\n\nexport interface ExtensionScope {\n surfaceId: SurfaceId;\n trayId?: TrayId;\n ext: string;\n}\n\nexport interface ExtensionEnvelope<TData = unknown> {\n scope: ExtensionScope;\n data: TData;\n}\n\nexport interface DaemonSessionHealth {\n sessionId: number;\n leaseId?: LeaseId;\n initialized: boolean;\n}\n\nexport interface DaemonHealth {\n pid: number;\n packageVersion: string;\n protocolVersion: number;\n endpoint: string;\n sessionCount: number;\n sessions: DaemonSessionHealth[];\n}\n\nexport type ClientFrame =\n | { type: \"init\"; protocolVersion: number; clientVersion: string }\n | ClientRequestFrame\n | { type: \"exit\" };\n\nexport type ClientRequestFrame =\n | ({ type: \"create-surface\"; requestId: RequestId } & SurfaceOptions)\n | { type: \"resolve-default-surface\"; requestId: RequestId }\n | { type: \"create-tray\"; requestId: RequestId; surface: SurfaceRef; tray: TrayOptions }\n | { type: \"destroy-tray\"; requestId: RequestId; surfaceId: SurfaceId; trayId: TrayId }\n | { type: \"set-tray-menu\"; requestId: RequestId; surfaceId: SurfaceId; trayId: TrayId; menu: Menu }\n | { type: \"set-tray-icon\"; requestId: RequestId; surfaceId: SurfaceId; trayId: TrayId; icon: Icon }\n | { type: \"set-tray-tooltip\"; requestId: RequestId; surfaceId: SurfaceId; trayId: TrayId; tooltip: Tooltip }\n | { type: \"load-ext\"; requestId: RequestId; surfaceId: SurfaceId; name: string; path: string }\n | { type: \"ext-command\"; requestId: RequestId; surfaceId: SurfaceId; trayId: TrayId; ext: string; data: unknown }\n | { type: \"unload-ext\"; requestId: RequestId; surfaceId: SurfaceId; name: string }\n | { type: \"health\"; requestId: RequestId };\n\nexport type ServerFrame =\n | { type: \"ready\"; protocolVersion: number; brokerVersion: string; leaseId: LeaseId }\n | { type: \"surface-created\"; requestId: RequestId; surface: SurfaceRef }\n | { type: \"default-surface\"; requestId: RequestId; surface: SurfaceRef }\n | { type: \"tray-created\"; requestId: RequestId; surfaceId: SurfaceId; trayId: TrayId }\n | { type: \"ack\"; requestId: RequestId }\n | { type: \"daemon-health\"; requestId: RequestId; health: DaemonHealth }\n | { type: \"event\"; event: TrayEvent }\n | { type: \"ext-event\"; surfaceId: SurfaceId; trayId: TrayId; ext: string; data: unknown }\n | { type: \"error\"; requestId?: RequestId; code: string; message: string };\n\nexport interface ParseResult<T> {\n ok: boolean;\n frame?: T;\n error?: string;\n}\n\nexport const parseServerFrame = (line: string): ParseResult<ServerFrame> => {\n try {\n const value: unknown = JSON.parse(line);\n if (!isServerFrame(value)) {\n return { ok: false, error: \"invalid server frame\" };\n }\n return { ok: true, frame: value };\n } catch (error) {\n return {\n ok: false,\n error: error instanceof Error ? error.message : \"unknown parse error\",\n };\n }\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nexport const isServerFrame = (value: unknown): value is ServerFrame => {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n switch (value.type) {\n case \"ready\":\n return (\n typeof value.protocolVersion === \"number\" &&\n typeof value.brokerVersion === \"string\" &&\n typeof value.leaseId === \"string\"\n );\n case \"surface-created\":\n return typeof value.requestId === \"string\" && isRecord(value.surface);\n case \"default-surface\":\n return typeof value.requestId === \"string\" && isRecord(value.surface);\n case \"tray-created\":\n return (\n typeof value.requestId === \"string\" &&\n typeof value.surfaceId === \"string\" &&\n typeof value.trayId === \"string\"\n );\n case \"ack\":\n return typeof value.requestId === \"string\";\n case \"daemon-health\":\n return typeof value.requestId === \"string\" && isDaemonHealth(value.health);\n case \"event\":\n return isTrayEvent(value.event);\n case \"ext-event\":\n return (\n typeof value.surfaceId === \"string\" &&\n typeof value.trayId === \"string\" &&\n typeof value.ext === \"string\"\n );\n case \"error\":\n return (\n (value.requestId === undefined || typeof value.requestId === \"string\") &&\n typeof value.code === \"string\" &&\n typeof value.message === \"string\"\n );\n default:\n return false;\n }\n};\n\nconst isDaemonHealth = (value: unknown): value is DaemonHealth => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n typeof value.pid === \"number\" &&\n typeof value.packageVersion === \"string\" &&\n typeof value.protocolVersion === \"number\" &&\n typeof value.endpoint === \"string\" &&\n typeof value.sessionCount === \"number\" &&\n Array.isArray(value.sessions) &&\n value.sessions.every(isDaemonSessionHealth)\n );\n};\n\nconst isDaemonSessionHealth = (value: unknown): value is DaemonSessionHealth =>\n isRecord(value) &&\n typeof value.sessionId === \"number\" &&\n (value.leaseId === undefined || typeof value.leaseId === \"string\") &&\n typeof value.initialized === \"boolean\";\n\nconst isTrayEvent = (value: unknown): value is TrayEvent => {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n switch (value.type) {\n case \"ready\":\n return typeof value.surfaceId === \"string\";\n case \"menuClick\":\n return (\n typeof value.surfaceId === \"string\" &&\n typeof value.trayId === \"string\" &&\n typeof value.itemId === \"number\"\n );\n case \"trayClick\":\n case \"trayDoubleClick\":\n return (\n typeof value.surfaceId === \"string\" &&\n isMouseButton(value.button) &&\n typeof value.x === \"number\" &&\n typeof value.y === \"number\"\n );\n default:\n return false;\n }\n};\n\nconst isMouseButton = (value: unknown): value is MouseButton =>\n value === \"left\" || value === \"right\" || value === \"middle\";\n"],"mappings":";AAMA,MAAa,mBAAmB;AAYhC,MAAa,gCAAgC,EAC3C,gBACA,kBAAA,QAC2D;CAC3D,wBAAwB,gBAAgB,gBAAgB;CACxD,IAAI,CAAC,OAAO,UAAU,eAAe,KAAK,mBAAmB,GAC3D,MAAM,IAAI,MAAM,+CAA+C,iBAAiB;CAGlF,OAAO;EACL;EACA;CACF;AACF;AAEA,MAAa,8BAA8B,oBACzC,oBAAA;AAEF,MAAa,4BAA4B,aAA6C;CACpF,uBAAuB,QAAQ;CAC/B,OAAO,YAAY,SAAS,eAAe,IAAI,SAAS;AAC1D;AAEA,MAAa,yBAAyB,SAAiB,aAA6C;CAClG,uBAAuB,QAAQ;CAC/B,IAAI,QAAQ,WAAW,GACrB,MAAM,IAAI,MAAM,2BAA2B;CAI7C,OAAO,GADgB,QAAQ,QAAQ,YAAY,EAC5B,EAAE,aAAa,SAAS;AACjD;AAEA,MAAa,wBAAwB,SAAiB,aACpD,GAAG,sBAAsB,SAAS,QAAQ,EAAE,aAAa,SAAS,gBAAgB;AAEpF,MAAa,yBAAyB,aACpC,gBAAgB,yBAAyB,QAAQ;AAEnD,MAAM,2BAA2B;AAEjC,MAAM,0BAA0B,aAA2C;CACzE,wBAAwB,SAAS,gBAAgB,gBAAgB;CACjE,IAAI,CAAC,OAAO,UAAU,SAAS,eAAe,KAAK,SAAS,mBAAmB,GAC7E,MAAM,IAAI,MAAM,+CAA+C,SAAS,iBAA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W,YACxB,OAAO,MAAM,QAAQ;EAEzB,KAAK,SACH,QACG,MAAM,cAAc,KAAA,KAAa,OAAO,MAAM,cAAc,aAC7D,OAAO,MAAM,SAAS,YACtB,OAAO,MAAM,YAAY;EAE7B,SACE,OAAO;CACX;AACF;AAEA,MAAM,kBAAkB,UAA0C;CAChE,IAAI,CAAC,SAAS,KAAK,GACjB,OAAO;CAGT,OACE,OAAO,MAAM,QAAQ,YACrB,OAAO,MAAM,mBAAmB,YAChC,OAAO,MAAM,oBAAoB,YACjC,OAAO,MAAM,aAAa,YAC1B,OAAO,MAAM,iBAAiB,YAC9B,MAAM,QAAQ,MAAM,QAAQ,KAC5B,MAAM,SAAS,MAAM,qBAAqB;AAE9C;AAEA,MAAM,yBAAyB,UAC7B,SAAS,KAAK,KACd,OAAO,MAAM,cAAc,aAC1B,MAAM,YAAY,KAAA,KAAa,OAAO,MAAM,YAAY,aACzD,OAAO,MAAM,gBAAgB;AAE/B,MAAM,eAAe,UAAuC;CAC1D,IAAI,CAAC,SAAS,KAAK,KAAK,OAAO,MAAM,SAAS,UAC5C,OAAO;CAGT,QAAQ,MAAM,MAAd;EACE,KAAK,SACH,OAAO,OAAO,MAAM,cAAc;EACpC,KAAK,aACH,OACE,OAAO,MAAM,cAAc,YAC3B,OAAO,MAAM,WAAW,YACxB,OAAO,MAAM,WAAW;EAE5B,KAAK;EACL,KAAK,mBACH,OACE,OAAO,MAAM,cAAc,YAC3B,cAAc,MAAM,MAAM,KAC1B,OAAO,MAAM,MAAM,YACnB,OAAO,MAAM,MAAM;EAEvB,SACE,OAAO;CACX;AACF;AAEA,MAAM,iBAAiB,UACrB,UAAU,UAAU,UAAU,WAAW,UAAU"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["export type SessionId = string;\nexport type RequestId = string;\nexport type SpaceId = string;\nexport type TrayId = string;\nexport type MenuItemId = number;\n\n/** @deprecated Use `SessionId`. */\nexport type LeaseId = SessionId;\n/** @deprecated Use `SpaceId`. */\nexport type SurfaceId = SpaceId;\n\nexport const PROTOCOL_VERSION = 1;\n\nexport interface BrokerEndpointIdentity {\n packageVersion: string;\n protocolVersion: number;\n}\n\nexport interface BrokerEndpointIdentityOptions {\n packageVersion: string;\n protocolVersion?: number;\n}\n\nexport const createBrokerEndpointIdentity = ({\n packageVersion,\n protocolVersion = PROTOCOL_VERSION,\n}: BrokerEndpointIdentityOptions): BrokerEndpointIdentity => {\n assertEndpointComponent(packageVersion, \"packageVersion\");\n if (!Number.isInteger(protocolVersion) || protocolVersion <= 0) {\n throw new Error(`protocolVersion must be a positive integer: ${protocolVersion}`);\n }\n\n return {\n packageVersion,\n protocolVersion,\n };\n};\n\nexport const isSupportedProtocolVersion = (protocolVersion: number): boolean =>\n protocolVersion === PROTOCOL_VERSION;\n\nexport const formatBrokerEndpointName = (identity: BrokerEndpointIdentity): string => {\n assertEndpointIdentity(identity);\n return `opentray-${identity.packageVersion}-p${identity.protocolVersion}`;\n};\n\nexport const formatBrokerStateRoot = (homeDir: string, identity: BrokerEndpointIdentity): string => {\n assertEndpointIdentity(identity);\n if (homeDir.length === 0) {\n throw new Error(\"homeDir must not be empty\");\n }\n\n const normalizedHome = homeDir.replace(/[\\\\/]+$/u, \"\");\n return `${normalizedHome}/.opentray/${identity.packageVersion}`;\n};\n\nexport const formatUnixSocketPath = (homeDir: string, identity: BrokerEndpointIdentity): string =>\n `${formatBrokerStateRoot(homeDir, identity)}/opentray-p${identity.protocolVersion}.sock`;\n\nexport const formatWindowsPipeName = (identity: BrokerEndpointIdentity): string =>\n `\\\\\\\\.\\\\pipe\\\\${formatBrokerEndpointName(identity)}`;\n\nconst endpointComponentPattern = /^[0-9A-Za-z._+-]+$/u;\n\nconst assertEndpointIdentity = (identity: BrokerEndpointIdentity): void => {\n assertEndpointComponent(identity.packageVersion, \"packageVersion\");\n if (!Number.isInteger(identity.protocolVersion) || identity.protocolVersion <= 0) {\n throw new Error(`protocolVersion must be a positive integer: ${identity.protocolVersion}`);\n }\n};\n\nconst assertEndpointComponent = (value: string, name: string): void => {\n if (value.length === 0) {\n throw new Error(`${name} must not be empty`);\n }\n if (!endpointComponentPattern.test(value)) {\n throw new Error(`${name} contains invalid endpoint characters: ${value}`);\n }\n};\n\nexport interface SpaceOptions {\n id?: SpaceId;\n title?: string;\n icon?: Icon;\n default?: boolean;\n}\n\n/** @deprecated Use `SpaceOptions`. */\nexport type SurfaceOptions = SpaceOptions;\n\nexport interface SpaceRef {\n spaceId: SpaceId;\n}\n\n/** @deprecated Use `SpaceRef`. */\nexport type SurfaceRef = SpaceRef;\n\nexport interface TrayOptions {\n trayId?: TrayId;\n appId?: string;\n title?: string;\n tooltip?: Tooltip;\n icon: Icon;\n menu?: Menu;\n}\n\nexport interface Tooltip {\n title: string;\n description: string;\n}\n\nexport interface Menu {\n items: MenuItem[];\n}\n\nexport type MenuItem =\n | {\n type: \"item\";\n id: MenuItemId;\n title: string;\n enabled?: boolean;\n shortcut?: string;\n }\n | {\n type: \"check\";\n id: MenuItemId;\n title: string;\n enabled?: boolean;\n checked?: boolean;\n }\n | {\n type: \"radio\";\n id: MenuItemId;\n title: string;\n enabled?: boolean;\n checked?: boolean;\n group: number;\n }\n | {\n type: \"separator\";\n }\n | {\n type: \"submenu\";\n title: string;\n enabled?: boolean;\n items: MenuItem[];\n };\n\nexport type Icon =\n | { type: \"rgba\"; data: Uint8Array | number[]; width: number; height: number }\n | { type: \"encoded\"; data: Uint8Array | number[] }\n | { type: \"file\"; path: string };\n\nexport interface Rect {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\nexport type MouseButton = \"left\" | \"right\" | \"middle\";\n\nexport type TrayEvent =\n | { type: \"ready\"; spaceId: SpaceId }\n | { type: \"menuClick\"; spaceId: SpaceId; trayId: TrayId; itemId: MenuItemId }\n | { type: \"trayClick\"; spaceId: SpaceId; button: MouseButton; x: number; y: number }\n | { type: \"trayDoubleClick\"; spaceId: SpaceId; button: MouseButton; x: number; y: number };\n\nexport interface ExtensionScope {\n spaceId: SpaceId;\n trayId?: TrayId;\n ext: string;\n}\n\nexport interface ExtensionEnvelope<TData = unknown> {\n scope: ExtensionScope;\n data: TData;\n}\n\nexport interface DaemonSessionHealth {\n sessionId: number;\n internalLeaseId?: SessionId;\n initialized: boolean;\n}\n\nexport interface DaemonHealth {\n pid: number;\n packageVersion: string;\n protocolVersion: number;\n endpoint: string;\n sessionCount: number;\n sessions: DaemonSessionHealth[];\n}\n\nexport type ClientFrame =\n | { type: \"init\"; protocolVersion: number; clientVersion: string }\n | ClientRequestFrame\n | { type: \"exit\" };\n\nexport type ClientRequestFrame =\n | ({ type: \"create-space\"; requestId: RequestId } & SpaceOptions)\n | { type: \"resolve-default-space\"; requestId: RequestId }\n | { type: \"create-tray\"; requestId: RequestId; space: SpaceRef; tray: TrayOptions }\n | { type: \"destroy-tray\"; requestId: RequestId; spaceId: SpaceId; trayId: TrayId }\n | { type: \"set-tray-menu\"; requestId: RequestId; spaceId: SpaceId; trayId: TrayId; menu: Menu }\n | { type: \"set-tray-icon\"; requestId: RequestId; spaceId: SpaceId; trayId: TrayId; icon: Icon }\n | { type: \"set-tray-tooltip\"; requestId: RequestId; spaceId: SpaceId; trayId: TrayId; tooltip: Tooltip }\n | { type: \"load-ext\"; requestId: RequestId; spaceId: SpaceId; name: string; path: string }\n | { type: \"ext-command\"; requestId: RequestId; spaceId: SpaceId; trayId: TrayId; ext: string; data: unknown }\n | { type: \"unload-ext\"; requestId: RequestId; spaceId: SpaceId; name: string }\n | { type: \"health\"; requestId: RequestId };\n\nexport type ServerFrame =\n | { type: \"ready\"; protocolVersion: number; brokerVersion: string; sessionId: SessionId }\n | { type: \"space-created\"; requestId: RequestId; space: SpaceRef }\n | { type: \"default-space\"; requestId: RequestId; space: SpaceRef }\n | { type: \"tray-created\"; requestId: RequestId; spaceId: SpaceId; trayId: TrayId }\n | { type: \"ack\"; requestId: RequestId }\n | { type: \"daemon-health\"; requestId: RequestId; health: DaemonHealth }\n | { type: \"event\"; event: TrayEvent }\n | { type: \"ext-event\"; spaceId: SpaceId; trayId: TrayId; ext: string; data: unknown }\n | { type: \"error\"; requestId?: RequestId; code: string; message: string };\n\nexport interface ParseResult<T> {\n ok: boolean;\n frame?: T;\n error?: string;\n}\n\nexport const parseServerFrame = (line: string): ParseResult<ServerFrame> => {\n try {\n const value: unknown = JSON.parse(line);\n if (!isServerFrame(value)) {\n return { ok: false, error: \"invalid server frame\" };\n }\n return { ok: true, frame: value };\n } catch (error) {\n return {\n ok: false,\n error: error instanceof Error ? error.message : \"unknown parse error\",\n };\n }\n};\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nexport const isServerFrame = (value: unknown): value is ServerFrame => {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n switch (value.type) {\n case \"ready\":\n return (\n typeof value.protocolVersion === \"number\" &&\n typeof value.brokerVersion === \"string\" &&\n typeof value.sessionId === \"string\"\n );\n case \"space-created\":\n return typeof value.requestId === \"string\" && isRecord(value.space);\n case \"default-space\":\n return typeof value.requestId === \"string\" && isRecord(value.space);\n case \"tray-created\":\n return (\n typeof value.requestId === \"string\" &&\n typeof value.spaceId === \"string\" &&\n typeof value.trayId === \"string\"\n );\n case \"ack\":\n return typeof value.requestId === \"string\";\n case \"daemon-health\":\n return typeof value.requestId === \"string\" && isDaemonHealth(value.health);\n case \"event\":\n return isTrayEvent(value.event);\n case \"ext-event\":\n return (\n typeof value.spaceId === \"string\" &&\n typeof value.trayId === \"string\" &&\n typeof value.ext === \"string\"\n );\n case \"error\":\n return (\n (value.requestId === undefined || typeof value.requestId === \"string\") &&\n typeof value.code === \"string\" &&\n typeof value.message === \"string\"\n );\n default:\n return false;\n }\n};\n\nconst isDaemonHealth = (value: unknown): value is DaemonHealth => {\n if (!isRecord(value)) {\n return false;\n }\n\n return (\n typeof value.pid === \"number\" &&\n typeof value.packageVersion === \"string\" &&\n typeof value.protocolVersion === \"number\" &&\n typeof value.endpoint === \"string\" &&\n typeof value.sessionCount === \"number\" &&\n Array.isArray(value.sessions) &&\n value.sessions.every(isDaemonSessionHealth)\n );\n};\n\nconst isDaemonSessionHealth = (value: unknown): value is DaemonSessionHealth =>\n isRecord(value) &&\n typeof value.sessionId === \"number\" &&\n (value.internalLeaseId === undefined || typeof value.internalLeaseId === \"string\") &&\n typeof value.initialized === \"boolean\";\n\nconst isTrayEvent = (value: unknown): value is TrayEvent => {\n if (!isRecord(value) || typeof value.type !== \"string\") {\n return false;\n }\n\n switch (value.type) {\n case \"ready\":\n return typeof value.spaceId === \"string\";\n case \"menuClick\":\n return (\n typeof value.spaceId === \"string\" &&\n typeof value.trayId === \"string\" &&\n typeof value.itemId === \"number\"\n );\n case \"trayClick\":\n case \"trayDoubleClick\":\n return (\n typeof value.spaceId === \"string\" &&\n isMouseButton(value.button) &&\n typeof value.x === \"number\" &&\n typeof value.y === \"number\"\n );\n default:\n return false;\n }\n};\n\nconst isMouseButton = (value: unknown): value is MouseButton =>\n value === \"left\" || value === \"right\" || value === \"middle\";\n"],"mappings":";AAWA,MAAa,mBAAmB;AAYhC,MAAa,gCAAgC,EAC3C,gBACA,kBAAA,QAC2D;CAC3D,wBAAwB,gBAAgB,gBAAgB;CACxD,IAAI,CAAC,OAAO,UAAU,eAAe,KAAK,mBAAmB,GAC3D,MAAM,IAAI,MAAM,+CAA+C,iBAAiB;CAGlF,OAAO;EACL;EACA;CACF;AACF;AAEA,MAAa,8BAA8B,oBACzC,oBAAA;AAEF,MAAa,4BAA4B,aAA6C;CACpF,uBAAuB,QAAQ;CAC/B,OAAO,YAAY,SAAS,eAAe,IAAI,SAAS;AAC1D;AAEA,MAAa,yBAAyB,SAAiB,aAA6C;CAClG,uBAAuB,QAAQ;CAC/B,IAAI,QAAQ,WAAW,GACrB,MAAM,IAAI,MAAM,2BAA2B;CAI7C,OAAO,GADgB,QAAQ,QAAQ,YAAY,EAC5B,EAAE,aAAa,SAAS;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