@edenapp/types 0.2.0 → 0.2.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/ipc/appbus.d.ts +232 -0
- package/ipc/edenapi.d.ts +61 -0
- package/ipc/index.d.ts +6 -0
- package/package.json +2 -1
package/ipc/appbus.d.ts
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AppBus Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Interface for app-to-app communication.
|
|
5
|
+
* Used by both frontend (window.appBus) and backend (worker.appBus).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Schema for fire-and-forget messages (send/on/once)
|
|
10
|
+
* Keys are method names, values are the payload types
|
|
11
|
+
*/
|
|
12
|
+
export type MessageSchema = Record<string, any>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Schema for request/response (request/handle)
|
|
16
|
+
* Keys are method names, values are { args, result } types
|
|
17
|
+
*/
|
|
18
|
+
export type RequestSchema = Record<string, { args: any; result: any }>;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Defines a bidirectional communication protocol between two sides.
|
|
22
|
+
* Use "host" for the side that exposes the service (exposeService).
|
|
23
|
+
* Use "peer" for the side that connects to the service (connect).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* type ChatProtocol = {
|
|
27
|
+
* // Messages the host sends, peer receives
|
|
28
|
+
* hostMessages: {
|
|
29
|
+
* 'welcome': { text: string };
|
|
30
|
+
* 'userJoined': { nickname: string };
|
|
31
|
+
* };
|
|
32
|
+
* // Messages the peer sends, host receives
|
|
33
|
+
* peerMessages: {
|
|
34
|
+
* 'typing': { isTyping: boolean };
|
|
35
|
+
* };
|
|
36
|
+
* // Requests the host handles (peer calls request, host calls handle)
|
|
37
|
+
* hostHandles: {
|
|
38
|
+
* 'join': { args: { nickname: string }; result: { success: boolean } };
|
|
39
|
+
* 'sendMessage': { args: { text: string }; result: void };
|
|
40
|
+
* };
|
|
41
|
+
* // Requests the peer handles (host calls request, peer calls handle)
|
|
42
|
+
* peerHandles: {
|
|
43
|
+
* 'ping': { args: {}; result: { pong: boolean } };
|
|
44
|
+
* };
|
|
45
|
+
* };
|
|
46
|
+
*/
|
|
47
|
+
export interface ChannelProtocol {
|
|
48
|
+
/** Messages sent by host, received by peer */
|
|
49
|
+
hostMessages: MessageSchema;
|
|
50
|
+
/** Messages sent by peer, received by host */
|
|
51
|
+
peerMessages: MessageSchema;
|
|
52
|
+
/** Requests that peer sends, host handles */
|
|
53
|
+
hostHandles: RequestSchema;
|
|
54
|
+
/** Requests that host sends, peer handles */
|
|
55
|
+
peerHandles: RequestSchema;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Default empty protocol (all any)
|
|
60
|
+
*/
|
|
61
|
+
type DefaultProtocol = {
|
|
62
|
+
hostMessages: MessageSchema;
|
|
63
|
+
peerMessages: MessageSchema;
|
|
64
|
+
hostHandles: RequestSchema;
|
|
65
|
+
peerHandles: RequestSchema;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* AppBus connection from the HOST perspective (the side that exposes the service).
|
|
70
|
+
* - send() sends hostMessages
|
|
71
|
+
* - on()/once() receives peerMessages
|
|
72
|
+
* - request() calls peerHandles
|
|
73
|
+
* - handle() implements hostHandles
|
|
74
|
+
*/
|
|
75
|
+
export type HostConnection<P extends ChannelProtocol> = AppBusConnection<
|
|
76
|
+
P["hostMessages"],
|
|
77
|
+
P["peerMessages"],
|
|
78
|
+
P["peerHandles"],
|
|
79
|
+
P["hostHandles"]
|
|
80
|
+
>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* AppBus connection from the PEER perspective (the side that connects).
|
|
84
|
+
* - send() sends peerMessages
|
|
85
|
+
* - on()/once() receives hostMessages
|
|
86
|
+
* - request() calls hostHandles
|
|
87
|
+
* - handle() implements peerHandles
|
|
88
|
+
*/
|
|
89
|
+
export type PeerConnection<P extends ChannelProtocol> = AppBusConnection<
|
|
90
|
+
P["peerMessages"],
|
|
91
|
+
P["hostMessages"],
|
|
92
|
+
P["hostHandles"],
|
|
93
|
+
P["peerHandles"]
|
|
94
|
+
>;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* AppBus connection returned by connect()
|
|
98
|
+
* Also used for frontend<->backend communication (appAPI)
|
|
99
|
+
*
|
|
100
|
+
* @typeParam TSend - Messages this side sends
|
|
101
|
+
* @typeParam TReceive - Messages this side receives
|
|
102
|
+
* @typeParam TRequest - Requests this side makes (other side handles)
|
|
103
|
+
* @typeParam THandle - Requests this side handles (other side makes)
|
|
104
|
+
*
|
|
105
|
+
* For typed connections, use HostConnection<Protocol> or PeerConnection<Protocol>
|
|
106
|
+
* which automatically flip the perspective.
|
|
107
|
+
*/
|
|
108
|
+
export interface AppBusConnection<
|
|
109
|
+
TSend extends MessageSchema = MessageSchema,
|
|
110
|
+
TReceive extends MessageSchema = MessageSchema,
|
|
111
|
+
TRequest extends RequestSchema = RequestSchema,
|
|
112
|
+
THandle extends RequestSchema = RequestSchema,
|
|
113
|
+
> {
|
|
114
|
+
/** Send a fire-and-forget message */
|
|
115
|
+
send<K extends keyof TSend>(method: K, args?: TSend[K]): void;
|
|
116
|
+
|
|
117
|
+
/** Listen for messages from the other side */
|
|
118
|
+
on<K extends keyof TReceive>(
|
|
119
|
+
method: K,
|
|
120
|
+
callback: (args: TReceive[K]) => void
|
|
121
|
+
): void;
|
|
122
|
+
/** Listen for messages only once, then auto-remove */
|
|
123
|
+
once<K extends keyof TReceive>(
|
|
124
|
+
method: K,
|
|
125
|
+
callback: (args: TReceive[K]) => void
|
|
126
|
+
): void;
|
|
127
|
+
/** Remove a listener */
|
|
128
|
+
off<K extends keyof TReceive>(
|
|
129
|
+
method: K,
|
|
130
|
+
callback: (args: TReceive[K]) => void
|
|
131
|
+
): void;
|
|
132
|
+
|
|
133
|
+
/** Send a request and wait for response (other side handles) */
|
|
134
|
+
request<K extends keyof TRequest>(
|
|
135
|
+
method: K,
|
|
136
|
+
args?: TRequest[K]["args"]
|
|
137
|
+
): Promise<TRequest[K]["result"]>;
|
|
138
|
+
|
|
139
|
+
/** Register a handler for requests from the other side */
|
|
140
|
+
handle<K extends keyof THandle>(
|
|
141
|
+
method: K,
|
|
142
|
+
handler: (
|
|
143
|
+
args: THandle[K]["args"]
|
|
144
|
+
) => THandle[K]["result"] | Promise<THandle[K]["result"]>
|
|
145
|
+
): void;
|
|
146
|
+
/** Remove a handler */
|
|
147
|
+
removeHandler<K extends keyof THandle>(method: K): void;
|
|
148
|
+
|
|
149
|
+
/** Check if the connection is active */
|
|
150
|
+
isConnected: () => boolean;
|
|
151
|
+
/** Register a callback for when the connection closes */
|
|
152
|
+
onClose: (callback: () => void) => void;
|
|
153
|
+
/** Close the connection */
|
|
154
|
+
close: () => void;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Information about a connecting client
|
|
159
|
+
*/
|
|
160
|
+
export interface ClientInfo {
|
|
161
|
+
appId: string;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Callback invoked when a client connects to a service
|
|
166
|
+
*/
|
|
167
|
+
export type ServiceConnectCallback = (
|
|
168
|
+
connection: AppBusConnection,
|
|
169
|
+
clientInfo: ClientInfo
|
|
170
|
+
) => void;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Service registration options
|
|
174
|
+
*/
|
|
175
|
+
export interface ServiceOptions {
|
|
176
|
+
description?: string;
|
|
177
|
+
allowedClients?: string[];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Service info returned by listServices
|
|
182
|
+
*/
|
|
183
|
+
export interface ServiceInfo {
|
|
184
|
+
appId: string;
|
|
185
|
+
serviceName: string;
|
|
186
|
+
description?: string;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* AppBus API - app-to-app communication
|
|
191
|
+
*/
|
|
192
|
+
export interface AppBusAPI {
|
|
193
|
+
/**
|
|
194
|
+
* Register a service that other apps can connect to.
|
|
195
|
+
* When a client connects, onConnect is called with their AppBusConnection.
|
|
196
|
+
* @param serviceName - Name of the service
|
|
197
|
+
* @param onConnect - Callback invoked for each connecting client with their bidirectional connection
|
|
198
|
+
* @param options - Optional configuration
|
|
199
|
+
*/
|
|
200
|
+
exposeService(
|
|
201
|
+
serviceName: string,
|
|
202
|
+
onConnect: ServiceConnectCallback,
|
|
203
|
+
options?: ServiceOptions
|
|
204
|
+
): Promise<{ success: boolean; error?: string }>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Unregister a service
|
|
208
|
+
* @param serviceName - Name of the service to unregister
|
|
209
|
+
*/
|
|
210
|
+
unexposeService(serviceName: string): Promise<{ success: boolean }>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Connect to another app's service
|
|
214
|
+
* @param targetAppId - App ID of the target app
|
|
215
|
+
* @param serviceName - Name of the service to connect to
|
|
216
|
+
*/
|
|
217
|
+
connect(
|
|
218
|
+
targetAppId: string,
|
|
219
|
+
serviceName: string
|
|
220
|
+
): Promise<AppBusConnection | { error: string }>;
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* List all available services
|
|
224
|
+
*/
|
|
225
|
+
listServices(): Promise<{ services: ServiceInfo[] }>;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* List services exposed by a specific app
|
|
229
|
+
* @param appId - App ID to query
|
|
230
|
+
*/
|
|
231
|
+
listServicesByApp(appId: string): Promise<{ services: ServiceInfo[] }>;
|
|
232
|
+
}
|
package/ipc/edenapi.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eden API Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* Interface for shell commands and event subscriptions.
|
|
5
|
+
* Used by both frontend (window.edenAPI) and backend (worker.edenAPI).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { CommandName, CommandArgs, CommandResult } from "../commands";
|
|
9
|
+
import type { EventName, EventData } from "../events";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Eden API - shell commands and event subscriptions
|
|
13
|
+
*/
|
|
14
|
+
export interface EdenAPI {
|
|
15
|
+
/**
|
|
16
|
+
* Execute a shell command with type-safe arguments
|
|
17
|
+
* @param command - The command name (e.g., "process/launch")
|
|
18
|
+
* @param args - Type-safe arguments for the command
|
|
19
|
+
* @returns Promise with the command result
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* await edenAPI.shellCommand("process/launch", {
|
|
24
|
+
* appId: "my-app",
|
|
25
|
+
* bounds: { x: 0, y: 0, width: 800, height: 600 }
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
shellCommand<T extends CommandName>(
|
|
30
|
+
command: T,
|
|
31
|
+
args: CommandArgs<T>
|
|
32
|
+
): Promise<CommandResult<T>>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Subscribe to a system event
|
|
36
|
+
* @param event - The event name
|
|
37
|
+
* @param callback - Callback function receiving typed event data
|
|
38
|
+
*/
|
|
39
|
+
subscribe<T extends EventName>(
|
|
40
|
+
event: T,
|
|
41
|
+
callback: (data: EventData<T>) => void
|
|
42
|
+
): Promise<void>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Unsubscribe from a system event
|
|
46
|
+
*/
|
|
47
|
+
unsubscribe<T extends EventName>(
|
|
48
|
+
event: T,
|
|
49
|
+
callback: (data: EventData<T>) => void
|
|
50
|
+
): void;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Check if an event is supported by the system
|
|
54
|
+
*/
|
|
55
|
+
isEventSupported(event: string): Promise<boolean>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get the launch arguments passed to this app.
|
|
59
|
+
*/
|
|
60
|
+
getLaunchArgs(): string[];
|
|
61
|
+
}
|
package/ipc/index.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edenapp/types",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "TypeScript type definitions for the Eden platform",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"author": "Dariusz Majnert",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"files": [
|
|
9
9
|
"*.d.ts",
|
|
10
|
+
"ipc/",
|
|
10
11
|
"README.md"
|
|
11
12
|
],
|
|
12
13
|
"keywords": [
|