electron-effect-rpc 0.1.1 → 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 CHANGED
@@ -1,23 +1,26 @@
1
1
  # electron-effect-rpc
2
2
 
3
- Typed IPC RPC for Electron, built on Effect and @effect/schema. This library
4
- lets you define a shared contract, generate a typed RPC client in the renderer,
5
- register handlers in the main process, and stream typed events across processes.
3
+ Typed IPC RPC for Electron, built on Effect and @effect/schema.
6
4
 
7
- This package is ESM-only. It targets modern Electron runtimes (current project
8
- uses Electron 38) and assumes ESM-capable bundling.
5
+ The ergonomic default is now a single shared `createIpcKit` configuration that
6
+ you reuse in main, preload, and renderer code. Low-level subpath APIs still
7
+ exist and remain fully supported.
8
+
9
+ This package is ESM-only. It targets modern Electron runtimes and assumes an
10
+ ESM-capable build pipeline.
9
11
 
10
12
  ## Features
11
13
  - Single shared contract for methods and events.
12
- - End-to-end type safety using @effect/schema.
13
- - Promise-based renderer client with typed errors.
14
- - Effect-based main handlers with optional runtime injection.
15
- - Event bus and subscriber for typed renderer events.
16
- - No protocol handshake or versioning; schema decoding is the source of truth.
14
+ - Single shared kit config to eliminate cross-process prefix drift.
15
+ - End-to-end schema validation at IPC boundaries.
16
+ - Promise-based renderer RPC with typed domain errors.
17
+ - Effect-native main handlers with explicit runtime injection.
18
+ - Explicit lifecycle handles and bounded event queue backpressure.
19
+ - Structured diagnostics hooks for decode/protocol/dispatch failures.
17
20
 
18
21
  ## Requirements
19
22
  - Electron with context isolation enabled.
20
- - ESM-capable build pipeline.
23
+ - ESM-capable bundling.
21
24
  - Peer dependencies: `effect`, `@effect/schema`, `electron`.
22
25
 
23
26
  ## Installation
@@ -25,31 +28,12 @@ uses Electron 38) and assumes ESM-capable bundling.
25
28
  bun add electron-effect-rpc effect @effect/schema
26
29
  ```
27
30
 
28
- If you are in a monorepo workspace, add the dependency to the target package
29
- and let the workspace resolver handle the rest.
30
-
31
- ## Core Concepts
32
-
33
- ### Communication directions
34
-
35
- This library provides two communication patterns for Electron IPC:
36
-
37
- | Direction | Mechanism | Pattern | Use case |
38
- |-----------|-----------|---------|----------|
39
- | **Renderer → Main** | RPC methods | Request/response | Fetching data, triggering actions, calling main process APIs |
40
- | **Main → Renderer** | Event bus | Push/broadcast | Progress updates, state changes, background task notifications |
41
-
42
- **RPC methods** are for when the renderer needs something from the main process. The renderer calls a method and awaits a typed response.
43
-
44
- **Events** are for when the main process needs to notify the renderer. The main process emits events whenever it wants, and the renderer subscribes to receive them.
45
-
46
- ### Defining methods and events
47
-
48
- Define methods and events using schema-based helpers:
31
+ ## Quickstart (Kit-First)
49
32
 
33
+ ### 1) Define contract and kit once
50
34
  ```ts
51
35
  import * as S from "@effect/schema/Schema";
52
- import { defineContract, event, rpc } from "electron-effect-rpc/contract";
36
+ import { createIpcKit, defineContract, event, rpc } from "electron-effect-rpc";
53
37
 
54
38
  export const GetAppVersion = rpc(
55
39
  "GetAppVersion",
@@ -66,190 +50,121 @@ export const WorkUnitProgress = event(
66
50
  })
67
51
  );
68
52
 
69
- const methods = [GetAppVersion] as const;
70
- const events = [WorkUnitProgress] as const;
71
-
72
- export const contract = defineContract({ methods, events });
73
- ```
74
-
75
- ### Errors
76
- Error schemas should be `Schema.TaggedError` classes. If a method does not
77
- declare an error schema, it uses `NoError` and the error channel is `never`.
53
+ const contract = defineContract({
54
+ methods: [GetAppVersion] as const,
55
+ events: [WorkUnitProgress] as const,
56
+ });
78
57
 
79
- ```ts
80
- import * as S from "@effect/schema/Schema";
81
- import { rpc } from "electron-effect-rpc/contract";
82
-
83
- export class FileReadError extends S.TaggedError<FileReadError>()("FileReadError", {
84
- message: S.String,
85
- path: S.String,
86
- }) {}
87
-
88
- export const ReadTextFile = rpc(
89
- "ReadTextFile",
90
- S.Struct({ path: S.String }),
91
- S.Struct({ content: S.String }),
92
- FileReadError
93
- );
58
+ export const ipc = createIpcKit({
59
+ contract,
60
+ channelPrefix: { rpc: "rpc/", event: "event/" },
61
+ bridge: { global: "api" },
62
+ decode: { rpc: "envelope", events: "safe" },
63
+ });
94
64
  ```
95
65
 
96
- ## Usage
97
-
98
- ### Main process: register handlers
66
+ ### 2) Main process
99
67
  ```ts
100
68
  import { app, ipcMain } from "electron";
101
69
  import { Effect } from "effect";
102
- import { createRpcServer, createEventBus } from "electron-effect-rpc/main";
103
- import { contract, WorkUnitProgress } from "./contract.ts";
104
-
105
- const implementations = {
106
- GetAppVersion: () => Effect.succeed({ version: app.getVersion() }),
107
- };
108
-
109
- createRpcServer(contract, ipcMain, implementations);
70
+ import * as Runtime from "effect/Runtime";
71
+ import { ipc, WorkUnitProgress } from "./shared-ipc.ts";
110
72
 
111
- const eventBus = createEventBus(contract, {
73
+ const mainRpc = ipc.main({
74
+ ipcMain,
75
+ handlers: {
76
+ GetAppVersion: () => Effect.succeed({ version: app.getVersion() }),
77
+ },
78
+ runtime: Runtime.defaultRuntime,
112
79
  getWindow: () => mainWindow,
113
80
  });
114
81
 
115
- eventBus.emit(WorkUnitProgress, {
82
+ mainRpc.start();
83
+
84
+ void mainRpc.emit(WorkUnitProgress, {
116
85
  requestId: "req-1",
117
- chunk: "working...",
86
+ chunk: "starting",
118
87
  done: false,
119
88
  });
120
- ```
121
89
 
122
- If your handlers require services in the Effect environment, provide a runtime:
123
-
124
- ```ts
125
- import * as Runtime from "effect/Runtime";
126
- import { createRpcServer } from "electron-effect-rpc/main";
127
- import { contract } from "./contract.ts";
128
-
129
- createRpcServer(contract, ipcMain, implementations, {
130
- runtime: Runtime.defaultRuntime,
131
- });
90
+ // Effect-native alternative:
91
+ // void Effect.runPromise(mainRpc.publish(WorkUnitProgress, {...}));
132
92
  ```
133
93
 
134
- ### Preload: expose bridge globals
94
+ ### 3) Preload
135
95
  ```ts
136
- import { exposeRpcBridge } from "electron-effect-rpc/preload";
96
+ import { ipc } from "./shared-ipc.ts";
137
97
 
138
- exposeRpcBridge();
98
+ ipc.preload().expose();
139
99
  ```
140
100
 
141
- Defaults:
142
- - RPC global: `window.rpc.invoke(method, payload)`
143
- - Events global: `window.events.subscribe(name, handler)`
144
- - Channel prefix: `rpc/` and `event/`
145
-
146
- You can override globals and prefixes:
147
- ```ts
148
- exposeRpcBridge({
149
- rpcGlobal: "rpcApi",
150
- eventsGlobal: "rpcEvents",
151
- channelPrefix: { rpc: "rpc/", event: "events/" },
152
- });
153
- ```
101
+ This exposes one global by default: `window.api`.
154
102
 
155
- ### Renderer: create client and subscriber
103
+ ### 4) Renderer
156
104
  ```ts
157
- import { createRpcClient, createEventSubscriber } from "electron-effect-rpc/renderer";
158
- import { contract, WorkUnitProgress } from "./contract.ts";
159
-
160
- const client = createRpcClient(contract, { invoke: window.rpc.invoke });
161
- const events = createEventSubscriber(contract, { subscribe: window.events.subscribe });
105
+ import { ipc, WorkUnitProgress } from "./shared-ipc.ts";
162
106
 
107
+ const { client, events } = ipc.renderer(window.api);
163
108
  const { version } = await client.GetAppVersion();
164
109
 
165
- events.subscribe(WorkUnitProgress, (payload) => {
110
+ const unsubscribe = events.subscribe(WorkUnitProgress, (payload) => {
166
111
  console.log(payload.chunk);
167
112
  });
168
- ```
169
113
 
170
- ### Window type augmentation
171
- If you expose globals in preload, add a local `globals.d.ts`:
114
+ // later
115
+ unsubscribe();
116
+ events.dispose();
117
+ ```
172
118
 
119
+ ### 5) Window typing
173
120
  ```ts
174
121
  declare global {
175
122
  interface Window {
176
- rpc: {
123
+ api: {
177
124
  invoke: (method: string, payload: unknown) => Promise<unknown>;
178
- };
179
- events: {
180
125
  subscribe: (name: string, handler: (payload: unknown) => void) => () => void;
181
126
  };
182
127
  }
183
128
  }
184
129
  ```
185
130
 
186
- ## Testing
187
-
188
- ### Renderer client tests
189
- Use the testing helpers to stub invoke behavior:
190
-
191
- ```ts
192
- import { createRpcClient } from "electron-effect-rpc/renderer";
193
- import { createInvokeStub } from "electron-effect-rpc/testing";
194
- import { contract } from "./contract.ts";
195
-
196
- const invoke = createInvokeStub(async (method, payload) => {
197
- // return encoded Exit values from your handler logic
198
- return payload;
199
- });
200
-
201
- const client = createRpcClient(contract, { invoke });
202
- await client.GetAppVersion();
203
-
204
- expect(invoke.invocations).toEqual([
205
- { method: "GetAppVersion", payload: {} },
206
- ]);
207
- ```
208
-
209
- ### Main process tests
210
- You can stub `IpcMainLike` and collect registered handlers:
211
-
212
- ```ts
213
- import { createRpcServer } from "electron-effect-rpc/main";
214
- import type { IpcMainLike } from "electron-effect-rpc/types";
215
- import { contract } from "./contract.ts";
216
-
217
- const handlers = new Map<string, (event: unknown, payload: unknown) => unknown>();
218
- const ipcMainStub: IpcMainLike = {
219
- handle: (channel, handler) => {
220
- handlers.set(channel, handler);
221
- },
222
- };
223
-
224
- createRpcServer(contract, ipcMainStub, implementations);
225
- ```
131
+ ## Error Model
226
132
 
227
- ## Error Handling
228
- - If a handler fails with a typed domain error, the renderer client rejects
229
- with that error instance.
230
- - If a handler dies or throws a defect, the renderer client rejects with
231
- `RpcDefectError`.
133
+ Domain failures are modeled with tagged error schemas and are re-thrown in the
134
+ renderer as those same error classes. Unexpected failures, transport defects,
135
+ and protocol mismatches are surfaced as `RpcDefectError`.
232
136
 
233
- ## API Surface
137
+ ## Low-Level APIs (Still Supported)
234
138
 
235
- Entry points:
139
+ If you need direct control, keep using subpath entry points:
236
140
  - `electron-effect-rpc/contract`
237
- - `rpc`, `event`, `defineContract`, `exitSchemaFor`, `SchemaNoContext`, `NoError`
238
- - `electron-effect-rpc/types`
239
- - Type aliases such as `Implementations`, `RpcClient`, `RpcEventBus`, `IpcMainLike`
240
141
  - `electron-effect-rpc/main`
241
- - `createRpcServer`, `createEventBus`
242
142
  - `electron-effect-rpc/renderer`
243
- - `createRpcClient`, `createEventSubscriber`, `RpcDefectError`
244
143
  - `electron-effect-rpc/preload`
245
- - `exposeRpcBridge`
144
+ - `electron-effect-rpc/types`
246
145
  - `electron-effect-rpc/testing`
247
- - `createInvokeStub`, `createDeferred`
146
+
147
+ ## Root API Surface
148
+
149
+ The root entry point exports:
150
+ - `createIpcKit`
151
+ - `rpc`, `event`, `defineContract`, `NoError`
152
+ - Types: `IpcKit`, `IpcKitOptions`, `IpcMainHandle`, `IpcBridge`, `IpcBridgeGlobal`
153
+
154
+ Low-level factories like `createRpcClient` remain subpath-only by design.
155
+
156
+ ## Tutorials
157
+
158
+ For deeper walkthroughs and production guidance:
159
+ - [Tutorial Index](./docs/tutorials/README.md)
160
+ - [First RPC: Main + Preload + Renderer](./docs/tutorials/01-first-rpc.md)
161
+ - [Typed Errors, Defects, and Diagnostics](./docs/tutorials/02-typed-errors-defects-diagnostics.md)
162
+ - [Events, Lifecycle, and Backpressure](./docs/tutorials/03-events-lifecycle-backpressure.md)
248
163
 
249
164
  ## Conventions
250
165
  - Relative imports use `.ts` extensions.
251
166
  - Package imports are extensionless.
252
- - No `index.ts` barrel files.
167
+ - No `index.ts` barrel files in subpath modules.
253
168
 
254
169
  ## License
255
170
  MIT
@@ -2,7 +2,8 @@ import * as S from "@effect/schema/Schema";
2
2
  export type SchemaNoContext = S.Schema.AnyNoContext;
3
3
  export declare const NoError: typeof S.Never;
4
4
  export type NoError = typeof NoError;
5
- export type ErrorSchema = SchemaNoContext | S.Schema<never, never, never>;
5
+ export type ErrorSchema = SchemaNoContext | NoError;
6
+ export declare function isNoErrorSchema(schema: ErrorSchema): schema is NoError;
6
7
  export interface RpcMethod<Name extends string, Req extends SchemaNoContext, Res extends SchemaNoContext, Err extends ErrorSchema = NoError> {
7
8
  readonly name: Name;
8
9
  readonly req: Req;
@@ -33,8 +34,8 @@ export interface RpcContract<Methods extends ReadonlyArray<AnyMethod>, Events ex
33
34
  readonly methods: Methods;
34
35
  readonly events: Events;
35
36
  }
36
- export declare const defineContract: <const Methods extends ReadonlyArray<AnyMethod>, const Events extends ReadonlyArray<AnyEvent>>(input: {
37
+ export declare function defineContract<const Methods extends ReadonlyArray<AnyMethod>, const Events extends ReadonlyArray<AnyEvent>>(input: {
37
38
  readonly methods: Methods;
38
39
  readonly events: Events;
39
- }) => RpcContract<Methods, Events>;
40
+ }): RpcContract<Methods, Events>;
40
41
  //# sourceMappingURL=contract.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../src/contract.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,uBAAuB,CAAC;AAE3C,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;AAEpD,eAAO,MAAM,OAAO,gBAAU,CAAC;AAC/B,MAAM,MAAM,OAAO,GAAG,OAAO,OAAO,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAE1E,MAAM,WAAW,SAAS,CACxB,IAAI,SAAS,MAAM,EACnB,GAAG,SAAS,eAAe,EAC3B,GAAG,SAAS,eAAe,EAC3B,GAAG,SAAS,WAAW,GAAG,OAAO;IAEjC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;CACnB;AAED,wBAAgB,GAAG,CACjB,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,GAAG,SAAS,eAAe,EAC3B,GAAG,SAAS,eAAe,EAC3B,GAAG,SAAS,WAAW,EACvB,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAE5E,wBAAgB,GAAG,CACjB,KAAK,CAAC,IAAI,SAAS,MAAM,EACzB,GAAG,SAAS,eAAe,EAC3B,GAAG,SAAS,eAAe,EAC3B,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,G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AAM,SAAS,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAErE,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAEpE,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,QAAQ,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;AAE9E,gEAAgE;AAChE,MAAM,MAAM,aAAa,CACvB,OAAO,SAAS,SAAS,SAAS,EAAE,EACpC,IAAI,SAAS,MAAM,IACjB,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC;AAEtD,MAAM,WAAW,WAAW,CAC1B,OAAO,SAAS,aAAa,CAAC,SAAS,CAAC,EACxC,MAAM,SAAS,aAAa,CAAC,QAAQ,CAAC;IAEtC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAiBD,wBAAgB,cAAc,CAC5B,KAAK,CAAC,OAAO,SAAS,aAAa,CAAC,SAAS,CAAC,EAC9C,KAAK,CAAC,MAAM,SAAS,aAAa,CAAC,QAAQ,CAAC,EAE5C,KAAK,EAAE;IACL,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,GACA,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CA0B9B"}
package/dist/contract.js CHANGED
@@ -1,5 +1,8 @@
1
1
  import * as S from "@effect/schema/Schema";
2
2
  export const NoError = S.Never;
3
+ export function isNoErrorSchema(schema) {
4
+ return schema === NoError;
5
+ }
3
6
  export function rpc(name, req, res, err = NoError) {
4
7
  return { name, req, res, err };
5
8
  }
@@ -11,7 +14,7 @@ export const exitSchemaFor = (method) => S.Exit({
11
14
  failure: method.err,
12
15
  defect: S.Defect,
13
16
  });
14
- const collectDuplicates = (names) => {
17
+ function collectDuplicates(names) {
15
18
  const counts = new Map();
16
19
  const duplicates = [];
17
20
  for (const name of names) {
@@ -22,8 +25,8 @@ const collectDuplicates = (names) => {
22
25
  }
23
26
  }
24
27
  return duplicates;
25
- };
26
- export const defineContract = (input) => {
28
+ }
29
+ export function defineContract(input) {
27
30
  const { methods, events } = input;
28
31
  if (!Array.isArray(methods)) {
29
32
  throw new Error("RPC contract methods must be an array.");
@@ -40,4 +43,4 @@ export const defineContract = (input) => {
40
43
  throw new Error(`Duplicate RPC event name(s): ${duplicateEvents.join(", ")}`);
41
44
  }
42
45
  return input;
43
- };
46
+ }
@@ -0,0 +1,4 @@
1
+ export { createIpcKit } from "./kit.ts";
2
+ export { defineContract, event, NoError, rpc } from "./contract.ts";
3
+ export type { IpcBridge, IpcBridgeGlobal, IpcKit, IpcKitOptions, IpcMainHandle, } from "./kit.ts";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpE,YAAY,EACV,SAAS,EACT,eAAe,EACf,MAAM,EACN,aAAa,EACb,aAAa,GACd,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { createIpcKit } from "./kit.js";
2
+ export { defineContract, event, NoError, rpc } from "./contract.js";
package/dist/kit.d.ts ADDED
@@ -0,0 +1,71 @@
1
+ import { Effect } from "effect";
2
+ import type * as Runtime from "effect/Runtime";
3
+ import type { AnyEvent, AnyMethod, RpcContract, RpcEventPayload } from "./contract.ts";
4
+ import { type ChannelPrefix, type EventDecodeMode, type EventPublisherDiagnostics, type EventSubscribe, type EventSubscriber, type IpcMainLike, type Implementations, type RendererWindowLike, type RpcClient, type RpcEndpoint, type RpcEndpointDiagnostics, type RpcEventPublisher, type RpcInvoke, type RpcResponseDecodeMode } from "./types.ts";
5
+ export type IpcBridge = {
6
+ readonly invoke: RpcInvoke;
7
+ readonly subscribe: EventSubscribe;
8
+ };
9
+ export type IpcBridgeGlobal<Name extends string = "api"> = {
10
+ readonly [K in Name]: IpcBridge;
11
+ };
12
+ export type IpcKitOptions<C extends RpcContract<readonly AnyMethod[], readonly AnyEvent[]>> = {
13
+ readonly contract: C;
14
+ readonly channelPrefix?: ChannelPrefix;
15
+ readonly bridge?: {
16
+ readonly global?: string;
17
+ };
18
+ readonly decode?: {
19
+ readonly rpc?: RpcResponseDecodeMode;
20
+ readonly events?: EventDecodeMode;
21
+ };
22
+ };
23
+ type IpcMainOptions<C extends RpcContract<readonly AnyMethod[], readonly AnyEvent[]>, R> = {
24
+ readonly ipcMain: IpcMainLike;
25
+ readonly handlers: Implementations<C, R>;
26
+ readonly runtime: Runtime.Runtime<R>;
27
+ readonly getWindow: () => RendererWindowLike | null;
28
+ readonly maxQueueSize?: number;
29
+ readonly diagnostics?: {
30
+ readonly rpc?: RpcEndpointDiagnostics;
31
+ readonly events?: EventPublisherDiagnostics;
32
+ };
33
+ };
34
+ export type IpcMainHandle<C extends RpcContract<readonly AnyMethod[], readonly AnyEvent[]>> = {
35
+ readonly endpoint: RpcEndpoint;
36
+ readonly publisher: RpcEventPublisher<C>;
37
+ readonly start: () => void;
38
+ readonly stop: () => void;
39
+ readonly dispose: () => void;
40
+ readonly isRunning: () => boolean;
41
+ readonly publish: <E extends C["events"][number]>(event: E, payload: RpcEventPayload<E>) => Effect.Effect<void, never>;
42
+ readonly emit: <E extends C["events"][number]>(event: E, payload: RpcEventPayload<E>) => Promise<void>;
43
+ readonly stats: () => {
44
+ readonly queued: number;
45
+ readonly dropped: number;
46
+ };
47
+ };
48
+ export type IpcKit<C extends RpcContract<readonly AnyMethod[], readonly AnyEvent[]>> = {
49
+ readonly contract: C;
50
+ readonly config: {
51
+ readonly channelPrefix: ChannelPrefix;
52
+ readonly bridgeGlobal: string;
53
+ readonly rpcDecodeMode: RpcResponseDecodeMode;
54
+ readonly eventDecodeMode: EventDecodeMode;
55
+ };
56
+ readonly main: <R>(options: IpcMainOptions<C, R>) => IpcMainHandle<C>;
57
+ readonly preload: (options?: {
58
+ readonly global?: string;
59
+ }) => {
60
+ readonly global: string;
61
+ readonly bridge: IpcBridge;
62
+ readonly expose: () => void;
63
+ };
64
+ readonly renderer: (bridge: IpcBridge) => {
65
+ readonly client: RpcClient<C>;
66
+ readonly events: EventSubscriber<C>;
67
+ };
68
+ };
69
+ export declare function createIpcKit<const Methods extends ReadonlyArray<AnyMethod>, const Events extends ReadonlyArray<AnyEvent>>(options: IpcKitOptions<RpcContract<Methods, Events>>): IpcKit<RpcContract<Methods, Events>>;
70
+ export {};
71
+ //# sourceMappingURL=kit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kit.d.ts","sourceRoot":"","sources":["../src/kit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,KAAK,OAAO,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIvF,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,SAAS,EAC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IpcBridge, createBridgeAdapters } from "./preload.js";
4
+ import { createEventSubscriber, createRpcClient } from "./renderer.js";
5
+ import { defaultChannelPrefix, } from "./types.js";
6
+ export function createIpcKit(options) {
7
+ const contract = options.contract;
8
+ const channelPrefix = options.channelPrefix
9
+ ? { ...options.channelPrefix }
10
+ : { ...defaultChannelPrefix };
11
+ const bridgeGlobal = options.bridge?.global ?? "api";
12
+ const rpcDecodeMode = options.decode?.rpc ?? "envelope";
13
+ const eventDecodeMode = options.decode?.events ?? "safe";
14
+ const main = (mainOptions) => {
15
+ const endpoint = createRpcEndpoint(contract, mainOptions.ipcMain, mainOptions.handlers, {
16
+ runtime: mainOptions.runtime,
17
+ channelPrefix,
18
+ diagnostics: mainOptions.diagnostics?.rpc,
19
+ });
20
+ const publisher = createEventPublisher(contract, {
21
+ getWindow: mainOptions.getWindow,
22
+ maxQueueSize: mainOptions.maxQueueSize,
23
+ channelPrefix,
24
+ diagnostics: mainOptions.diagnostics?.events,
25
+ });
26
+ function start() {
27
+ endpoint.start();
28
+ try {
29
+ publisher.start();
30
+ }
31
+ catch (cause) {
32
+ try {
33
+ endpoint.stop();
34
+ }
35
+ catch {
36
+ // Best effort rollback.
37
+ }
38
+ throw cause;
39
+ }
40
+ }
41
+ function stop() {
42
+ let firstError;
43
+ try {
44
+ publisher.stop();
45
+ }
46
+ catch (cause) {
47
+ firstError ??= cause;
48
+ }
49
+ try {
50
+ endpoint.stop();
51
+ }
52
+ catch (cause) {
53
+ firstError ??= cause;
54
+ }
55
+ if (firstError !== undefined) {
56
+ throw firstError;
57
+ }
58
+ }
59
+ function dispose() {
60
+ let firstError;
61
+ try {
62
+ publisher.dispose();
63
+ }
64
+ catch (cause) {
65
+ firstError ??= cause;
66
+ }
67
+ try {
68
+ endpoint.dispose();
69
+ }
70
+ catch (cause) {
71
+ firstError ??= cause;
72
+ }
73
+ if (firstError !== undefined) {
74
+ throw firstError;
75
+ }
76
+ }
77
+ function isRunning() {
78
+ return endpoint.isRunning() && publisher.isRunning();
79
+ }
80
+ function publish(event, payload) {
81
+ return publisher.publish(event, payload);
82
+ }
83
+ function emit(event, payload) {
84
+ return Effect.runPromise(publisher.publish(event, payload));
85
+ }
86
+ return {
87
+ endpoint,
88
+ publisher,
89
+ start,
90
+ stop,
91
+ dispose,
92
+ isRunning,
93
+ publish,
94
+ emit,
95
+ stats: publisher.stats,
96
+ };
97
+ };
98
+ const preload = (preloadOptions) => {
99
+ const global = preloadOptions?.global ?? bridgeGlobal;
100
+ const bridge = createBridgeAdapters({
101
+ channelPrefix,
102
+ });
103
+ return {
104
+ global,
105
+ bridge,
106
+ expose: () => {
107
+ exposeIpcBridge({
108
+ global,
109
+ channelPrefix,
110
+ });
111
+ },
112
+ };
113
+ };
114
+ const renderer = (bridge) => {
115
+ return {
116
+ client: createRpcClient(contract, {
117
+ invoke: bridge.invoke,
118
+ rpcDecodeMode,
119
+ }),
120
+ events: createEventSubscriber(contract, {
121
+ subscribe: bridge.subscribe,
122
+ decodeMode: eventDecodeMode,
123
+ }),
124
+ };
125
+ };
126
+ return {
127
+ contract,
128
+ config: {
129
+ channelPrefix,
130
+ bridgeGlobal,
131
+ rpcDecodeMode,
132
+ eventDecodeMode,
133
+ },
134
+ main,
135
+ preload,
136
+ renderer,
137
+ };
138
+ }
package/dist/main.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { type RpcContract } from "./contract.ts";
2
- import { type AnyEvent, type AnyMethod, type EventBusOptions, type Implementations, type IpcMainLike, type RpcEventBus, type RpcServerOptions } from "./types.ts";
3
- export declare const createRpcServer: <const Methods extends ReadonlyArray<AnyMethod>, const Events extends ReadonlyArray<AnyEvent>, R = never>(contract: RpcContract<Methods, Events>, ipc: IpcMainLike, implementations: Implementations<RpcContract<Methods, Events>, R>, options?: RpcServerOptions<R>) => void;
4
- export declare const createEventBus: <const Methods extends ReadonlyArray<AnyMethod>, const Events extends ReadonlyArray<AnyEvent>>(_contract: RpcContract<Methods, Events>, options: EventBusOptions) => RpcEventBus<RpcContract<Methods, Events>>;
1
+ import type { RpcContract } from "./contract.ts";
2
+ import { type AnyEvent, type AnyMethod, type EventPublisherOptions, type Implementations, type IpcMainLike, type RpcEndpoint, type RpcEndpointOptions, type RpcEventPublisher } from "./types.ts";
3
+ export declare function createRpcEndpoint<const Methods extends ReadonlyArray<AnyMethod>, const Events extends ReadonlyArray<AnyEvent>, R = never>(contract: RpcContract<Methods, Events>, ipc: IpcMainLike, implementations: Implementations<RpcContract<Methods, Events>, R>, options: RpcEndpointOptions<R>): RpcEndpoint;
4
+ export declare function createEventPublisher<const Methods extends ReadonlyArray<AnyMethod>, const Events extends ReadonlyArray<AnyEvent>>(_contract: RpcContract<Methods, Events>, options: EventPublisherOptions): RpcEventPublisher<RpcContract<Methods, Events>>;
5
5
  //# sourceMappingURL=main.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,WAAW,EAKjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACtB,MAAM,YAAY,CAAC;AAKpB,eAAO,MAAM,eAAe,GAC1B,KAAK,CAAC,OAAO,SAAS,aAAa,CAAC,SAAS,CAAC,EAC9C,KAAK,CAAC,MAAM,SAAS,aAAa,CAAC,QAAQ,CAAC,EAC5C,CAAC,GAAG,KAAK,EAET,UAAU,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,EACtC,KAAK,WAAW,EAChB,iBAAiB,eAAe,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,EACjE,UAAU,gBAAgB,CAAC,CAAC,CAAC,KAC5B,IA6CF,CAAC;AAqCF,eAAO,MAAM,cAAc,GACzB,KAAK,CAAC,OAAO,SAAS,aAA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