@delight-rpc/piscina 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 BlackGlory <woshenmedoubuzhidao@blackglory.me>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # @delight-rpc/piscina
2
+ ## Install
3
+ ```sh
4
+ npm install --save @delight-rpc/piscina
5
+ # or
6
+ yarn add @delight-rpc/piscina
7
+ ```
8
+
9
+ ## Usage
10
+ ```ts
11
+ // api.d.ts
12
+ interface IAPI {
13
+ echo(message: string): string
14
+ }
15
+
16
+ // worker.ts
17
+ import { createServer } from '@delight-rpc/piscina'
18
+
19
+ const api: IAPI = {
20
+ echo(message: string): string {
21
+ return message
22
+ }
23
+ }
24
+
25
+ export default createServer(api)
26
+
27
+ // main.ts
28
+ import { createClient } from '@delight-rpc/piscina'
29
+
30
+ const piscina = new Piscina({
31
+ filename: new URL('./worker.js', import.meta.url).href
32
+ })
33
+ const client = createClient<IAPI>(piscina)
34
+
35
+ await client.echo('hello world')
36
+ ```
37
+
38
+ ## API
39
+ ### createClient
40
+ ```ts
41
+ function createClient<IAPI extends object>(
42
+ piscina: Piscina
43
+ , parameterValidators?: DelightRPC.ParameterValidators<IAPI>
44
+ ): DelightRPC.ClientProxy<IAPI>
45
+ ```
46
+
47
+ ### createServer
48
+ ```ts
49
+ function createServer<IAPI extends object>(
50
+ api: IAPI
51
+ , parameterValidators?: DelightRPC.ParameterValidators<IAPI>
52
+ ): (req: any) => Promise<any>
53
+ ```
@@ -0,0 +1,3 @@
1
+ import * as DelightRPC from 'delight-rpc';
2
+ import Piscina from 'piscina';
3
+ export declare function createClient<IAPI extends object>(piscina: Piscina, parameterValidators?: DelightRPC.ParameterValidators<IAPI>): DelightRPC.ClientProxy<IAPI>;
package/lib/client.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.createClient = void 0;
23
+ const DelightRPC = __importStar(require("delight-rpc"));
24
+ function createClient(piscina, parameterValidators) {
25
+ const client = DelightRPC.createClient(async function send(request) {
26
+ return await piscina.run(request);
27
+ }, parameterValidators);
28
+ return client;
29
+ }
30
+ exports.createClient = createClient;
31
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAyC;AAGzC,SAAgB,YAAY,CAC1B,OAAgB,EAChB,mBAA0D;IAE1D,MAAM,MAAM,GAAG,UAAU,CAAC,YAAY,CACpC,KAAK,UAAU,IAAI,CAAC,OAAO;QACzB,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IACnC,CAAC,EACD,mBAAmB,CACpB,CAAA;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAZD,oCAYC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './client';
2
+ export * from './server';
package/lib/index.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./client"), exports);
14
+ __exportStar(require("./server"), exports);
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAwB;AACxB,2CAAwB"}
@@ -0,0 +1,2 @@
1
+ import * as DelightRPC from 'delight-rpc';
2
+ export declare function createServer<IAPI extends object>(api: IAPI, parameterValidators?: DelightRPC.ParameterValidators<IAPI>): (req: any) => Promise<any>;
package/lib/server.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.createServer = void 0;
23
+ const DelightRPC = __importStar(require("delight-rpc"));
24
+ function createServer(api, parameterValidators) {
25
+ return async function handler(req) {
26
+ if (DelightRPC.isRequest(req)) {
27
+ const result = await DelightRPC.createResponse(api, req, parameterValidators);
28
+ return result;
29
+ }
30
+ };
31
+ }
32
+ exports.createServer = createServer;
33
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,wDAAyC;AAEzC,SAAgB,YAAY,CAC1B,GAAS,EACT,mBAA0D;IAE1D,OAAO,KAAK,UAAU,OAAO,CAAC,GAAQ;QACpC,IAAI,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE;YAC7B,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,mBAAmB,CAAC,CAAA;YAC7E,OAAO,MAAM,CAAA;SACd;IACH,CAAC,CAAA;AACH,CAAC;AAVD,oCAUC"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@delight-rpc/piscina",
3
+ "version": "0.1.0",
4
+ "description": "",
5
+ "keywords": [],
6
+ "files": [
7
+ "lib"
8
+ ],
9
+ "main": "lib/index.js",
10
+ "types": "lib/index.d.ts",
11
+ "repository": "git@github.com:delight-rpc/piscina.git",
12
+ "author": "BlackGlory <woshenmedoubuzhidao@blackglory.me>",
13
+ "license": "MIT",
14
+ "scripts": {
15
+ "prepare": "ts-patch install -s",
16
+ "lint": "eslint --ext .js,.jsx,.ts,.tsx --quiet src",
17
+ "test": "jest --no-cache --config jest.config.js",
18
+ "test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
19
+ "test:coverage": "jest --coverage --config jest.config.js",
20
+ "prepublishOnly": "run-s clean build",
21
+ "clean": "rimraf lib",
22
+ "build": "cross-env NODE_ENV=production tsc --project tsconfig.build.json",
23
+ "release": "standard-version"
24
+ },
25
+ "husky": {
26
+ "hooks": {
27
+ "pre-commit": "run-s prepare lint build test",
28
+ "commit-msg": "commitlint --env HUSKY_GIT_PARAMS"
29
+ }
30
+ },
31
+ "devDependencies": {
32
+ "@blackglory/jest-matchers": "^0.2.1",
33
+ "@commitlint/cli": "^16.0.1",
34
+ "@commitlint/config-conventional": "^16.0.0",
35
+ "@types/jest": "^27.4.0",
36
+ "@types/node": "14",
37
+ "@typescript-eslint/eslint-plugin": "^5.9.0",
38
+ "@typescript-eslint/parser": "^5.9.0",
39
+ "cross-env": "^7.0.3",
40
+ "delight-rpc": "^1.2.0",
41
+ "eslint": "8.6.0",
42
+ "husky": "4",
43
+ "jest": "^27.4.5",
44
+ "npm-run-all": "^4.1.5",
45
+ "piscina": "^3.2.0",
46
+ "return-style": "^0.12.5",
47
+ "rimraf": "^3.0.2",
48
+ "standard-version": "^9.3.2",
49
+ "ts-jest": "^27.1.2",
50
+ "ts-node": "^10.4.0",
51
+ "ts-patch": "^2.0.1",
52
+ "typescript": "^4.5.4",
53
+ "typescript-transform-paths": "^3.3.1"
54
+ },
55
+ "peerDependencies": {
56
+ "delight-rpc": "^1.2.0",
57
+ "piscina": "^3.2.0"
58
+ }
59
+ }