Comparing version 0.2.0 to 1.0.0-rc.1
{ | ||
"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; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80489
14
1446
110
3
20
1
+ Added@sinclair/typebox@^0.12.9
+ Addedajv@^7.1.1
+ Added@sinclair/typebox@0.12.9(transitive)
+ Addedajv@7.2.4(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedjson-schema-traverse@1.0.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedrequire-from-string@2.0.2(transitive)
+ Addeduri-js@4.4.1(transitive)