update tsconfig
This commit is contained in:
parent
a44496ab56
commit
c0005e76c7
@ -7,14 +7,23 @@
|
|||||||
"shortDescription": "node inter process communication",
|
"shortDescription": "node inter process communication",
|
||||||
"npmPackagename": "@push.rocks/smartipc",
|
"npmPackagename": "@push.rocks/smartipc",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks"
|
"projectDomain": "push.rocks",
|
||||||
|
"description": "A library for node inter process communication, providing an easy-to-use API for IPC.",
|
||||||
|
"keywords": [
|
||||||
|
"IPC",
|
||||||
|
"node.js",
|
||||||
|
"inter-process communication",
|
||||||
|
"event-driven",
|
||||||
|
"client-server",
|
||||||
|
"message passing"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [],
|
"npmGlobalTools": [],
|
||||||
"npmAccessLevel": "public"
|
"npmAccessLevel": "public"
|
||||||
},
|
},
|
||||||
"tsdocs": {
|
"tsdoc": {
|
||||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
12
package.json
12
package.json
@ -2,7 +2,7 @@
|
|||||||
"name": "@push.rocks/smartipc",
|
"name": "@push.rocks/smartipc",
|
||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "node inter process communication",
|
"description": "A library for node inter process communication, providing an easy-to-use API for IPC.",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
@ -27,5 +27,13 @@
|
|||||||
"@pushrocks/smartrx": "^2.0.3",
|
"@pushrocks/smartrx": "^2.0.3",
|
||||||
"@types/node-ipc": "^9.1.1",
|
"@types/node-ipc": "^9.1.1",
|
||||||
"node-ipc": "^9.1.1"
|
"node-ipc": "^9.1.1"
|
||||||
}
|
},
|
||||||
|
"keywords": [
|
||||||
|
"IPC",
|
||||||
|
"node.js",
|
||||||
|
"inter-process communication",
|
||||||
|
"event-driven",
|
||||||
|
"client-server",
|
||||||
|
"message passing"
|
||||||
|
]
|
||||||
}
|
}
|
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
174
readme.md
174
readme.md
@ -1,26 +1,164 @@
|
|||||||
# @pushrocks/smartipc
|
# @push.rocks/smartipc
|
||||||
node inter process communication
|
node inter process communication
|
||||||
|
|
||||||
## Availabililty and Links
|
## Install
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartipc)
|
To install @push.rocks/smartipc, use the following command with npm:
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartipc)
|
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartipc)
|
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartipc/)
|
|
||||||
|
|
||||||
## Status for master
|
```bash
|
||||||
[![build status](https://gitlab.com/pushrocks/smartipc/badges/master/build.svg)](https://gitlab.com/pushrocks/smartipc/commits/master)
|
npm install @push.rocks/smartipc --save
|
||||||
[![coverage report](https://gitlab.com/pushrocks/smartipc/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartipc/commits/master)
|
```
|
||||||
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartipc.svg)](https://www.npmjs.com/package/@pushrocks/smartipc)
|
|
||||||
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartipc/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartipc)
|
This command adds `@push.rocks/smartipc` to your project's dependencies.
|
||||||
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
|
||||||
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
`@push.rocks/smartipc` simplifies inter-process communication (IPC) in Node.js applications, wrapping the complexity of IPC setup into an easy-to-use API. It supports both server and client roles within IPC, allowing processes to communicate with each other efficiently. Below, you'll find comprehensive guides and examples to quickly incorporate `smartipc` into your Node.js projects.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
### Getting Started
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
|
||||||
|
|
||||||
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)
|
First, import `SmartIpc` from `@push.rocks/smartipc` in your TypeScript file:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { SmartIpc } from '@push.rocks/smartipc';
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setting Up a Server
|
||||||
|
|
||||||
|
To set up an IPC server, create an instance of `SmartIpc` with the type set to `'server'`. Define a unique `ipcSpace` name, which serves as the namespace for your IPC communication.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const serverIpc = new SmartIpc({
|
||||||
|
type: 'server',
|
||||||
|
ipcSpace: 'myUniqueIpcSpace'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Registering Handlers
|
||||||
|
|
||||||
|
Before starting your server, register message handlers. These handlers listen for specific keywords and execute corresponding functions when messages arrive.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
serverIpc.registerHandler({
|
||||||
|
keyword: 'greeting',
|
||||||
|
handlerFunc: (dataArg: string) => {
|
||||||
|
console.log(`Received greeting: ${dataArg}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Starting the Server
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
(async () => {
|
||||||
|
await serverIpc.start();
|
||||||
|
console.log('IPC Server started!');
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Setting Up a Client
|
||||||
|
|
||||||
|
Setting up a client is similar to setting up a server. Create a `SmartIpc` instance with the type set to `'client'` and use the same `ipcSpace` name used for the server.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const clientIpc = new SmartIpc({
|
||||||
|
type: 'client',
|
||||||
|
ipcSpace: 'myUniqueIpcSpace'
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Starting the Client
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
(async () => {
|
||||||
|
await clientIpc.start();
|
||||||
|
console.log('IPC Client connected!');
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sending Messages
|
||||||
|
|
||||||
|
Once the client and server are set up and running, you can send messages using `sendMessage`. Specify the message identifier and the message content. The server will receive this message and process it using the registered handler.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// From the client
|
||||||
|
clientIpc.sendMessage('greeting', 'Hello from the client!');
|
||||||
|
```
|
||||||
|
|
||||||
|
### Clean Up
|
||||||
|
|
||||||
|
It's a good practice to gracefully stop the IPC server and client when they're no longer needed.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Stopping the client
|
||||||
|
(async () => {
|
||||||
|
await clientIpc.stop();
|
||||||
|
console.log('IPC Client disconnected!');
|
||||||
|
})();
|
||||||
|
|
||||||
|
// Stopping the server
|
||||||
|
(async () => {
|
||||||
|
await serverIpc.stop();
|
||||||
|
console.log('IPC Server stopped!');
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Advanced Usage
|
||||||
|
|
||||||
|
#### Handling JSON Messages
|
||||||
|
|
||||||
|
While `@push.rocks/smartipc` allows sending strings directly, you might often need to send structured data. The `sendMessage` method can handle objects by converting them to JSON strings before sending.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Sending an object from the client
|
||||||
|
clientIpc.sendMessage('data', { key: 'value' });
|
||||||
|
|
||||||
|
// Server handler for 'data'
|
||||||
|
serverIpc.registerHandler({
|
||||||
|
keyword: 'data',
|
||||||
|
handlerFunc: (dataArg: string) => {
|
||||||
|
const dataObject = JSON.parse(dataArg);
|
||||||
|
console.log(dataObject.key); // Outputs: value
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Error Handling
|
||||||
|
|
||||||
|
Always include error handling in production applications to manage unexpected scenarios, such as disconnection or message parsing errors.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// Example of adding error handling to the server start process
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
await serverIpc.start();
|
||||||
|
console.log('IPC Server started!');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to start IPC Server:', error);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
```
|
||||||
|
|
||||||
|
### Conclusion
|
||||||
|
|
||||||
|
Integrating `@push.rocks/smartipc` into your Node.js applications streamlines the process of setting up IPC for inter-process communication. Through the examples provided, you've seen how to configure both servers and clients, register message handlers, send messages, and incorporate error handling. With `smartipc`, you can facilitate robust communication channels between different parts of your application, enhancing modularity and process isolation.
|
||||||
|
|
||||||
|
For further information and advanced configuration options, refer to the `@push.rocks/smartipc` documentation.
|
||||||
|
|
||||||
|
## License and Legal Information
|
||||||
|
|
||||||
|
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||||
|
|
||||||
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
### Trademarks
|
||||||
|
|
||||||
|
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||||
|
|
||||||
|
### Company Information
|
||||||
|
|
||||||
|
Task Venture Capital GmbH
|
||||||
|
Registered at District court Bremen HRB 35230 HB, Germany
|
||||||
|
|
||||||
|
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||||
|
|
||||||
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||||
|
Loading…
Reference in New Issue
Block a user