@niobium/api-transport
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name" : "@niobium/api-transport", | ||
"description" : "Niobium API transport layer", | ||
"version" : "0.1.1", | ||
"version" : "0.1.2", | ||
"license" : "MIT", | ||
@@ -6,0 +6,0 @@ "author" : { |
@@ -152,3 +152,5 @@ const nTools = require('@niobium/tools'); | ||
const ret = await mw.fn.apply(packet.injects, this._injectToArgs(mw.fn, packet.injects, [])); | ||
_update(); | ||
if (!nTools.isUndefined(ret)) { | ||
@@ -174,5 +176,6 @@ packet.breaked = true; | ||
serializePacket(packet) { | ||
async serializePacket(packet) { | ||
const filtred = this.filterPacket(packet); | ||
try { | ||
return this.serializer.serialize(this.filterPacket(packet)); | ||
return !this.coderOverride ? this.serializer.serialize(filtred) : await this.coderOverride(filtred); | ||
} catch (e) { | ||
@@ -186,7 +189,7 @@ if (!packet.name) console.log('Error in serializePacket, incorrect packet: ', packet); | ||
return nTools.isObject(packet) | ||
&& nTools.isString(packet.id) | ||
&& nTools.isString(packet.name) | ||
&& nTools.isArray(packet.args) | ||
&& nTools.isObject(packet.meta) | ||
&& packet.version === ApiTransportProtoVersion; | ||
&& nTools.isString(packet.id) | ||
&& nTools.isString(packet.name) | ||
&& nTools.isArray(packet.args) | ||
&& nTools.isObject(packet.meta) | ||
&& packet.version === ApiTransportProtoVersion; | ||
} | ||
@@ -236,3 +239,3 @@ | ||
if (packet && !this.isLocal) this.socket.binary(true).compress(false).emit(this.options.cmdToTarget, this.serializePacket(packet)); | ||
if (packet && !this.isLocal) this.socket.binary(true).compress(false).emit(this.options.cmdToTarget, await this.serializePacket(packet)); | ||
if (packet && this.isLocal) { | ||
@@ -247,3 +250,3 @@ let ret = await this.emitEx(packet.name, true, { | ||
packet.args = [ret]; | ||
await this.incomingRetHandler(this.serializePacket(packet)); | ||
await this.incomingRetHandler(await this.serializePacket(packet)); | ||
} | ||
@@ -260,3 +263,3 @@ | ||
try { | ||
packet = this.serializer.deserialize(rawPacket, this.packetSchema); | ||
packet = !this.coderOverride ? this.serializer.deserialize(rawPacket, this.packetSchema) : await this.coderOverride(rawPacket, this.packetSchema); | ||
} catch (e) { } | ||
@@ -298,4 +301,4 @@ if (!this.checkPacket(packet)) return; | ||
const args = Object.keys(ret).length === 1 | ||
? ret[Object.keys(ret)[0]] | ||
: nTools.objectToArray(ret); | ||
? ret[Object.keys(ret)[0]] | ||
: nTools.objectToArray(ret); | ||
let packet = this.makePacket(mwConfig.apiPacketId, name.trim(), [args]); | ||
@@ -307,3 +310,3 @@ await this.mwIterate(this.middlewaresInc, packet, true); | ||
this.socket.binary(true).compress(false).emit(this.options.cmdFromTargetRet, this.serializePacket(packet)); | ||
this.socket.binary(true).compress(false).emit(this.options.cmdFromTargetRet, await this.serializePacket(packet)); | ||
} | ||
@@ -313,3 +316,3 @@ | ||
/** @type {Packet} */ | ||
const packet = this.serializer.deserialize(rawPacket, this.packetSchema); | ||
const packet = !this.coderOverride ? this.serializer.deserialize(rawPacket, this.packetSchema) : await this.coderOverride(rawPacket, this.packetSchema); | ||
if (!this.checkPacket(packet)) return; | ||
@@ -316,0 +319,0 @@ |
@@ -20,2 +20,3 @@ const nTools = require('@niobium/tools'); | ||
this.onDisconnects = []; | ||
this.coderOverride = false; | ||
@@ -22,0 +23,0 @@ /** @type {DataCoder} */ |
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
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
18887
532