ferrum-db-client
Advanced tools
Comparing version 0.2.12 to 0.2.13
@@ -115,6 +115,6 @@ "use strict"; | ||
this.heartBeatPending = false; | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -121,0 +121,0 @@ } |
@@ -31,6 +31,6 @@ "use strict"; | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -49,10 +49,10 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedData)(br, encoding, compression); | ||
return utils_1.readEncodedData(br, encoding, compression); | ||
} | ||
@@ -72,6 +72,6 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -89,6 +89,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -105,3 +105,3 @@ else { | ||
async setTag(key, value, encoding = 'json', compression = 'gzip') { | ||
const encodedData = await (0, utils_1.encodeData)(value, encoding, compression); | ||
const encodedData = await utils_1.encodeData(value, encoding, compression); | ||
const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.COLLECTION_SET_TAG, this.database.length + this.collectionKey.length + key.length + encodedData.length + 16); | ||
@@ -116,6 +116,6 @@ bw.writeString(this.database, csharp_binary_stream_1.Encoding.Utf8); | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -122,0 +122,0 @@ else { |
@@ -22,6 +22,6 @@ "use strict"; | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -41,6 +41,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -58,6 +58,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -74,6 +74,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -89,6 +89,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -110,6 +110,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -129,6 +129,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -145,6 +145,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -161,6 +161,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -176,6 +176,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -198,6 +198,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -217,6 +217,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -234,6 +234,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -250,6 +250,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -265,6 +265,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -285,6 +285,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -291,0 +291,0 @@ else { |
@@ -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>; |
@@ -21,6 +21,6 @@ "use strict"; | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -38,6 +38,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -55,6 +55,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -66,2 +66,26 @@ else { | ||
} | ||
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 = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success === 0) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else if (success === 1) { | ||
try { | ||
return 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) { | ||
@@ -74,10 +98,10 @@ const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.INDEX_GET, this.database.length + this.collectionKey.length + key.length + 12); | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedData)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedData(br, this.encoding, this.compression); | ||
} | ||
@@ -96,6 +120,6 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -115,6 +139,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -132,3 +156,3 @@ else { | ||
async set(key, value) { | ||
const encodedData = await (0, utils_1.encodeData)(value, this.encoding, this.compression); | ||
const encodedData = await utils_1.encodeData(value, this.encoding, this.compression); | ||
const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.INDEX_SET, this.database.length + this.collectionKey.length + key.length + encodedData.length + 12); | ||
@@ -142,6 +166,6 @@ bw.writeString(this.database, csharp_binary_stream_1.Encoding.Utf8); | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -158,6 +182,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -174,6 +198,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -180,0 +204,0 @@ else { |
@@ -51,6 +51,6 @@ "use strict"; | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -66,6 +66,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -81,6 +81,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -96,6 +96,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -111,6 +111,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -123,6 +123,6 @@ return undefined; | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -129,0 +129,0 @@ else { |
@@ -19,6 +19,6 @@ "use strict"; | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -35,6 +35,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -57,6 +57,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -73,6 +73,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -90,6 +90,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -106,6 +106,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -112,0 +112,0 @@ else { |
@@ -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>; |
@@ -21,6 +21,6 @@ "use strict"; | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -31,2 +31,27 @@ else { | ||
} | ||
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 = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success === 0) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else if (success === 1) { | ||
try { | ||
return 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) { | ||
@@ -40,10 +65,10 @@ const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.TIME_SERIES_GET_ENTRY, this.database.length + this.collectionKey.length + 8 + serie.length + 12); | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedData)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedData(br, this.encoding, this.compression); | ||
} | ||
@@ -63,6 +88,6 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -81,6 +106,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -96,6 +121,6 @@ return; | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -123,10 +148,10 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedDataArray)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedDataArray(br, this.encoding, this.compression); | ||
} | ||
@@ -146,10 +171,10 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedData)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedData(br, this.encoding, this.compression); | ||
} | ||
@@ -169,10 +194,10 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedData)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedData(br, this.encoding, this.compression); | ||
} | ||
@@ -192,10 +217,10 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedData)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedData(br, this.encoding, this.compression); | ||
} | ||
@@ -214,10 +239,10 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedData)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedData(br, this.encoding, this.compression); | ||
} | ||
@@ -236,10 +261,10 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedData)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedData(br, this.encoding, this.compression); | ||
} | ||
@@ -259,10 +284,10 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedDataArray)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedDataArray(br, this.encoding, this.compression); | ||
} | ||
@@ -282,10 +307,10 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedDataArray)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedDataArray(br, this.encoding, this.compression); | ||
} | ||
@@ -305,10 +330,10 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedDataArray)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedDataArray(br, this.encoding, this.compression); | ||
} | ||
@@ -329,10 +354,10 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
else { | ||
try { | ||
return (0, utils_1.readEncodedDataArray)(br, this.encoding, this.compression); | ||
return utils_1.readEncodedDataArray(br, this.encoding, this.compression); | ||
} | ||
@@ -351,6 +376,6 @@ catch (e) { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -366,3 +391,3 @@ else { | ||
async set(serie, timestamp, value) { | ||
let encodedData = await (0, utils_1.encodeData)(value, this.encoding, this.compression); | ||
let encodedData = await utils_1.encodeData(value, this.encoding, this.compression); | ||
const { bw, myId } = this.client.getSendWriter(protcol_1.ApiMessageType.TIME_SERIES_PUT_ENTRY, this.database.length + this.collectionKey.length + serie.length + 8 + encodedData.length + 12); | ||
@@ -377,6 +402,6 @@ bw.writeString(this.database, csharp_binary_stream_1.Encoding.Utf8); | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -393,6 +418,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -409,6 +434,6 @@ else { | ||
const response = await this.client.getResponse(myId); | ||
const br = (0, utils_1.getBinaryReader)(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
return (0, utils_1.handleErrorResponse)(br); | ||
const br = utils_1.getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return utils_1.handleErrorResponse(br); | ||
} | ||
@@ -415,0 +440,0 @@ else { |
@@ -9,4 +9,4 @@ "use strict"; | ||
exports.bsonBufferSize = 17825792; // 128MB | ||
const gunzipPromise = (0, util_1.promisify)(zlib_1.gunzip); | ||
const gzipPromise = (0, util_1.promisify)(zlib_1.gzip); | ||
const gunzipPromise = util_1.promisify(zlib_1.gunzip); | ||
const gzipPromise = util_1.promisify(zlib_1.gzip); | ||
function getBinaryReader(buffer) { | ||
@@ -30,3 +30,3 @@ //Hack to skip the constructor of BinaryReader because it does unecessairy and expensive copying | ||
try { | ||
return (0, bson_1.serialize)(value); | ||
return bson_1.serialize(value); | ||
} | ||
@@ -36,3 +36,3 @@ catch (e) { | ||
exports.bsonBufferSize *= 2; | ||
(0, bson_1.setInternalBufferSize)(exports.bsonBufferSize); | ||
bson_1.setInternalBufferSize(exports.bsonBufferSize); | ||
return encodeBSON(value); | ||
@@ -81,6 +81,6 @@ } | ||
if (decompressed.length > exports.bsonBufferSize) { | ||
(0, bson_1.setInternalBufferSize)(decompressed.length); | ||
bson_1.setInternalBufferSize(decompressed.length); | ||
expandBsonBuffer(decompressed.length); | ||
} | ||
decodedValue = (0, bson_1.deserialize)(decompressed); | ||
decodedValue = bson_1.deserialize(decompressed); | ||
} | ||
@@ -87,0 +87,0 @@ else if (encoding === 'float') { |
{ | ||
"name": "ferrum-db-client", | ||
"version": "0.2.12", | ||
"version": "0.2.13", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "typings": "dist/index.d.ts", |
@@ -136,4 +136,4 @@ import { BinaryWriter, Encoding } from 'csharp-binary-stream'; | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -140,0 +140,0 @@ } |
@@ -42,4 +42,4 @@ import { Encoding } from 'csharp-binary-stream'; | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -65,4 +65,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -92,4 +92,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -111,4 +111,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -143,4 +143,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -147,0 +147,0 @@ } else { |
@@ -34,4 +34,4 @@ import { Encoding } from 'csharp-binary-stream'; | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -57,4 +57,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -82,4 +82,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -100,4 +100,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -117,4 +117,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -141,4 +141,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -164,4 +164,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -183,4 +183,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -201,4 +201,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -218,4 +218,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -248,4 +248,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -271,4 +271,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -296,4 +296,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -314,4 +314,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -331,4 +331,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -352,4 +352,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -356,0 +356,0 @@ } else { |
@@ -27,4 +27,4 @@ import { Encoding } from 'csharp-binary-stream'; | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -49,4 +49,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -68,4 +68,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -78,2 +78,26 @@ } else { | ||
public async getOrNull(key: string): Promise<T | null> { | ||
const { bw, myId } = this.client.getSendWriter(ApiMessageType.INDEX_GET, this.database.length + this.collectionKey.length + key.length + 12); | ||
bw.writeString(this.database, Encoding.Utf8); | ||
bw.writeString(this.collectionKey, Encoding.Utf8); | ||
bw.writeString(key, Encoding.Utf8); | ||
this.client.sendMsg(bw); | ||
const response = await this.client.getResponse(myId); | ||
const br = getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success === 0) { | ||
return handleErrorResponse(br); | ||
} else if (success === 1) { | ||
try { | ||
return 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; | ||
} | ||
} | ||
public async get(key: string): Promise<T> { | ||
@@ -89,4 +113,4 @@ const { bw, myId } = this.client.getSendWriter(ApiMessageType.INDEX_GET, this.database.length + this.collectionKey.length + key.length + 12); | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -112,4 +136,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -133,4 +157,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -166,4 +190,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -184,4 +208,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -202,4 +226,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -206,0 +230,0 @@ } else { |
@@ -55,4 +55,4 @@ import { Encoding } from 'csharp-binary-stream'; | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -72,4 +72,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -89,4 +89,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -106,4 +106,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -123,4 +123,4 @@ } else { | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -138,4 +138,4 @@ } | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -142,0 +142,0 @@ } else { |
@@ -22,4 +22,4 @@ import { Encoding } from 'csharp-binary-stream'; | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -40,4 +40,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -65,4 +65,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -83,4 +83,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -102,4 +102,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -120,4 +120,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -124,0 +124,0 @@ } else { |
@@ -38,4 +38,4 @@ import { Encoding } from 'csharp-binary-stream'; | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -47,2 +47,30 @@ } else { | ||
public async getEntryOrNull(serie: string, timestamp: number): Promise<T | null> { | ||
const { bw, myId } = this.client.getSendWriter( | ||
ApiMessageType.TIME_SERIES_GET_ENTRY, | ||
this.database.length + this.collectionKey.length + 8 + serie.length + 12, | ||
); | ||
bw.writeString(this.database, Encoding.Utf8); | ||
bw.writeString(this.collectionKey, Encoding.Utf8); | ||
bw.writeString(serie, Encoding.Utf8); | ||
bw.writeLong(timestamp); | ||
this.client.sendMsg(bw); | ||
const response = await this.client.getResponse(myId); | ||
const br = getBinaryReader(response); | ||
const success = br.readByte(); | ||
if (success === 0) { | ||
return handleErrorResponse(br); | ||
} else if (success === 1) { | ||
try { | ||
return 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; | ||
} | ||
} | ||
public async getEntry(serie: string, timestamp: number): Promise<T> { | ||
@@ -62,4 +90,4 @@ const { bw, myId } = this.client.getSendWriter( | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -89,4 +117,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -112,4 +140,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -134,4 +162,4 @@ } | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -166,4 +194,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -193,4 +221,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -219,4 +247,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -246,4 +274,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -272,4 +300,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -298,4 +326,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -325,4 +353,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -352,4 +380,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -379,4 +407,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -407,4 +435,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -433,4 +461,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -465,4 +493,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -483,4 +511,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -501,4 +529,4 @@ } else { | ||
const br = getBinaryReader(response); | ||
const success = br.readBoolean(); | ||
if (!success) { | ||
const success = br.readByte(); | ||
if (success !== 1) { | ||
return handleErrorResponse(br); | ||
@@ -505,0 +533,0 @@ } else { |
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
313478
3620