Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

waitsocket

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

waitsocket - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0-rc.1

dist/AbstractWaitSocket.d.ts

7

package.json
{
"name": "waitsocket",
"version": "0.2.0",
"version": "1.0.0-rc.1",
"description": "Library for better handling WebSocket interactions and waiting for response messages",
"main": "dist/index.js",
"main": "dist/WaitSocket.js",
"scripts": {

@@ -24,2 +24,4 @@ "build": "tsc -d",

"dependencies": {
"@sinclair/typebox": "^0.12.9",
"ajv": "^7.1.1",
"nanoid": "^3.1.20"

@@ -39,2 +41,3 @@ },

"eslint-plugin-react-hooks": "^4.0.0",
"get-port": "^5.1.1",
"husky": "^5.1.0",

@@ -41,0 +44,0 @@ "jest": "^26.6.3",

@@ -73,6 +73,10 @@ # WaitSocket.js

## API
## JSONSchema Validation
### constructor
You can define JSONSchema for each type of your incoming and outgoing messages. For incoming messages, validation process original deserialized message (before any interceptors). For outgoing messages, validation process resulting message (after all interceptors, but before serialization, of course).
```javascript
this.waitSocket.addIncomingJSONSchema('MESSAGE_TYPE', jsonSchemaObject);
```
## Customization

@@ -82,22 +86,22 @@

* `addType(messageObject: PlainObject, type: string)` - Returns message object with type in it.
* `getType(messageObject: PlainObject): string` - Returns message type.
* `addPayload(messageObject: PlainObject, payload?: any)` - Returns message object with payload in it.
* `getPayload(messageObject: PlainObject): any` - Returns message payload.
* `addRequestId(messageObject: PlainObject, requestId?: string)` - Returns message object with requestId meta data.
* `getRequestId(messageObject: PlainObject)` - Returns message requestId meta data.
* `getType(messageObject: MessageType): string` - Returns message type.
* `getPayload(messageObject: MessageType): any` - Returns message payload.
* `getRequestId(messageObject: MessageType): string` - Returns message requestId meta data.
* `getMessageObject(type: string, payload?: any, requestId?: string): MessageType;` - Returns message object with type, payload and requestId in it.
Example (use `body` parameter instead of `payload`):
```typescript
class myWaitSocket extends WaitSocket {
protected addPayload(messageObject: PlainObject, payload?: PlainObject) {
if (!body) {
return { ...messageObject };
class myWaitSocket extends AbstractWaitSocket<MyMessageType> {
protected getMessageObject(type: string, payload?: any, requestId?: string) {
const result: DefaultMessageType = { type };
if (payload) {
result.body = payload;
}
return {
...messageObject,
body: payload,
};
if (requestId) {
result.meta = { requestId };
}
return result;
}
public getPayload(messageObject: PlainObject) {

@@ -104,0 +108,0 @@ return messageObject.body;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc