@delight-rpc/child-process 0.3.0 → 0.4.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 +21 -4
- package/lib/client.d.ts +9 -1
- package/lib/client.js +44 -4
- 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 +5 -1
- package/lib/server.js +16 -5
- package/lib/server.js.map +1 -1
- package/package.json +18 -16
package/README.md
CHANGED
|
@@ -67,17 +67,34 @@ await client.echo('hello world')
|
|
|
67
67
|
```ts
|
|
68
68
|
function createClient<IAPI extends object>(
|
|
69
69
|
process: ChildProcess | NodeJS.Process
|
|
70
|
-
,
|
|
71
|
-
|
|
70
|
+
, options?: {
|
|
71
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>
|
|
72
|
+
expectedVersion?: `${number}.${number}.${number}`
|
|
73
|
+
channel?: string
|
|
74
|
+
}
|
|
72
75
|
): [client: DelightRPC.ClientProxy<IAPI>, close: () => void]
|
|
73
76
|
```
|
|
74
77
|
|
|
78
|
+
### createBatchClient
|
|
79
|
+
```ts
|
|
80
|
+
function createBatchClient(
|
|
81
|
+
process: ChildProcess | NodeJS.Process
|
|
82
|
+
, options?: {
|
|
83
|
+
expectedVersion?: `${number}.${number}.${number}`
|
|
84
|
+
channel?: string
|
|
85
|
+
}
|
|
86
|
+
): [client: DelightRPC.BatchClient, close: () => void]
|
|
87
|
+
```
|
|
88
|
+
|
|
75
89
|
### createServer
|
|
76
90
|
```ts
|
|
77
91
|
function createServer<IAPI extends object>(
|
|
78
92
|
api: DelightRPC.ImplementationOf<IAPI>
|
|
79
93
|
, process: ChildProcess | NodeJS.Process
|
|
80
|
-
,
|
|
81
|
-
|
|
94
|
+
, options?: {
|
|
95
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>
|
|
96
|
+
version?: `${number}.${number}.${number}`
|
|
97
|
+
channel?: string
|
|
98
|
+
}
|
|
82
99
|
): () => void
|
|
83
100
|
```
|
package/lib/client.d.ts
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
import * as DelightRPC from 'delight-rpc';
|
|
3
3
|
import { ChildProcess } from 'child_process';
|
|
4
4
|
import { CustomError } from '@blackglory/errors';
|
|
5
|
-
export declare function createClient<IAPI extends object>(process: ChildProcess | NodeJS.Process, parameterValidators
|
|
5
|
+
export declare function createClient<IAPI extends object>(process: ChildProcess | NodeJS.Process, { parameterValidators, expectedVersion, channel }?: {
|
|
6
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
7
|
+
expectedVersion?: `${number}.${number}.${number}`;
|
|
8
|
+
channel?: string;
|
|
9
|
+
}): [client: DelightRPC.ClientProxy<IAPI>, close: () => void];
|
|
10
|
+
export declare function createBatchClient(process: ChildProcess | NodeJS.Process, { expectedVersion, channel }?: {
|
|
11
|
+
expectedVersion?: `${number}.${number}.${number}`;
|
|
12
|
+
channel?: string;
|
|
13
|
+
}): [client: DelightRPC.BatchClient, close: () => void];
|
|
6
14
|
export declare class ClientClosed extends CustomError {
|
|
7
15
|
}
|
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.createClient = void 0;
|
|
26
|
+
exports.ClientClosed = exports.createBatchClient = exports.createClient = 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 createClient(process, parameterValidators, expectedVersion) {
|
|
30
|
+
function createClient(process, { parameterValidators, expectedVersion, channel } = {}) {
|
|
27
31
|
const pendings = {};
|
|
28
32
|
process.on('message', handler);
|
|
29
33
|
const client = DelightRPC.createClient(async function send(request) {
|
|
@@ -36,7 +40,11 @@ function createClient(process, 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
|
process.off('message', handler);
|
|
@@ -52,6 +60,38 @@ function createClient(process, parameterValidators, expectedVersion) {
|
|
|
52
60
|
}
|
|
53
61
|
}
|
|
54
62
|
exports.createClient = createClient;
|
|
63
|
+
function createBatchClient(process, { expectedVersion, channel } = {}) {
|
|
64
|
+
const pendings = {};
|
|
65
|
+
process.on('message', handler);
|
|
66
|
+
const client = new DelightRPC.BatchClient(async function send(request) {
|
|
67
|
+
const res = new extra_promise_1.Deferred();
|
|
68
|
+
pendings[request.id] = res;
|
|
69
|
+
try {
|
|
70
|
+
process.send(request);
|
|
71
|
+
return await res;
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
delete pendings[request.id];
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
77
|
+
expectedVersion,
|
|
78
|
+
channel
|
|
79
|
+
});
|
|
80
|
+
return [client, close];
|
|
81
|
+
function close() {
|
|
82
|
+
process.off('message', handler);
|
|
83
|
+
for (const [key, deferred] of Object.entries(pendings)) {
|
|
84
|
+
deferred.reject(new ClientClosed());
|
|
85
|
+
delete pendings[key];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function handler(res) {
|
|
89
|
+
if (DelightRPC.isError(res) || DelightRPC.isBatchResponse(res)) {
|
|
90
|
+
pendings[res.id].resolve(res);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.createBatchClient = createBatchClient;
|
|
55
95
|
class ClientClosed extends errors_1.CustomError {
|
|
56
96
|
}
|
|
57
97
|
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;AAEzC,iDAAwC;AACxC,+CAAgD;AAGhD,SAAgB,YAAY,CAC1B,OAAsC,EACtC,EAAE,mBAAmB,EAAE,eAAe,EAAE,OAAO,KAI3C,EAAE;IAEN,MAAM,QAAQ,GAAmD,EAAE,CAAA;IAEnE,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAE9B,MAAM,MAAM,GAAG,UAAU,CAAC,YAAY,CACpC,KAAK,UAAU,IAAI,CAAC,OAA0B;QAC5C,MAAM,GAAG,GAAG,IAAI,wBAAQ,EAAsB,CAAA;QAC9C,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,GAAG,CAAA;QAC1B,IAAI;YACF,OAAO,CAAC,IAAK,CAAC,OAAO,CAAC,CAAA;YACtB,OAAO,MAAM,GAAG,CAAA;SACjB;gBAAS;YACR,OAAO,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;SAC5B;IACH,CA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AO;KACR,CACF,CAAA;IAED,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;IAEtB,SAAS,KAAK;QACZ,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAE/B,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,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAA;SACrB;IACH,CAAC;IAED,SAAS,OAAO,CAAC,GAAQ;QACvB,IAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,eAAe,CAAC,GAAG,CAAC,EAAE;YAC9D,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;SAC9B;IACH,CAAC;AACH,CAAC;AAjDD,8CAiDC;AAED,MAAa,YAAa,SAAQ,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,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as DelightRPC from 'delight-rpc';
|
|
3
3
|
import { ChildProcess } from 'child_process';
|
|
4
|
-
export declare function createServer<IAPI extends object>(api: DelightRPC.ImplementationOf<IAPI>, process: ChildProcess | NodeJS.Process, parameterValidators
|
|
4
|
+
export declare function createServer<IAPI extends object>(api: DelightRPC.ImplementationOf<IAPI>, process: ChildProcess | NodeJS.Process, { parameterValidators, version, channel }?: {
|
|
5
|
+
parameterValidators?: DelightRPC.ParameterValidators<IAPI>;
|
|
6
|
+
version?: `${number}.${number}.${number}`;
|
|
7
|
+
channel?: string;
|
|
8
|
+
}): () => 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,13 +25,20 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
26
|
exports.createServer = void 0;
|
|
23
27
|
const DelightRPC = __importStar(require("delight-rpc"));
|
|
24
|
-
|
|
28
|
+
const prelude_1 = require("@blackglory/prelude");
|
|
29
|
+
function createServer(api, process, { parameterValidators, version, channel } = {}) {
|
|
25
30
|
process.on('message', handler);
|
|
26
31
|
return () => process.off('message', handler);
|
|
27
32
|
async function handler(req) {
|
|
28
|
-
if (DelightRPC.isRequest(req)) {
|
|
29
|
-
const result = await DelightRPC.createResponse(api, req,
|
|
30
|
-
|
|
33
|
+
if (DelightRPC.isRequest(req) || DelightRPC.isBatchRequest(req)) {
|
|
34
|
+
const result = await DelightRPC.createResponse(api, req, {
|
|
35
|
+
parameterValidators,
|
|
36
|
+
version,
|
|
37
|
+
channel
|
|
38
|
+
});
|
|
39
|
+
if ((0, prelude_1.isntNull)(result)) {
|
|
40
|
+
process.send(result);
|
|
41
|
+
}
|
|
31
42
|
}
|
|
32
43
|
}
|
|
33
44
|
}
|
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,YAAY,CAC1B,GAAsC,EACtC,OAAsC,EACtC,EAAE,mBAAmB,EAAE,OAAO,EAAE,OAAO,KAInC,EAAE;IAEN,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAC9B,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAE5C,KAAK,UAAU,OAAO,CAAC,GAAQ;QAC7B,IAAI,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE;YAC/D,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,cAAc,CAC5C,GAAG,EACH,GAAG,EACH;gBACE,mBAAmB;gBACnB,OAAO;gBACP,OAAO;aACR,CACF,CAAA;YAED,IAAI,IAAA,kBAAQ,EAAC,MAAM,CAAC,EAAE;gBACpB,OAAO,CAAC,IAAK,CAAC,MAAM,CAAC,CAAA;aACtB;SACF;IACH,CAAC;AACH,CAAC;AA7BD,oCA6BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delight-rpc/child-process",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"files": [
|
|
@@ -29,33 +29,35 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@blackglory/jest-matchers": "^0.
|
|
33
|
-
"@commitlint/cli": "^16.
|
|
34
|
-
"@commitlint/config-conventional": "^16.
|
|
35
|
-
"@types/jest": "^27.
|
|
32
|
+
"@blackglory/jest-matchers": "^0.3.1",
|
|
33
|
+
"@commitlint/cli": "^16.2.4",
|
|
34
|
+
"@commitlint/config-conventional": "^16.2.4",
|
|
35
|
+
"@types/jest": "^27.5.0",
|
|
36
36
|
"@types/node": "14",
|
|
37
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
38
|
-
"@typescript-eslint/parser": "^5.
|
|
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": "^
|
|
41
|
-
"eslint": "8.
|
|
40
|
+
"delight-rpc": "^4.0.0",
|
|
41
|
+
"eslint": "8.15.0",
|
|
42
42
|
"husky": "4",
|
|
43
43
|
"jest": "^27.5.1",
|
|
44
44
|
"npm-run-all": "^4.1.5",
|
|
45
|
-
"return-style": "^0.
|
|
45
|
+
"return-style": "^1.0.0",
|
|
46
46
|
"rimraf": "^3.0.2",
|
|
47
47
|
"standard-version": "^9.3.2",
|
|
48
|
-
"ts-jest": "^27.1.
|
|
49
|
-
"ts-node": "^10.
|
|
48
|
+
"ts-jest": "^27.1.4",
|
|
49
|
+
"ts-node": "^10.7.0",
|
|
50
50
|
"ts-patch": "^2.0.1",
|
|
51
|
-
"typescript": "^4.
|
|
51
|
+
"typescript": "^4.6.4",
|
|
52
52
|
"typescript-transform-paths": "^3.3.1"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@blackglory/errors": "^2.2.
|
|
56
|
-
"
|
|
55
|
+
"@blackglory/errors": "^2.2.1",
|
|
56
|
+
"@blackglory/prelude": "^0.1.1",
|
|
57
|
+
"@delight-rpc/protocol": "^2.2.0",
|
|
58
|
+
"extra-promise": "^1.0.2"
|
|
57
59
|
},
|
|
58
60
|
"peerDependencies": {
|
|
59
|
-
"delight-rpc": "^2.
|
|
61
|
+
"delight-rpc": "^2.1.1"
|
|
60
62
|
}
|
|
61
63
|
}
|