@delight-rpc/electron 3.0.0 → 4.0.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 +43 -9
- package/lib/client.d.ts +18 -2
- package/lib/client.js +84 -6
- package/lib/client.js.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/server.d.ts +10 -2
- package/lib/server.js +26 -9
- package/lib/server.js.map +1 -1
- package/package.json +16 -14
package/README.md
CHANGED
|
@@ -197,8 +197,11 @@ window.ready()
|
|
|
197
197
|
```ts
|
|
198
198
|
function createClientInMain<IAPI extends object>(
|
|
199
199
|
port: Electron.MessagePortMain
|
|
200
|
-
,
|
|
201
|
-
|
|
200
|
+
, options?: {
|
|
201
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>
|
|
202
|
+
expectedVersion?: `${number}.${number}.${number}`
|
|
203
|
+
channel?: string
|
|
204
|
+
}
|
|
202
205
|
): [client: DelightRPC.ClientProxy<IAPI>, close: () => void]
|
|
203
206
|
```
|
|
204
207
|
|
|
@@ -206,18 +209,46 @@ function createClientInMain<IAPI extends object>(
|
|
|
206
209
|
```ts
|
|
207
210
|
function createClientInRenderer<IAPI extends object>(
|
|
208
211
|
port: MessagePort
|
|
209
|
-
,
|
|
210
|
-
|
|
212
|
+
, options?: {
|
|
213
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>
|
|
214
|
+
expectedVersion?: `${number}.${number}.${number}`
|
|
215
|
+
channel?: string
|
|
216
|
+
}
|
|
211
217
|
): [client: DelightRPC.ClientProxy<IAPI>, close: () => void]
|
|
212
218
|
```
|
|
213
219
|
|
|
220
|
+
### createBatchClientInMain
|
|
221
|
+
```ts
|
|
222
|
+
function createBatchClientInMain(
|
|
223
|
+
port: Electron.MessagePortMain
|
|
224
|
+
, options?: {
|
|
225
|
+
expectedVersion?: `${number}.${number}.${number}`
|
|
226
|
+
channel?: string
|
|
227
|
+
}
|
|
228
|
+
): [client: DelightRPC.BatchClient, close: () => void]
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### createBatchClientInRenderer
|
|
232
|
+
```ts
|
|
233
|
+
function createBatchClientInRenderer(
|
|
234
|
+
port: MessagePort
|
|
235
|
+
, options?: {
|
|
236
|
+
expectedVersion?: `${number}.${number}.${number}`
|
|
237
|
+
channel?: string
|
|
238
|
+
}
|
|
239
|
+
): [client: DelightRPC.BatchClient, close: () => void]
|
|
240
|
+
```
|
|
241
|
+
|
|
214
242
|
### createServerInMain
|
|
215
243
|
```ts
|
|
216
244
|
function createServerInMain<IAPI extends object>(
|
|
217
245
|
api: DelightRPC.ImplementationOf<IAPI>
|
|
218
|
-
,
|
|
219
|
-
|
|
220
|
-
|
|
246
|
+
, options?: {
|
|
247
|
+
port: Electron.MessagePortMain
|
|
248
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>
|
|
249
|
+
version?: `${number}.${number}.${number}`
|
|
250
|
+
channel?: string
|
|
251
|
+
}
|
|
221
252
|
): () => void
|
|
222
253
|
```
|
|
223
254
|
|
|
@@ -226,7 +257,10 @@ function createServerInMain<IAPI extends object>(
|
|
|
226
257
|
function createServerInRenderer<IAPI extends object>(
|
|
227
258
|
api: DelightRPC.ImplementationOf<IAPI>
|
|
228
259
|
, port: MessagePort
|
|
229
|
-
,
|
|
230
|
-
|
|
260
|
+
, options?: {
|
|
261
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>
|
|
262
|
+
version?: `${number}.${number}.${number}`
|
|
263
|
+
channel?: string
|
|
264
|
+
}
|
|
231
265
|
): () => void
|
|
232
266
|
```
|
package/lib/client.d.ts
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import * as DelightRPC from 'delight-rpc';
|
|
2
2
|
import Electron from 'electron';
|
|
3
3
|
import { CustomError } from '@blackglory/errors';
|
|
4
|
-
export declare function createClientInMain<IAPI extends object>(port: Electron.MessagePortMain, parameterValidators
|
|
5
|
-
|
|
4
|
+
export declare function createClientInMain<IAPI extends object>(port: Electron.MessagePortMain, { parameterValidators, expectedVersion, channel }?: {
|
|
5
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
6
|
+
expectedVersion?: `${number}.${number}.${number}`;
|
|
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?: `${number}.${number}.${number}`;
|
|
12
|
+
channel?: string;
|
|
13
|
+
}): [client: DelightRPC.ClientProxy<IAPI>, close: () => void];
|
|
14
|
+
export declare function createBatchClientInMain(port: Electron.MessagePortMain, { expectedVersion, channel }?: {
|
|
15
|
+
expectedVersion?: `${number}.${number}.${number}`;
|
|
16
|
+
channel?: string;
|
|
17
|
+
}): [client: DelightRPC.BatchClient, close: () => void];
|
|
18
|
+
export declare function createBatchClientInRenderer(port: MessagePort, { expectedVersion, channel }?: {
|
|
19
|
+
expectedVersion?: `${number}.${number}.${number}`;
|
|
20
|
+
channel?: string;
|
|
21
|
+
}): [client: DelightRPC.BatchClient, close: () => void];
|
|
6
22
|
export declare class ClientClosed extends CustomError {
|
|
7
23
|
}
|
package/lib/client.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -19,11 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.ClientClosed = exports.createClientInRenderer = exports.createClientInMain = void 0;
|
|
26
|
+
exports.ClientClosed = exports.createBatchClientInRenderer = exports.createBatchClientInMain = exports.createClientInRenderer = exports.createClientInMain = void 0;
|
|
23
27
|
const DelightRPC = __importStar(require("delight-rpc"));
|
|
24
28
|
const extra_promise_1 = require("extra-promise");
|
|
25
29
|
const errors_1 = require("@blackglory/errors");
|
|
26
|
-
function createClientInMain(port, parameterValidators, expectedVersion) {
|
|
30
|
+
function createClientInMain(port, { parameterValidators, expectedVersion, channel } = {}) {
|
|
27
31
|
const pendings = {};
|
|
28
32
|
port.addListener('message', handler);
|
|
29
33
|
const client = DelightRPC.createClient(async function send(request) {
|
|
@@ -36,7 +40,11 @@ function createClientInMain(port, parameterValidators, expectedVersion) {
|
|
|
36
40
|
finally {
|
|
37
41
|
delete pendings[request.id];
|
|
38
42
|
}
|
|
39
|
-
},
|
|
43
|
+
}, {
|
|
44
|
+
parameterValidators,
|
|
45
|
+
expectedVersion,
|
|
46
|
+
channel
|
|
47
|
+
});
|
|
40
48
|
return [client, close];
|
|
41
49
|
function close() {
|
|
42
50
|
port.removeListener('message', handler);
|
|
@@ -53,7 +61,7 @@ function createClientInMain(port, parameterValidators, expectedVersion) {
|
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
exports.createClientInMain = createClientInMain;
|
|
56
|
-
function createClientInRenderer(port, parameterValidators, expectedVersion) {
|
|
64
|
+
function createClientInRenderer(port, { parameterValidators, expectedVersion, channel } = {}) {
|
|
57
65
|
const pendings = {};
|
|
58
66
|
port.addEventListener('message', handler);
|
|
59
67
|
const client = DelightRPC.createClient(async function send(request) {
|
|
@@ -66,7 +74,11 @@ function createClientInRenderer(port, parameterValidators, expectedVersion) {
|
|
|
66
74
|
finally {
|
|
67
75
|
delete pendings[request.id];
|
|
68
76
|
}
|
|
69
|
-
},
|
|
77
|
+
}, {
|
|
78
|
+
parameterValidators,
|
|
79
|
+
expectedVersion,
|
|
80
|
+
channel
|
|
81
|
+
});
|
|
70
82
|
return [client, close];
|
|
71
83
|
function close() {
|
|
72
84
|
port.removeEventListener('message', handler);
|
|
@@ -83,6 +95,72 @@ function createClientInRenderer(port, parameterValidators, expectedVersion) {
|
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
97
|
exports.createClientInRenderer = createClientInRenderer;
|
|
98
|
+
function createBatchClientInMain(port, { expectedVersion, channel } = {}) {
|
|
99
|
+
const pendings = {};
|
|
100
|
+
port.addListener('message', handler);
|
|
101
|
+
const client = new DelightRPC.BatchClient(async function send(request) {
|
|
102
|
+
const res = new extra_promise_1.Deferred();
|
|
103
|
+
pendings[request.id] = res;
|
|
104
|
+
try {
|
|
105
|
+
port.postMessage(request);
|
|
106
|
+
return await res;
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
delete pendings[request.id];
|
|
110
|
+
}
|
|
111
|
+
}, {
|
|
112
|
+
expectedVersion,
|
|
113
|
+
channel
|
|
114
|
+
});
|
|
115
|
+
return [client, close];
|
|
116
|
+
function close() {
|
|
117
|
+
port.removeListener('message', handler);
|
|
118
|
+
for (const [key, deferred] of Object.entries(pendings)) {
|
|
119
|
+
deferred.reject(new ClientClosed());
|
|
120
|
+
delete pendings[key];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function handler(event) {
|
|
124
|
+
const res = event.data;
|
|
125
|
+
if (DelightRPC.isError(res) || DelightRPC.isBatchResponse(res)) {
|
|
126
|
+
pendings[res.id].resolve(res);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
exports.createBatchClientInMain = createBatchClientInMain;
|
|
131
|
+
function createBatchClientInRenderer(port, { expectedVersion, channel } = {}) {
|
|
132
|
+
const pendings = {};
|
|
133
|
+
port.addEventListener('message', handler);
|
|
134
|
+
const client = new DelightRPC.BatchClient(async function send(request) {
|
|
135
|
+
const res = new extra_promise_1.Deferred();
|
|
136
|
+
pendings[request.id] = res;
|
|
137
|
+
try {
|
|
138
|
+
port.postMessage(request);
|
|
139
|
+
return await res;
|
|
140
|
+
}
|
|
141
|
+
finally {
|
|
142
|
+
delete pendings[request.id];
|
|
143
|
+
}
|
|
144
|
+
}, {
|
|
145
|
+
expectedVersion,
|
|
146
|
+
channel
|
|
147
|
+
});
|
|
148
|
+
return [client, close];
|
|
149
|
+
function close() {
|
|
150
|
+
port.removeEventListener('message', handler);
|
|
151
|
+
for (const [key, deferred] of Object.entries(pendings)) {
|
|
152
|
+
deferred.reject(new ClientClosed());
|
|
153
|
+
delete pendings[key];
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function handler(event) {
|
|
157
|
+
const res = event.data;
|
|
158
|
+
if (DelightRPC.isError(res) || DelightRPC.isBatchResponse(res)) {
|
|
159
|
+
pendings[res.id].resolve(res);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.createBatchClientInRenderer = createBatchClientInRenderer;
|
|
86
164
|
class ClientClosed extends errors_1.CustomError {
|
|
87
165
|
}
|
|
88
166
|
exports.ClientClosed = ClientClosed;
|
package/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAyC;AACzC,iDAAwC;AAExC,+CAAgD;AAGhD,SAAgB,kBAAkB,CAChC,IAA8B,EAC9B,EAAE,mBAAmB,EAAE,eAAe,EAAE,OAAO,KAI3C,EAAE;IAEN,MAAM,QAA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,oBAAW;CAAG;AAAhD,oCAAgD"}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,2CAAwB"}
|
package/lib/server.d.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import * as DelightRPC from 'delight-rpc';
|
|
2
2
|
import Electron from 'electron';
|
|
3
|
-
export declare function createServerInMain<IAPI extends object>(api: DelightRPC.ImplementationOf<IAPI>, port: Electron.MessagePortMain, parameterValidators
|
|
4
|
-
|
|
3
|
+
export declare function createServerInMain<IAPI extends object>(api: DelightRPC.ImplementationOf<IAPI>, port: Electron.MessagePortMain, { parameterValidators, version, channel }?: {
|
|
4
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
5
|
+
version?: `${number}.${number}.${number}`;
|
|
6
|
+
channel?: string;
|
|
7
|
+
}): () => void;
|
|
8
|
+
export declare function createServerInRenderer<IAPI extends object>(api: DelightRPC.ImplementationOf<IAPI>, port: MessagePort, { parameterValidators, version, channel }?: {
|
|
9
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
10
|
+
version?: `${number}.${number}.${number}`;
|
|
11
|
+
channel?: string;
|
|
12
|
+
}): () => void;
|
package/lib/server.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -21,26 +25,39 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
26
|
exports.createServerInRenderer = exports.createServerInMain = void 0;
|
|
23
27
|
const DelightRPC = __importStar(require("delight-rpc"));
|
|
24
|
-
|
|
28
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
29
|
+
function createServerInMain(api, port, { parameterValidators, version, channel } = {}) {
|
|
25
30
|
port.addListener('message', handler);
|
|
26
31
|
return () => port.removeListener('message', handler);
|
|
27
32
|
async function handler(event) {
|
|
28
33
|
const req = event.data;
|
|
29
|
-
if (DelightRPC.isRequest(req)) {
|
|
30
|
-
const result = await DelightRPC.createResponse(api, req,
|
|
31
|
-
|
|
34
|
+
if (DelightRPC.isRequest(req) || DelightRPC.isBatchRequest(req)) {
|
|
35
|
+
const result = await DelightRPC.createResponse(api, req, {
|
|
36
|
+
parameterValidators,
|
|
37
|
+
version,
|
|
38
|
+
channel
|
|
39
|
+
});
|
|
40
|
+
if ((0, prelude_1.isntNull)(result)) {
|
|
41
|
+
port.postMessage(result);
|
|
42
|
+
}
|
|
32
43
|
}
|
|
33
44
|
}
|
|
34
45
|
}
|
|
35
46
|
exports.createServerInMain = createServerInMain;
|
|
36
|
-
function createServerInRenderer(api, port, parameterValidators, version) {
|
|
47
|
+
function createServerInRenderer(api, port, { parameterValidators, version, channel } = {}) {
|
|
37
48
|
port.addEventListener('message', handler);
|
|
38
49
|
return () => port.removeEventListener('message', handler);
|
|
39
50
|
async function handler(event) {
|
|
40
51
|
const req = event.data;
|
|
41
|
-
if (DelightRPC.isRequest(req)) {
|
|
42
|
-
const result = await DelightRPC.createResponse(api, req,
|
|
43
|
-
|
|
52
|
+
if (DelightRPC.isRequest(req) || DelightRPC.isBatchRequest(req)) {
|
|
53
|
+
const result = await DelightRPC.createResponse(api, req, {
|
|
54
|
+
parameterValidators,
|
|
55
|
+
version,
|
|
56
|
+
channel
|
|
57
|
+
});
|
|
58
|
+
if ((0, prelude_1.isntNull)(result)) {
|
|
59
|
+
port.postMessage(result);
|
|
60
|
+
}
|
|
44
61
|
}
|
|
45
62
|
}
|
|
46
63
|
}
|
package/lib/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAyC;AAEzC,iDAA8C;AAE9C,SAAgB,kBAAkB,CAChC,GAAsC,EACtC,IAA8B,EAC9B,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,KAInC,EAAE;IAEN,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IACpC,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAEpD,KAAK,UAAU,OAAO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ight-rpc/electron",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"files": [
|
|
@@ -30,31 +30,33 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@blackglory/jest-matchers": "^0.
|
|
34
|
-
"@commitlint/cli": "^16.
|
|
35
|
-
"@commitlint/config-conventional": "^16.
|
|
36
|
-
"@types/jest": "^27.
|
|
37
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
38
|
-
"@typescript-eslint/parser": "^5.
|
|
33
|
+
"@blackglory/jest-matchers": "^0.3.1",
|
|
34
|
+
"@commitlint/cli": "^16.2.4",
|
|
35
|
+
"@commitlint/config-conventional": "^16.2.4",
|
|
36
|
+
"@types/jest": "^27.5.0",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^5.22.0",
|
|
38
|
+
"@typescript-eslint/parser": "^5.22.0",
|
|
39
39
|
"cross-env": "^7.0.3",
|
|
40
|
-
"delight-rpc": "^
|
|
40
|
+
"delight-rpc": "^4.0.0",
|
|
41
41
|
"electron": "^16.0.7",
|
|
42
|
-
"eslint": "8.
|
|
42
|
+
"eslint": "8.15.0",
|
|
43
43
|
"husky": "4",
|
|
44
44
|
"jest": "^27.5.1",
|
|
45
45
|
"npm-run-all": "^4.1.5",
|
|
46
46
|
"rimraf": "^3.0.2",
|
|
47
47
|
"standard-version": "^9.3.2",
|
|
48
|
-
"ts-jest": "^27.1.
|
|
48
|
+
"ts-jest": "^27.1.4",
|
|
49
49
|
"tscpaths": "^0.0.9",
|
|
50
|
-
"typescript": "^4.
|
|
50
|
+
"typescript": "^4.6.4"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@blackglory/errors": "^2.2.
|
|
54
|
-
"
|
|
53
|
+
"@blackglory/errors": "^2.2.1",
|
|
54
|
+
"@blackglory/prelude": "^0.1.1",
|
|
55
|
+
"@delight-rpc/protocol": "^2.2.0",
|
|
56
|
+
"extra-promise": "^1.0.2"
|
|
55
57
|
},
|
|
56
58
|
"peerDependencies": {
|
|
57
|
-
"delight-rpc": "^
|
|
59
|
+
"delight-rpc": "^4.0.0",
|
|
58
60
|
"electron": "^16.0.1"
|
|
59
61
|
}
|
|
60
62
|
}
|