@delight-rpc/electron 6.0.3 → 6.0.5
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 +38 -14
- package/lib/client.d.ts +23 -23
- package/lib/client.js +139 -139
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/server.d.ts +14 -14
- package/lib/server.js +38 -38
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -7,14 +7,20 @@ yarn add @delight-rpc/electron
|
|
|
7
7
|
```
|
|
8
8
|
|
|
9
9
|
## Usage
|
|
10
|
+
If your application sends RPC requests immediately after creating the RPC client,
|
|
11
|
+
you need to create the RPC server as soon as possible,
|
|
12
|
+
which means your corresponding code needs to be as **synchronized** as possible.
|
|
13
|
+
|
|
10
14
|
### Main as Client, Renderer as Server
|
|
15
|
+
#### api.d.ts
|
|
11
16
|
```ts
|
|
12
|
-
// api.d.ts
|
|
13
17
|
interface IAPI {
|
|
14
18
|
echo(message: string): string
|
|
15
19
|
}
|
|
20
|
+
```
|
|
16
21
|
|
|
17
|
-
|
|
22
|
+
#### main.js
|
|
23
|
+
```ts
|
|
18
24
|
import { app, ipcMain } from 'electron'
|
|
19
25
|
import { createClientInMain } from '@delight-rpc/electron'
|
|
20
26
|
|
|
@@ -32,8 +38,10 @@ const window = new BrowserWindow({
|
|
|
32
38
|
webPreferences: { preload: 'preload.js' }
|
|
33
39
|
})
|
|
34
40
|
window.loadFile('renderer.html')
|
|
41
|
+
```
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
#### preload.js
|
|
44
|
+
```ts
|
|
37
45
|
import { ipcRenderer } from 'electron'
|
|
38
46
|
|
|
39
47
|
window.addEventListener('message', event => {
|
|
@@ -42,8 +50,10 @@ window.addEventListener('message', event => {
|
|
|
42
50
|
ipcRenderer.postMessage('message-port', null, [port])
|
|
43
51
|
}
|
|
44
52
|
})
|
|
53
|
+
```
|
|
45
54
|
|
|
46
|
-
|
|
55
|
+
#### renderer.js
|
|
56
|
+
```ts
|
|
47
57
|
import { createServerInRenderer } from '@delight-rpc/electron'
|
|
48
58
|
|
|
49
59
|
const api: IAPI = {
|
|
@@ -62,13 +72,15 @@ window.postMessage('message-port', '*', [channel.port2])
|
|
|
62
72
|
```
|
|
63
73
|
|
|
64
74
|
### Renderer as Client, Main as Server
|
|
75
|
+
#### api.d.ts
|
|
65
76
|
```ts
|
|
66
|
-
// api.d.ts
|
|
67
77
|
interface IAPI {
|
|
68
78
|
echo(message: string): string
|
|
69
79
|
}
|
|
80
|
+
```
|
|
70
81
|
|
|
71
|
-
|
|
82
|
+
#### main.js
|
|
83
|
+
```ts
|
|
72
84
|
import { app, ipcMain } from 'electron'
|
|
73
85
|
import { createClientInMain } from '@delight-rpc/electron'
|
|
74
86
|
|
|
@@ -80,7 +92,7 @@ const api: IAPI = {
|
|
|
80
92
|
|
|
81
93
|
await app.whenReady()
|
|
82
94
|
|
|
83
|
-
ipcMain.on('message-port',
|
|
95
|
+
ipcMain.on('message-port', event => {
|
|
84
96
|
const [port] = event.ports
|
|
85
97
|
|
|
86
98
|
port.start()
|
|
@@ -91,8 +103,10 @@ const window = new BrowserWindow({
|
|
|
91
103
|
webPreferences: { preload: 'preload.js' }
|
|
92
104
|
})
|
|
93
105
|
window.loadFile('renderer.html')
|
|
106
|
+
```
|
|
94
107
|
|
|
95
|
-
|
|
108
|
+
#### preload.js
|
|
109
|
+
```ts
|
|
96
110
|
import { ipcRenderer } from 'electron'
|
|
97
111
|
|
|
98
112
|
window.addEventListener('message', event => {
|
|
@@ -101,8 +115,10 @@ window.addEventListener('message', event => {
|
|
|
101
115
|
ipcRenderer.postMessage('message-port', null, [port])
|
|
102
116
|
}
|
|
103
117
|
})
|
|
118
|
+
```
|
|
104
119
|
|
|
105
|
-
|
|
120
|
+
#### renderer.js
|
|
121
|
+
```ts
|
|
106
122
|
import { createClientInRenderer } from '@delight-rpc/electron'
|
|
107
123
|
|
|
108
124
|
// create the MessageChannel in the renderer,
|
|
@@ -116,13 +132,15 @@ await client.echo('hello world')
|
|
|
116
132
|
```
|
|
117
133
|
|
|
118
134
|
### Renderer as Client, Renderer as Server
|
|
135
|
+
#### api.d.ts
|
|
119
136
|
```ts
|
|
120
|
-
// api.d.ts
|
|
121
137
|
interface IAPI {
|
|
122
138
|
echo(message: string): string
|
|
123
139
|
}
|
|
140
|
+
```
|
|
124
141
|
|
|
125
|
-
|
|
142
|
+
#### main.js
|
|
143
|
+
```ts
|
|
126
144
|
import { app, ipcMain, MessageChannelMain } from 'electron'
|
|
127
145
|
|
|
128
146
|
await app.whenReady()
|
|
@@ -140,8 +158,10 @@ windowB.loadFile('renderer-b.html')
|
|
|
140
158
|
const channel = new MessageChannelMain()
|
|
141
159
|
windowA.webContents.postMessage('message-port', null, [channel.port1])
|
|
142
160
|
windowB.webContents.postMessage('message-port', null, [channel.port2])
|
|
161
|
+
```
|
|
143
162
|
|
|
144
|
-
|
|
163
|
+
#### preload.ts
|
|
164
|
+
```ts
|
|
145
165
|
import { ipcRenderer, contextBridge } from 'electron'
|
|
146
166
|
import { Deferred } from 'extra-promise'
|
|
147
167
|
|
|
@@ -155,8 +175,10 @@ ipcRenderer.on('message-port', event => {
|
|
|
155
175
|
await ready
|
|
156
176
|
window.postMessage('message-port', '*', [port])
|
|
157
177
|
})
|
|
178
|
+
```
|
|
158
179
|
|
|
159
|
-
|
|
180
|
+
#### renderer-a.js
|
|
181
|
+
```ts
|
|
160
182
|
import { createServerInRenderer } from '@delight-rpc/electron'
|
|
161
183
|
|
|
162
184
|
const api: IAPI = {
|
|
@@ -175,8 +197,10 @@ window.addEventListener('message', async event => {
|
|
|
175
197
|
})
|
|
176
198
|
|
|
177
199
|
window.ready()
|
|
200
|
+
```
|
|
178
201
|
|
|
179
|
-
|
|
202
|
+
#### renderer-b.js
|
|
203
|
+
```ts
|
|
180
204
|
import { createClientInRenderer } from '@delight-rpc/electron'
|
|
181
205
|
|
|
182
206
|
window.addEventListener('message', async event => {
|
package/lib/client.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import * as DelightRPC from 'delight-rpc';
|
|
2
|
-
import Electron from 'electron';
|
|
3
|
-
import { CustomError } from '@blackglory/errors';
|
|
4
|
-
export declare function createClientInMain<IAPI extends object>(port: Electron.MessagePortMain, { parameterValidators, expectedVersion, channel }?: {
|
|
5
|
-
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
6
|
-
expectedVersion?: string;
|
|
7
|
-
channel?: string;
|
|
8
|
-
}): [client: DelightRPC.ClientProxy<IAPI>, close: () => void];
|
|
9
|
-
export declare function createClientInRenderer<IAPI extends object>(port: MessagePort, { parameterValidators, expectedVersion, channel }?: {
|
|
10
|
-
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
11
|
-
expectedVersion?: string;
|
|
12
|
-
channel?: string;
|
|
13
|
-
}): [client: DelightRPC.ClientProxy<IAPI>, close: () => void];
|
|
14
|
-
export declare function createBatchClientInMain<DataType>(port: Electron.MessagePortMain, { expectedVersion, channel }?: {
|
|
15
|
-
expectedVersion?: string;
|
|
16
|
-
channel?: string;
|
|
17
|
-
}): [client: DelightRPC.BatchClient<DataType>, close: () => void];
|
|
18
|
-
export declare function createBatchClientInRenderer<DataType>(port: MessagePort, { expectedVersion, channel }?: {
|
|
19
|
-
expectedVersion?: string;
|
|
20
|
-
channel?: string;
|
|
21
|
-
}): [client: DelightRPC.BatchClient<DataType>, close: () => void];
|
|
22
|
-
export declare class ClientClosed extends CustomError {
|
|
23
|
-
}
|
|
1
|
+
import * as DelightRPC from 'delight-rpc';
|
|
2
|
+
import Electron from 'electron';
|
|
3
|
+
import { CustomError } from '@blackglory/errors';
|
|
4
|
+
export declare function createClientInMain<IAPI extends object>(port: Electron.MessagePortMain, { parameterValidators, expectedVersion, channel }?: {
|
|
5
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
6
|
+
expectedVersion?: string;
|
|
7
|
+
channel?: string;
|
|
8
|
+
}): [client: DelightRPC.ClientProxy<IAPI>, close: () => void];
|
|
9
|
+
export declare function createClientInRenderer<IAPI extends object>(port: MessagePort, { parameterValidators, expectedVersion, channel }?: {
|
|
10
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
11
|
+
expectedVersion?: string;
|
|
12
|
+
channel?: string;
|
|
13
|
+
}): [client: DelightRPC.ClientProxy<IAPI>, close: () => void];
|
|
14
|
+
export declare function createBatchClientInMain<DataType>(port: Electron.MessagePortMain, { expectedVersion, channel }?: {
|
|
15
|
+
expectedVersion?: string;
|
|
16
|
+
channel?: string;
|
|
17
|
+
}): [client: DelightRPC.BatchClient<DataType>, close: () => void];
|
|
18
|
+
export declare function createBatchClientInRenderer<DataType>(port: MessagePort, { expectedVersion, channel }?: {
|
|
19
|
+
expectedVersion?: string;
|
|
20
|
+
channel?: string;
|
|
21
|
+
}): [client: DelightRPC.BatchClient<DataType>, close: () => void];
|
|
22
|
+
export declare class ClientClosed extends CustomError {
|
|
23
|
+
}
|
package/lib/client.js
CHANGED
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
import * as DelightRPC from 'delight-rpc';
|
|
2
|
-
import { Deferred } from 'extra-promise';
|
|
3
|
-
import { CustomError } from '@blackglory/errors';
|
|
4
|
-
export function createClientInMain(port, { parameterValidators, expectedVersion, channel } = {}) {
|
|
5
|
-
const pendings = {};
|
|
6
|
-
port.addListener('message', handler);
|
|
7
|
-
const client = DelightRPC.createClient(async function send(request) {
|
|
8
|
-
const res = new Deferred();
|
|
9
|
-
pendings[request.id] = res;
|
|
10
|
-
try {
|
|
11
|
-
port.postMessage(request);
|
|
12
|
-
return await res;
|
|
13
|
-
}
|
|
14
|
-
finally {
|
|
15
|
-
delete pendings[request.id];
|
|
16
|
-
}
|
|
17
|
-
}, {
|
|
18
|
-
parameterValidators,
|
|
19
|
-
expectedVersion,
|
|
20
|
-
channel
|
|
21
|
-
});
|
|
22
|
-
return [client, close];
|
|
23
|
-
function close() {
|
|
24
|
-
port.removeListener('message', handler);
|
|
25
|
-
for (const [key, deferred] of Object.entries(pendings)) {
|
|
26
|
-
deferred.reject(new ClientClosed());
|
|
27
|
-
delete pendings[key];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function handler(event) {
|
|
31
|
-
var _a;
|
|
32
|
-
const res = event.data;
|
|
33
|
-
if (DelightRPC.isResult(res) || DelightRPC.isError(res)) {
|
|
34
|
-
(_a = pendings[res.id]) === null || _a === void 0 ? void 0 : _a.resolve(res);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export function createClientInRenderer(port, { parameterValidators, expectedVersion, channel } = {}) {
|
|
39
|
-
const pendings = {};
|
|
40
|
-
port.addEventListener('message', handler);
|
|
41
|
-
const client = DelightRPC.createClient(async function send(request) {
|
|
42
|
-
const res = new Deferred();
|
|
43
|
-
pendings[request.id] = res;
|
|
44
|
-
try {
|
|
45
|
-
port.postMessage(request);
|
|
46
|
-
return await res;
|
|
47
|
-
}
|
|
48
|
-
finally {
|
|
49
|
-
delete pendings[request.id];
|
|
50
|
-
}
|
|
51
|
-
}, {
|
|
52
|
-
parameterValidators,
|
|
53
|
-
expectedVersion,
|
|
54
|
-
channel
|
|
55
|
-
});
|
|
56
|
-
return [client, close];
|
|
57
|
-
function close() {
|
|
58
|
-
port.removeEventListener('message', handler);
|
|
59
|
-
for (const [key, deferred] of Object.entries(pendings)) {
|
|
60
|
-
deferred.reject(new ClientClosed());
|
|
61
|
-
delete pendings[key];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function handler(event) {
|
|
65
|
-
var _a;
|
|
66
|
-
const res = event.data;
|
|
67
|
-
if (DelightRPC.isResult(res) || DelightRPC.isError(res)) {
|
|
68
|
-
(_a = pendings[res.id]) === null || _a === void 0 ? void 0 : _a.resolve(res);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
export function createBatchClientInMain(port, { expectedVersion, channel } = {}) {
|
|
73
|
-
const pendings = {};
|
|
74
|
-
port.addListener('message', handler);
|
|
75
|
-
const client = new DelightRPC.BatchClient(async function send(request) {
|
|
76
|
-
const res = new Deferred();
|
|
77
|
-
pendings[request.id] = res;
|
|
78
|
-
try {
|
|
79
|
-
port.postMessage(request);
|
|
80
|
-
return await res;
|
|
81
|
-
}
|
|
82
|
-
finally {
|
|
83
|
-
delete pendings[request.id];
|
|
84
|
-
}
|
|
85
|
-
}, {
|
|
86
|
-
expectedVersion,
|
|
87
|
-
channel
|
|
88
|
-
});
|
|
89
|
-
return [client, close];
|
|
90
|
-
function close() {
|
|
91
|
-
port.removeListener('message', handler);
|
|
92
|
-
for (const [key, deferred] of Object.entries(pendings)) {
|
|
93
|
-
deferred.reject(new ClientClosed());
|
|
94
|
-
delete pendings[key];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
function handler(event) {
|
|
98
|
-
var _a;
|
|
99
|
-
const res = event.data;
|
|
100
|
-
if (DelightRPC.isError(res) || DelightRPC.isBatchResponse(res)) {
|
|
101
|
-
(_a = pendings[res.id]) === null || _a === void 0 ? void 0 : _a.resolve(res);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
export function createBatchClientInRenderer(port, { expectedVersion, channel } = {}) {
|
|
106
|
-
const pendings = {};
|
|
107
|
-
port.addEventListener('message', handler);
|
|
108
|
-
const client = new DelightRPC.BatchClient(async function send(request) {
|
|
109
|
-
const res = new Deferred();
|
|
110
|
-
pendings[request.id] = res;
|
|
111
|
-
try {
|
|
112
|
-
port.postMessage(request);
|
|
113
|
-
return await res;
|
|
114
|
-
}
|
|
115
|
-
finally {
|
|
116
|
-
delete pendings[request.id];
|
|
117
|
-
}
|
|
118
|
-
}, {
|
|
119
|
-
expectedVersion,
|
|
120
|
-
channel
|
|
121
|
-
});
|
|
122
|
-
return [client, close];
|
|
123
|
-
function close() {
|
|
124
|
-
port.removeEventListener('message', handler);
|
|
125
|
-
for (const [key, deferred] of Object.entries(pendings)) {
|
|
126
|
-
deferred.reject(new ClientClosed());
|
|
127
|
-
delete pendings[key];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function handler(event) {
|
|
131
|
-
var _a;
|
|
132
|
-
const res = event.data;
|
|
133
|
-
if (DelightRPC.isError(res) || DelightRPC.isBatchResponse(res)) {
|
|
134
|
-
(_a = pendings[res.id]) === null || _a === void 0 ? void 0 : _a.resolve(res);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
export class ClientClosed extends CustomError {
|
|
139
|
-
}
|
|
1
|
+
import * as DelightRPC from 'delight-rpc';
|
|
2
|
+
import { Deferred } from 'extra-promise';
|
|
3
|
+
import { CustomError } from '@blackglory/errors';
|
|
4
|
+
export function createClientInMain(port, { parameterValidators, expectedVersion, channel } = {}) {
|
|
5
|
+
const pendings = {};
|
|
6
|
+
port.addListener('message', handler);
|
|
7
|
+
const client = DelightRPC.createClient(async function send(request) {
|
|
8
|
+
const res = new Deferred();
|
|
9
|
+
pendings[request.id] = res;
|
|
10
|
+
try {
|
|
11
|
+
port.postMessage(request);
|
|
12
|
+
return await res;
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
delete pendings[request.id];
|
|
16
|
+
}
|
|
17
|
+
}, {
|
|
18
|
+
parameterValidators,
|
|
19
|
+
expectedVersion,
|
|
20
|
+
channel
|
|
21
|
+
});
|
|
22
|
+
return [client, close];
|
|
23
|
+
function close() {
|
|
24
|
+
port.removeListener('message', handler);
|
|
25
|
+
for (const [key, deferred] of Object.entries(pendings)) {
|
|
26
|
+
deferred.reject(new ClientClosed());
|
|
27
|
+
delete pendings[key];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function handler(event) {
|
|
31
|
+
var _a;
|
|
32
|
+
const res = event.data;
|
|
33
|
+
if (DelightRPC.isResult(res) || DelightRPC.isError(res)) {
|
|
34
|
+
(_a = pendings[res.id]) === null || _a === void 0 ? void 0 : _a.resolve(res);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function createClientInRenderer(port, { parameterValidators, expectedVersion, channel } = {}) {
|
|
39
|
+
const pendings = {};
|
|
40
|
+
port.addEventListener('message', handler);
|
|
41
|
+
const client = DelightRPC.createClient(async function send(request) {
|
|
42
|
+
const res = new Deferred();
|
|
43
|
+
pendings[request.id] = res;
|
|
44
|
+
try {
|
|
45
|
+
port.postMessage(request);
|
|
46
|
+
return await res;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
delete pendings[request.id];
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
parameterValidators,
|
|
53
|
+
expectedVersion,
|
|
54
|
+
channel
|
|
55
|
+
});
|
|
56
|
+
return [client, close];
|
|
57
|
+
function close() {
|
|
58
|
+
port.removeEventListener('message', handler);
|
|
59
|
+
for (const [key, deferred] of Object.entries(pendings)) {
|
|
60
|
+
deferred.reject(new ClientClosed());
|
|
61
|
+
delete pendings[key];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function handler(event) {
|
|
65
|
+
var _a;
|
|
66
|
+
const res = event.data;
|
|
67
|
+
if (DelightRPC.isResult(res) || DelightRPC.isError(res)) {
|
|
68
|
+
(_a = pendings[res.id]) === null || _a === void 0 ? void 0 : _a.resolve(res);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function createBatchClientInMain(port, { expectedVersion, channel } = {}) {
|
|
73
|
+
const pendings = {};
|
|
74
|
+
port.addListener('message', handler);
|
|
75
|
+
const client = new DelightRPC.BatchClient(async function send(request) {
|
|
76
|
+
const res = new Deferred();
|
|
77
|
+
pendings[request.id] = res;
|
|
78
|
+
try {
|
|
79
|
+
port.postMessage(request);
|
|
80
|
+
return await res;
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
delete pendings[request.id];
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
expectedVersion,
|
|
87
|
+
channel
|
|
88
|
+
});
|
|
89
|
+
return [client, close];
|
|
90
|
+
function close() {
|
|
91
|
+
port.removeListener('message', handler);
|
|
92
|
+
for (const [key, deferred] of Object.entries(pendings)) {
|
|
93
|
+
deferred.reject(new ClientClosed());
|
|
94
|
+
delete pendings[key];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function handler(event) {
|
|
98
|
+
var _a;
|
|
99
|
+
const res = event.data;
|
|
100
|
+
if (DelightRPC.isError(res) || DelightRPC.isBatchResponse(res)) {
|
|
101
|
+
(_a = pendings[res.id]) === null || _a === void 0 ? void 0 : _a.resolve(res);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function createBatchClientInRenderer(port, { expectedVersion, channel } = {}) {
|
|
106
|
+
const pendings = {};
|
|
107
|
+
port.addEventListener('message', handler);
|
|
108
|
+
const client = new DelightRPC.BatchClient(async function send(request) {
|
|
109
|
+
const res = new Deferred();
|
|
110
|
+
pendings[request.id] = res;
|
|
111
|
+
try {
|
|
112
|
+
port.postMessage(request);
|
|
113
|
+
return await res;
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
delete pendings[request.id];
|
|
117
|
+
}
|
|
118
|
+
}, {
|
|
119
|
+
expectedVersion,
|
|
120
|
+
channel
|
|
121
|
+
});
|
|
122
|
+
return [client, close];
|
|
123
|
+
function close() {
|
|
124
|
+
port.removeEventListener('message', handler);
|
|
125
|
+
for (const [key, deferred] of Object.entries(pendings)) {
|
|
126
|
+
deferred.reject(new ClientClosed());
|
|
127
|
+
delete pendings[key];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function handler(event) {
|
|
131
|
+
var _a;
|
|
132
|
+
const res = event.data;
|
|
133
|
+
if (DelightRPC.isError(res) || DelightRPC.isBatchResponse(res)) {
|
|
134
|
+
(_a = pendings[res.id]) === null || _a === void 0 ? void 0 : _a.resolve(res);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export class ClientClosed extends CustomError {
|
|
139
|
+
}
|
|
140
140
|
//# sourceMappingURL=client.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './client.js';
|
|
2
|
-
export * from './server.js';
|
|
1
|
+
export * from './client.js';
|
|
2
|
+
export * from './server.js';
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './client.js';
|
|
2
|
-
export * from './server.js';
|
|
1
|
+
export * from './client.js';
|
|
2
|
+
export * from './server.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/lib/server.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import * as DelightRPC from 'delight-rpc';
|
|
2
|
-
import Electron from 'electron';
|
|
3
|
-
export declare function createServerInMain<IAPI extends object>(api: DelightRPC.ImplementationOf<IAPI>, port: Electron.MessagePortMain, { parameterValidators, version, channel, ownPropsOnly }?: {
|
|
4
|
-
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
5
|
-
version?: `${number}.${number}.${number}`;
|
|
6
|
-
channel?: string | RegExp | typeof DelightRPC.AnyChannel;
|
|
7
|
-
ownPropsOnly?: boolean;
|
|
8
|
-
}): () => void;
|
|
9
|
-
export declare function createServerInRenderer<IAPI extends object>(api: DelightRPC.ImplementationOf<IAPI>, port: MessagePort, { parameterValidators, version, channel, ownPropsOnly }?: {
|
|
10
|
-
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
11
|
-
version?: `${number}.${number}.${number}`;
|
|
12
|
-
channel?: string | RegExp | typeof DelightRPC.AnyChannel;
|
|
13
|
-
ownPropsOnly?: boolean;
|
|
14
|
-
}): () => void;
|
|
1
|
+
import * as DelightRPC from 'delight-rpc';
|
|
2
|
+
import Electron from 'electron';
|
|
3
|
+
export declare function createServerInMain<IAPI extends object>(api: DelightRPC.ImplementationOf<IAPI>, port: Electron.MessagePortMain, { parameterValidators, version, channel, ownPropsOnly }?: {
|
|
4
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
5
|
+
version?: `${number}.${number}.${number}`;
|
|
6
|
+
channel?: string | RegExp | typeof DelightRPC.AnyChannel;
|
|
7
|
+
ownPropsOnly?: boolean;
|
|
8
|
+
}): () => void;
|
|
9
|
+
export declare function createServerInRenderer<IAPI extends object>(api: DelightRPC.ImplementationOf<IAPI>, port: MessagePort, { parameterValidators, version, channel, ownPropsOnly }?: {
|
|
10
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
11
|
+
version?: `${number}.${number}.${number}`;
|
|
12
|
+
channel?: string | RegExp | typeof DelightRPC.AnyChannel;
|
|
13
|
+
ownPropsOnly?: boolean;
|
|
14
|
+
}): () => void;
|
package/lib/server.js
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import * as DelightRPC from 'delight-rpc';
|
|
2
|
-
import { isntNull } from '@blackglory/prelude';
|
|
3
|
-
export function createServerInMain(api, port, { parameterValidators, version, channel, ownPropsOnly } = {}) {
|
|
4
|
-
port.addListener('message', handler);
|
|
5
|
-
return () => port.removeListener('message', handler);
|
|
6
|
-
async function handler(event) {
|
|
7
|
-
const req = event.data;
|
|
8
|
-
if (DelightRPC.isRequest(req) || DelightRPC.isBatchRequest(req)) {
|
|
9
|
-
const result = await DelightRPC.createResponse(api, req, {
|
|
10
|
-
parameterValidators,
|
|
11
|
-
version,
|
|
12
|
-
channel,
|
|
13
|
-
ownPropsOnly
|
|
14
|
-
});
|
|
15
|
-
if (isntNull(result)) {
|
|
16
|
-
port.postMessage(result);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export function createServerInRenderer(api, port, { parameterValidators, version, channel, ownPropsOnly } = {}) {
|
|
22
|
-
port.addEventListener('message', handler);
|
|
23
|
-
return () => port.removeEventListener('message', handler);
|
|
24
|
-
async function handler(event) {
|
|
25
|
-
const req = event.data;
|
|
26
|
-
if (DelightRPC.isRequest(req) || DelightRPC.isBatchRequest(req)) {
|
|
27
|
-
const result = await DelightRPC.createResponse(api, req, {
|
|
28
|
-
parameterValidators,
|
|
29
|
-
version,
|
|
30
|
-
channel,
|
|
31
|
-
ownPropsOnly
|
|
32
|
-
});
|
|
33
|
-
if (isntNull(result)) {
|
|
34
|
-
port.postMessage(result);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
import * as DelightRPC from 'delight-rpc';
|
|
2
|
+
import { isntNull } from '@blackglory/prelude';
|
|
3
|
+
export function createServerInMain(api, port, { parameterValidators, version, channel, ownPropsOnly } = {}) {
|
|
4
|
+
port.addListener('message', handler);
|
|
5
|
+
return () => port.removeListener('message', handler);
|
|
6
|
+
async function handler(event) {
|
|
7
|
+
const req = event.data;
|
|
8
|
+
if (DelightRPC.isRequest(req) || DelightRPC.isBatchRequest(req)) {
|
|
9
|
+
const result = await DelightRPC.createResponse(api, req, {
|
|
10
|
+
parameterValidators,
|
|
11
|
+
version,
|
|
12
|
+
channel,
|
|
13
|
+
ownPropsOnly
|
|
14
|
+
});
|
|
15
|
+
if (isntNull(result)) {
|
|
16
|
+
port.postMessage(result);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function createServerInRenderer(api, port, { parameterValidators, version, channel, ownPropsOnly } = {}) {
|
|
22
|
+
port.addEventListener('message', handler);
|
|
23
|
+
return () => port.removeEventListener('message', handler);
|
|
24
|
+
async function handler(event) {
|
|
25
|
+
const req = event.data;
|
|
26
|
+
if (DelightRPC.isRequest(req) || DelightRPC.isBatchRequest(req)) {
|
|
27
|
+
const result = await DelightRPC.createResponse(api, req, {
|
|
28
|
+
parameterValidators,
|
|
29
|
+
version,
|
|
30
|
+
channel,
|
|
31
|
+
ownPropsOnly
|
|
32
|
+
});
|
|
33
|
+
if (isntNull(result)) {
|
|
34
|
+
port.postMessage(result);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
39
|
//# sourceMappingURL=server.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delight-rpc/electron",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"files": [
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@typescript-eslint/parser": "^5.55.0",
|
|
44
44
|
"cross-env": "^7.0.3",
|
|
45
45
|
"delight-rpc": "^6.0.0",
|
|
46
|
-
"electron": "^
|
|
46
|
+
"electron": "^34.1.1",
|
|
47
47
|
"eslint": "8.36.0",
|
|
48
48
|
"husky": "4",
|
|
49
49
|
"jest": "^29.5.0",
|
|
@@ -65,6 +65,6 @@
|
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"delight-rpc": "^5.0.0 || ^6.0.0",
|
|
68
|
-
"electron": ">=16.0.1 <
|
|
68
|
+
"electron": ">=16.0.1 <35"
|
|
69
69
|
}
|
|
70
70
|
}
|