Define JSON schemas in TypeScript interfaces in core.md

This commit is contained in:
ChronosX88 2019-12-15 19:04:56 +04:00
parent b831bf7f2a
commit fc7657d338
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
2 changed files with 116 additions and 23 deletions

View File

@ -37,13 +37,37 @@ For starting we simply use JSON + Websockets.
BaseMessage is a basic message model, basis of the whole protocol. It is used for a very easy protocol extension process. BaseMessage is a basic message model, basis of the whole protocol. It is used for a very easy protocol extension process.
BaseMessage scheme: BaseMessage scheme:
``` ```typescript
id (string) - message identifier (used to track the request-response chain) interface BaseMessage {
type (string) - type of message (used to determine which extension this message belongs to) /**
from (EntityID) - from which entity this message is send * Message identifier (used to track the request-response chain)
to (EntityID) - message recipient */
ok (boolean) - operation success indicator (used to determine if the error happened while processing request) id: string, //
payload (Map<K,V>) - message payload (used to store extra information in message, list of permissible fields in the payload depends on "type" field)
/**
* Type of message (used to determine which extension this message belongs to)
*/
type: string, //
/**
* From which entity this message is send
*/
from: EntityID, //
/**
* Message recipient
*/
to: EntityID, //
/**
* Operation success indicator (used to determine if the error happened while processing request)
*/
ok: boolean, //
/**
* Message payload (used to store extra information in message, list of permissible fields in the payload depends on "type" field)
*/
payload: Map<K,V> //
}
``` ```
## Errors ## Errors
@ -51,9 +75,24 @@ Mechanism of error processing included into protocol.
Adds into type name `:error` postfix. Adds into type name `:error` postfix.
**Payload**: **Payload**:
* `errCode: int` - error code (defined in extensions, may be same per extensions) ```typescript
* `errText: String` - explanation of error in human-readable view interface ErrorPayload {
* `errPayload: Map<K,V>` - advanced error information (fields defined in extensions) /**
* Error code (defined in extensions, may be same per extensions)
*/
errCode: number,
/**
* Explanation of error in human-readable view
*/
errText: string,
/**
* Advanced error information (fields defined in extensions)
*/
errPayload: Map<K,V>
}
```
**Usecase**: **Usecase**:
@ -93,14 +132,46 @@ Adds into type name `:error` postfix.
**Description**: Create user account on a server **Description**: Create user account on a server
**Type**: `profile:register` **Type**: `profile:register`
**Payload**: **Payload**:
- Request: - Request:
- `username: string` - the username that the user wants to register ```typescript
- `thirdPIDs: []` - array of user third party IDs (email and/or MSISDN). Array contains objects with following fields: interface RegistrationRequestPayload {
- `type: string` - type of third party ID. /**
- `value: string` - string contains third party ID. Examples: `juliet@capulett.com`, `+1234567890`. * The username that the user wants to register
- `password: string` - password of new account */
username: string,
/**
* Array of user third party IDs (email and/or MSISDN)
*/
thirdPIDs: ThirdPartyID[],
/**
* Password of new account
*/
password: string
}
interface ThirdPartyID {
/**
* Type of third party ID
*/
type: string,
/**
* String contains third party ID. Examples: "juliet@capulett.com", "+1234567890".
*/
value: string
}
```
- Response: - Response:
- `userID: EntityID`- ID of user (Username in priority. If we haven't username, then we put to this field one of user's third party IDs). ```typescript
interface RegistrationResponsePayload {
/**
* ID of user (Username in priority. If we haven't username, then we put to this field one of user's third party IDs)
*/
userID: EntityID
}
```
**Errors**: **Errors**:
- 0: limit exceed - 0: limit exceed
@ -159,12 +230,34 @@ Adds into type name `:error` postfix.
**Description**: Login into user account on a server by username **Description**: Login into user account on a server by username
**Type**: `profile:login` **Type**: `profile:login`
**Payload**: **Payload**:
- Request: - Request:
- `username: string` - the username of account which user wants to login ```typescript
- `password: string` - password of new account interface LoginRequestPayload {
/**
* The username of account which user wants to login
*/
username: string,
/**
* Password of new account
*/
password: string
}
```
- Response: - Response:
- `authToken: string` - authentication token which required for various user actions (UUID) ```typescript
- `deviceID: string` - identifier of new user device (created by this login action) interface LoginResponsePayload {
/**
* Authentication token which required for various user actions (UUID)
*/
authToken: string,
/**
* Identifier of new user device (created by this login action)
*/
deviceID: string
}
```
**Errors**: **Errors**:
- 0: limit exceed - 0: limit exceed

View File

@ -31,7 +31,7 @@
"examples": [ "examples": [
"Incorrect type of message (type isn't implemented in the server)", "Incorrect type of message (type isn't implemented in the server)",
"Rate-limit exceed" "Rate-limit exceed"
], ]
}, },
"errPayload": { "errPayload": {
"$id": "#/properties/errPayload", "$id": "#/properties/errPayload",