ferrum-db-client
Advanced tools
Comparing version 0.2.14 to 0.2.15
@@ -116,4 +116,4 @@ "use strict"; | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -120,0 +120,0 @@ } |
@@ -32,4 +32,4 @@ "use strict"; | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -50,4 +50,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -73,4 +73,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -90,4 +90,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -116,4 +116,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -120,0 +120,0 @@ } |
@@ -23,4 +23,4 @@ "use strict"; | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -42,4 +42,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -59,4 +59,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -75,4 +75,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -90,4 +90,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -111,4 +111,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -130,4 +130,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -146,4 +146,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -162,4 +162,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -177,4 +177,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -199,4 +199,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -218,4 +218,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -235,4 +235,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -251,4 +251,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -266,4 +266,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -286,4 +286,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -290,0 +290,0 @@ } |
@@ -12,2 +12,3 @@ /// <reference types="node" /> | ||
getRecordCount(): Promise<number>; | ||
getOrNull(key: string): Promise<T | null>; | ||
get(key: string): Promise<T>; | ||
@@ -14,0 +15,0 @@ delete(key: string): Promise<void>; |
@@ -22,4 +22,4 @@ "use strict"; | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -39,4 +39,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -56,4 +56,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -66,2 +66,26 @@ } | ||
} | ||
async getOrNull(key) { | ||
const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.INDEX_GET, this.database.length + this.collectionKey.length + key.length + 12); | ||
bw.writeString(this.database, csharp_binary_stream_1.Encoding.Utf8); | ||
bw.writeString(this.collectionKey, csharp_binary_stream_1.Encoding.Utf8); | ||
bw.writeString(key, csharp_binary_stream_1.Encoding.Utf8); | ||
this.client.sendMsg(bw); | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readByte(); | ||
if (success === 0) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
} | ||
else if (success === 1) { | ||
try { | ||
return (0, utils_1.readEncodedData)(br, this.encoding, this.compression); | ||
} | ||
catch (e) { | ||
throw new Error(`Failed to get ${key} from ${this.collectionKey} \n\nCaused by: ${e}`); | ||
} | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
async get(key) { | ||
@@ -75,4 +99,4 @@ const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.INDEX_GET, this.database.length + this.collectionKey.length + key.length + 12); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -97,4 +121,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -116,4 +140,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -142,4 +166,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -158,4 +182,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -174,4 +198,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -178,0 +202,0 @@ } |
@@ -7,2 +7,7 @@ import { FerrumServerClient } from './client'; | ||
export { SetRemote } from './set_remote'; | ||
export interface ServerConnectionInfo { | ||
connectedSince: Date; | ||
messgesSent: number; | ||
messagesPerMinute: number; | ||
} | ||
export declare function ferrumConnect(ip: string, port: number, options?: { | ||
@@ -15,2 +20,5 @@ heartbeatTimeout: number; | ||
reconnect(): Promise<void>; | ||
getServerConnections(): Promise<string[]>; | ||
getServerConnectionInfo(id: string): Promise<ServerConnectionInfo>; | ||
kickConnection(id: string): Promise<void>; | ||
disconnect(): void; | ||
@@ -17,0 +25,0 @@ createDatabaseIfNotExists(dbName: string): Promise<FerrumDBRemote>; |
@@ -34,2 +34,55 @@ "use strict"; | ||
} | ||
async getServerConnections() { | ||
const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.GET_CONNECTIONS, 4); | ||
this.client.sendMsg(bw); | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
} | ||
else { | ||
const len = br.readInt(); | ||
const result = new Array(len); | ||
for (let i = 0; i < len; i++) { | ||
result[i] = br.readString(csharp_binary_stream_1.Encoding.Utf8); | ||
} | ||
return result; | ||
} | ||
} | ||
async getServerConnectionInfo(id) { | ||
const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.GET_CONNECTION_INFO, id.length + 4); | ||
bw.writeString(id, csharp_binary_stream_1.Encoding.Utf8); | ||
this.client.sendMsg(bw); | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
} | ||
else { | ||
const messgesSent = br.readLong(); | ||
const messagesPerMinute = br.readLong(); | ||
const connectedSince = new Date(br.readLong()); | ||
return { | ||
connectedSince, | ||
messgesSent, | ||
messagesPerMinute, | ||
}; | ||
} | ||
} | ||
async kickConnection(id) { | ||
const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.KICK_CONNECTION, id.length); | ||
bw.writeString(id, csharp_binary_stream_1.Encoding.Utf8); | ||
this.client.sendMsg(bw); | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
} | ||
else { | ||
return; | ||
} | ||
} | ||
disconnect() { | ||
@@ -44,4 +97,4 @@ this.client.disconnect(); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -59,4 +112,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -74,4 +127,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -89,4 +142,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -104,4 +157,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -116,4 +169,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -120,0 +173,0 @@ } |
@@ -67,4 +67,7 @@ export declare enum ApiMessageType { | ||
COLLECTION_SET_TAG = 64, | ||
COLLECTION_GET_TAG_ENTRY = 65 | ||
COLLECTION_GET_TAG_ENTRY = 65, | ||
GET_CONNECTIONS = 66, | ||
GET_CONNECTION_INFO = 67, | ||
KICK_CONNECTION = 68 | ||
} | ||
//# sourceMappingURL=protcol.d.ts.map |
@@ -72,3 +72,6 @@ "use strict"; | ||
ApiMessageType[ApiMessageType["COLLECTION_GET_TAG_ENTRY"] = 65] = "COLLECTION_GET_TAG_ENTRY"; | ||
ApiMessageType[ApiMessageType["GET_CONNECTIONS"] = 66] = "GET_CONNECTIONS"; | ||
ApiMessageType[ApiMessageType["GET_CONNECTION_INFO"] = 67] = "GET_CONNECTION_INFO"; | ||
ApiMessageType[ApiMessageType["KICK_CONNECTION"] = 68] = "KICK_CONNECTION"; | ||
})(ApiMessageType = exports.ApiMessageType || (exports.ApiMessageType = {})); | ||
//# sourceMappingURL=protcol.js.map |
@@ -20,4 +20,4 @@ "use strict"; | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -36,4 +36,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -58,4 +58,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -74,4 +74,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -91,4 +91,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -107,4 +107,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -111,0 +111,0 @@ } |
@@ -9,2 +9,3 @@ import { FerrumServerClient } from './client'; | ||
hasSerie(serie: string): Promise<boolean>; | ||
getEntryOrNull(serie: string, timestamp: number): Promise<T | null>; | ||
getEntry(serie: string, timestamp: number): Promise<T>; | ||
@@ -11,0 +12,0 @@ hasEntry(serie: string, timestamp: number): Promise<boolean>; |
@@ -22,4 +22,4 @@ "use strict"; | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -31,2 +31,27 @@ } | ||
} | ||
async getEntryOrNull(serie, timestamp) { | ||
const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.TIME_SERIES_GET_ENTRY, this.database.length + this.collectionKey.length + 8 + serie.length + 12); | ||
bw.writeString(this.database, csharp_binary_stream_1.Encoding.Utf8); | ||
bw.writeString(this.collectionKey, csharp_binary_stream_1.Encoding.Utf8); | ||
bw.writeString(serie, csharp_binary_stream_1.Encoding.Utf8); | ||
bw.writeLong(timestamp); | ||
this.client.sendMsg(bw); | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readByte(); | ||
if (success === 0) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
} | ||
else if (success === 1) { | ||
try { | ||
return (0, utils_1.readEncodedData)(br, this.encoding, this.compression); | ||
} | ||
catch (e) { | ||
throw new Error(`Failed to get ${serie} from ${this.collectionKey} \n\nCaused by: ${e}`); | ||
} | ||
} | ||
else { | ||
return null; | ||
} | ||
} | ||
async getEntry(serie, timestamp) { | ||
@@ -41,4 +66,4 @@ const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.TIME_SERIES_GET_ENTRY, this.database.length + this.collectionKey.length + 8 + serie.length + 12); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -64,4 +89,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -82,4 +107,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -97,4 +122,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -124,4 +149,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -147,4 +172,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -170,4 +195,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -193,4 +218,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -215,4 +240,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -237,4 +262,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -260,4 +285,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -283,4 +308,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -306,4 +331,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -330,4 +355,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -352,4 +377,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -377,4 +402,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -393,4 +418,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -409,4 +434,4 @@ } | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
@@ -413,0 +438,0 @@ } |
{ | ||
"name": "ferrum-db-client", | ||
"version": "0.2.14", | ||
"version": "0.2.15", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "typings": "dist/index.d.ts", |
@@ -29,3 +29,3 @@ import { BinaryWriter, Encoding } from 'csharp-binary-stream'; | ||
private initialize(socket: Socket) { | ||
private initialize(socket: Socket): void { | ||
this.socket = socket; | ||
@@ -32,0 +32,0 @@ this.socket = socket; |
@@ -13,2 +13,8 @@ import { Encoding } from 'csharp-binary-stream'; | ||
export interface ServerConnectionInfo { | ||
connectedSince: Date; | ||
messgesSent: number; | ||
messagesPerMinute: number; | ||
} | ||
const HEARTBEAT_TIMEOUT = 1000 * 30; | ||
@@ -35,2 +41,61 @@ | ||
public async getServerConnections(): Promise<string[]> { | ||
const { bw, myId } = this.client.getSendWriter(ApiMessageType.GET_CONNECTIONS, 4); | ||
this.client.sendMsg(bw); | ||
const response = await this.client.getResponse(myId); | ||
const br = getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
} else { | ||
const len = br.readInt(); | ||
const result = new Array(len); | ||
for (let i = 0; i < len; i++) { | ||
result[i] = br.readString(Encoding.Utf8); | ||
} | ||
return result; | ||
} | ||
} | ||
public async getServerConnectionInfo(id: string): Promise<ServerConnectionInfo> { | ||
const { bw, myId } = this.client.getSendWriter(ApiMessageType.GET_CONNECTION_INFO, id.length + 4); | ||
bw.writeString(id, Encoding.Utf8); | ||
this.client.sendMsg(bw); | ||
const response = await this.client.getResponse(myId); | ||
const br = getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
} else { | ||
const messgesSent = br.readLong(); | ||
const messagesPerMinute = br.readLong(); | ||
const connectedSince = new Date(br.readLong()); | ||
return { | ||
connectedSince, | ||
messgesSent, | ||
messagesPerMinute, | ||
}; | ||
} | ||
} | ||
public async kickConnection(id: string): Promise<void> { | ||
const { bw, myId } = this.client.getSendWriter(ApiMessageType.KICK_CONNECTION, id.length); | ||
bw.writeString(id, Encoding.Utf8); | ||
this.client.sendMsg(bw); | ||
const response = await this.client.getResponse(myId); | ||
const br = getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
} else { | ||
return; | ||
} | ||
} | ||
public disconnect(): void { | ||
@@ -37,0 +102,0 @@ this.client.disconnect(); |
@@ -68,2 +68,5 @@ export enum ApiMessageType { | ||
COLLECTION_GET_TAG_ENTRY = 65, | ||
GET_CONNECTIONS = 66, | ||
GET_CONNECTION_INFO = 67, | ||
KICK_CONNECTION = 68, | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
326678
3765