@delight-rpc/electron 6.0.5 → 6.0.6
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/lib/client.d.ts +23 -23
- package/lib/client.js +139 -139
- package/lib/client.js.map +1 -1
- 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 +1 -1
- package/src/client.ts +30 -33
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
|
|
10
|
-
try {
|
|
11
|
-
port.postMessage(request);
|
|
12
|
-
return await res;
|
|
13
|
-
}
|
|
14
|
-
finally {
|
|
15
|
-
delete
|
|
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
|
|
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
|
|
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
|
|
44
|
-
try {
|
|
45
|
-
port.postMessage(request);
|
|
46
|
-
return await res;
|
|
47
|
-
}
|
|
48
|
-
finally {
|
|
49
|
-
delete
|
|
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
|
|
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
|
|
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
|
|
78
|
-
try {
|
|
79
|
-
port.postMessage(request);
|
|
80
|
-
return await res;
|
|
81
|
-
}
|
|
82
|
-
finally {
|
|
83
|
-
delete
|
|
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
|
|
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
|
|
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
|
|
111
|
-
try {
|
|
112
|
-
port.postMessage(request);
|
|
113
|
-
return await res;
|
|
114
|
-
}
|
|
115
|
-
finally {
|
|
116
|
-
delete
|
|
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
|
|
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
|
|
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 = new Map();
|
|
6
|
+
port.addListener('message', handler);
|
|
7
|
+
const client = DelightRPC.createClient(async function send(request) {
|
|
8
|
+
const res = new Deferred();
|
|
9
|
+
pendings.set(request.id, res);
|
|
10
|
+
try {
|
|
11
|
+
port.postMessage(request);
|
|
12
|
+
return await res;
|
|
13
|
+
}
|
|
14
|
+
finally {
|
|
15
|
+
pendings.delete(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
|
+
pendings.delete(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.get(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 = new Map();
|
|
40
|
+
port.addEventListener('message', handler);
|
|
41
|
+
const client = DelightRPC.createClient(async function send(request) {
|
|
42
|
+
const res = new Deferred();
|
|
43
|
+
pendings.set(request.id, res);
|
|
44
|
+
try {
|
|
45
|
+
port.postMessage(request);
|
|
46
|
+
return await res;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
pendings.delete(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
|
+
pendings.delete(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.get(res.id)) === null || _a === void 0 ? void 0 : _a.resolve(res);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function createBatchClientInMain(port, { expectedVersion, channel } = {}) {
|
|
73
|
+
const pendings = new Map();
|
|
74
|
+
port.addListener('message', handler);
|
|
75
|
+
const client = new DelightRPC.BatchClient(async function send(request) {
|
|
76
|
+
const res = new Deferred();
|
|
77
|
+
pendings.set(request.id, res);
|
|
78
|
+
try {
|
|
79
|
+
port.postMessage(request);
|
|
80
|
+
return await res;
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
pendings.delete(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
|
+
pendings.delete(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.get(res.id)) === null || _a === void 0 ? void 0 : _a.resolve(res);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function createBatchClientInRenderer(port, { expectedVersion, channel } = {}) {
|
|
106
|
+
const pendings = new Map();
|
|
107
|
+
port.addEventListener('message', handler);
|
|
108
|
+
const client = new DelightRPC.BatchClient(async function send(request) {
|
|
109
|
+
const res = new Deferred();
|
|
110
|
+
pendings.set(request.id, res);
|
|
111
|
+
try {
|
|
112
|
+
port.postMessage(request);
|
|
113
|
+
return await res;
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
pendings.delete(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
|
+
pendings.delete(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.get(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/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGhD,MAAM,UAAU,kBAAkB,CAChC,IAA8B,EAC9B,EAAE,mBAAmB,EAAE,eAAe,EAAE,OAAO,KAI3C,EAAE;IAEN,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,aAAa,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGhD,MAAM,UAAU,kBAAkB,CAChC,IAA8B,EAC9B,EAAE,mBAAmB,EAAE,eAAe,EAAE,OAAO,KAI3C,EAAE;IAEN,MAAM,QAAQ,GAA8C,IAAI,GAAG,EAAE,CAAA;IAErE,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAEpC,MAAM,MAAM,GAAG,UAAU,CAAC,YAAY,CACpC,KAAK,UAAU,IAAI,CAAC,OAAO;QACzB,MAAM,GAAG,GAAG,IAAI,QAAQ,EAAsB,CAAA;QAC9C,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;QAC7B,IAAI;YACF,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;YACzB,OAAO,MAAM,GAAG,CAAA;SACjB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,IAAI,QAAQ,EAGrB,CAAA;QACH,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;QAC7B,IAAI;YACF,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;YACzB,OAAO,MAAM,GAAG,CAAA;SACjB;gBAAS;YACR,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;SAC5B;IACH,CAAC,EACD;QACE,eAAe;QACf,OAAO;KACR,CACF,CAAA;IAED,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IAEtB,SAAS,KAAK;QACZ,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAE5C,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YACtD,QAAQ,CAAC,MAAM,CAAC,IAAI,YAAY,EAAE,CAAC,CAAA;YACnC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;SACrB;IACH,CAAC;IAED,SAAS,OAAO,CAAC,KAAmB;;QAClC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAA;QACtB,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE;YAC9D,MAAA,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,0CAAE,OAAO,CAAC,GAAG,CAAC,CAAA;SACnC;IACH,CAAC;AACH,CAAC;AAED,MAAM,OAAO,YAAa,SAAQ,WAAW;CAAG"}
|
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
package/src/client.ts
CHANGED
|
@@ -12,19 +12,19 @@ export function createClientInMain<IAPI extends object>(
|
|
|
12
12
|
, channel?: string
|
|
13
13
|
} = {}
|
|
14
14
|
): [client: DelightRPC.ClientProxy<IAPI>, close: () => void] {
|
|
15
|
-
const pendings:
|
|
15
|
+
const pendings: Map<string, Deferred<IResponse<unknown>>> = new Map()
|
|
16
16
|
|
|
17
17
|
port.addListener('message', handler)
|
|
18
18
|
|
|
19
19
|
const client = DelightRPC.createClient<IAPI>(
|
|
20
20
|
async function send(request) {
|
|
21
21
|
const res = new Deferred<IResponse<unknown>>()
|
|
22
|
-
pendings
|
|
22
|
+
pendings.set(request.id, res)
|
|
23
23
|
try {
|
|
24
24
|
port.postMessage(request)
|
|
25
25
|
return await res
|
|
26
26
|
} finally {
|
|
27
|
-
delete
|
|
27
|
+
pendings.delete(request.id)
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
, {
|
|
@@ -40,15 +40,15 @@ export function createClientInMain<IAPI extends object>(
|
|
|
40
40
|
port.removeListener('message', handler)
|
|
41
41
|
|
|
42
42
|
for (const [key, deferred] of Object.entries(pendings)) {
|
|
43
|
-
deferred
|
|
44
|
-
delete
|
|
43
|
+
deferred.reject(new ClientClosed())
|
|
44
|
+
pendings.delete(key)
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function handler(event: Electron.MessageEvent): void {
|
|
49
49
|
const res = event.data
|
|
50
50
|
if (DelightRPC.isResult(res) || DelightRPC.isError(res)) {
|
|
51
|
-
pendings
|
|
51
|
+
pendings.get(res.id)?.resolve(res)
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -61,23 +61,22 @@ export function createClientInRenderer<IAPI extends object>(
|
|
|
61
61
|
channel?: string
|
|
62
62
|
} = {}
|
|
63
63
|
): [client: DelightRPC.ClientProxy<IAPI>, close: () => void] {
|
|
64
|
-
const pendings:
|
|
64
|
+
const pendings: Map<
|
|
65
65
|
string
|
|
66
|
-
,
|
|
67
|
-
|
|
68
|
-
> = {}
|
|
66
|
+
, Deferred<IResponse<unknown>>
|
|
67
|
+
> = new Map()
|
|
69
68
|
|
|
70
69
|
port.addEventListener('message', handler)
|
|
71
70
|
|
|
72
71
|
const client = DelightRPC.createClient<IAPI>(
|
|
73
72
|
async function send(request) {
|
|
74
73
|
const res = new Deferred<IResponse<unknown>>()
|
|
75
|
-
pendings
|
|
74
|
+
pendings.set(request.id, res)
|
|
76
75
|
try {
|
|
77
76
|
port.postMessage(request)
|
|
78
77
|
return await res
|
|
79
78
|
} finally {
|
|
80
|
-
delete
|
|
79
|
+
pendings.delete(request.id)
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
, {
|
|
@@ -93,15 +92,15 @@ export function createClientInRenderer<IAPI extends object>(
|
|
|
93
92
|
port.removeEventListener('message', handler)
|
|
94
93
|
|
|
95
94
|
for (const [key, deferred] of Object.entries(pendings)) {
|
|
96
|
-
deferred
|
|
97
|
-
delete
|
|
95
|
+
deferred.reject(new ClientClosed())
|
|
96
|
+
pendings.delete(key)
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
function handler(event: MessageEvent): void {
|
|
102
101
|
const res = event.data
|
|
103
102
|
if (DelightRPC.isResult(res) || DelightRPC.isError(res)) {
|
|
104
|
-
pendings
|
|
103
|
+
pendings.get(res.id)?.resolve(res)
|
|
105
104
|
}
|
|
106
105
|
}
|
|
107
106
|
}
|
|
@@ -113,11 +112,10 @@ export function createBatchClientInMain<DataType>(
|
|
|
113
112
|
channel?: string
|
|
114
113
|
} = {}
|
|
115
114
|
): [client: DelightRPC.BatchClient<DataType>, close: () => void] {
|
|
116
|
-
const pendings:
|
|
115
|
+
const pendings: Map<
|
|
117
116
|
string
|
|
118
|
-
,
|
|
119
|
-
|
|
120
|
-
> = {}
|
|
117
|
+
, Deferred<IError | IBatchResponse<unknown>>
|
|
118
|
+
> = new Map()
|
|
121
119
|
|
|
122
120
|
port.addListener('message', handler)
|
|
123
121
|
|
|
@@ -127,12 +125,12 @@ export function createBatchClientInMain<DataType>(
|
|
|
127
125
|
| IError
|
|
128
126
|
| IBatchResponse<unknown>
|
|
129
127
|
>()
|
|
130
|
-
pendings
|
|
128
|
+
pendings.set(request.id, res)
|
|
131
129
|
try {
|
|
132
130
|
port.postMessage(request)
|
|
133
131
|
return await res
|
|
134
132
|
} finally {
|
|
135
|
-
delete
|
|
133
|
+
pendings.delete(request.id)
|
|
136
134
|
}
|
|
137
135
|
}
|
|
138
136
|
, {
|
|
@@ -147,15 +145,15 @@ export function createBatchClientInMain<DataType>(
|
|
|
147
145
|
port.removeListener('message', handler)
|
|
148
146
|
|
|
149
147
|
for (const [key, deferred] of Object.entries(pendings)) {
|
|
150
|
-
deferred
|
|
151
|
-
delete
|
|
148
|
+
deferred.reject(new ClientClosed())
|
|
149
|
+
pendings.delete(key)
|
|
152
150
|
}
|
|
153
151
|
}
|
|
154
152
|
|
|
155
153
|
function handler(event: Electron.MessageEvent): void {
|
|
156
154
|
const res = event.data
|
|
157
155
|
if (DelightRPC.isError(res) || DelightRPC.isBatchResponse(res)) {
|
|
158
|
-
pendings
|
|
156
|
+
pendings.get(res.id)?.resolve(res)
|
|
159
157
|
}
|
|
160
158
|
}
|
|
161
159
|
}
|
|
@@ -167,11 +165,10 @@ export function createBatchClientInRenderer<DataType>(
|
|
|
167
165
|
channel?: string
|
|
168
166
|
} = {}
|
|
169
167
|
): [client: DelightRPC.BatchClient<DataType>, close: () => void] {
|
|
170
|
-
const pendings:
|
|
168
|
+
const pendings: Map<
|
|
171
169
|
string
|
|
172
|
-
,
|
|
173
|
-
|
|
174
|
-
> = {}
|
|
170
|
+
, Deferred<IError | IBatchResponse<unknown>>
|
|
171
|
+
> = new Map()
|
|
175
172
|
|
|
176
173
|
port.addEventListener('message', handler)
|
|
177
174
|
|
|
@@ -181,12 +178,12 @@ export function createBatchClientInRenderer<DataType>(
|
|
|
181
178
|
| IError
|
|
182
179
|
| IBatchResponse<unknown>
|
|
183
180
|
>()
|
|
184
|
-
pendings
|
|
181
|
+
pendings.set(request.id, res)
|
|
185
182
|
try {
|
|
186
183
|
port.postMessage(request)
|
|
187
184
|
return await res
|
|
188
185
|
} finally {
|
|
189
|
-
delete
|
|
186
|
+
pendings.delete(request.id)
|
|
190
187
|
}
|
|
191
188
|
}
|
|
192
189
|
, {
|
|
@@ -201,15 +198,15 @@ export function createBatchClientInRenderer<DataType>(
|
|
|
201
198
|
port.removeEventListener('message', handler)
|
|
202
199
|
|
|
203
200
|
for (const [key, deferred] of Object.entries(pendings)) {
|
|
204
|
-
deferred
|
|
205
|
-
delete
|
|
201
|
+
deferred.reject(new ClientClosed())
|
|
202
|
+
pendings.delete(key)
|
|
206
203
|
}
|
|
207
204
|
}
|
|
208
205
|
|
|
209
206
|
function handler(event: MessageEvent): void {
|
|
210
207
|
const res = event.data
|
|
211
208
|
if (DelightRPC.isError(res) || DelightRPC.isBatchResponse(res)) {
|
|
212
|
-
pendings
|
|
209
|
+
pendings.get(res.id)?.resolve(res)
|
|
213
210
|
}
|
|
214
211
|
}
|
|
215
212
|
}
|