Comparing version 2.2.0 to 2.2.1
@@ -177,3 +177,3 @@ 'use strict'; | ||
const USER_AGENT = "libhoney-js/2.2.0"; | ||
const USER_AGENT = "libhoney-js/2.2.1"; | ||
@@ -245,3 +245,3 @@ const _global = | ||
try { | ||
let encodedEvent = ev.toJSON(); // directly call toJSON, not JSON.stringify, because the latter wraps it in an additional set of quotes | ||
let encodedEvent = JSON.stringify(ev); | ||
numEncoded++; | ||
@@ -285,2 +285,16 @@ let newAcc = acc + (!first ? "," : "") + encodedEvent; | ||
toJSON() { | ||
let json = {}; | ||
if (this.timestamp) { | ||
json.time = this.timestamp; | ||
} | ||
if (this.sampleRate) { | ||
json.samplerate = this.sampleRate; | ||
} | ||
if (this.postData) { | ||
json.data = this.postData; | ||
} | ||
return json; | ||
} | ||
toBrokenJSON() { | ||
let fields = []; | ||
@@ -294,3 +308,3 @@ if (this.timestamp) { | ||
if (this.postData) { | ||
fields.push(`"data":${this.postData}`); | ||
fields.push(`"data":${JSON.stringify(this.postData)}`); | ||
} | ||
@@ -321,4 +335,15 @@ return `{${fields.join(",")}}`; | ||
// deprecated. Use ConsoleTransmission instead. | ||
class WriterTransmission { | ||
sendEvent(ev) { | ||
console.log(JSON.stringify(ev.toBrokenJSON())); | ||
} | ||
sendPresampledEvent(ev) { | ||
console.log(JSON.stringify(ev.toBrokenJSON())); | ||
} | ||
} | ||
class ConsoleTransmission { | ||
sendEvent(ev) { | ||
console.log(JSON.stringify(ev)); | ||
@@ -901,3 +926,4 @@ } | ||
// - "mock": an implementation that accumulates all events sent | ||
// - "writer": an implementation that logs to the console all events sent | ||
// - "writer": an implementation that logs to the console all events sent (deprecated. use "console" instead) | ||
// - "console": an implementation that logs correct json objects to the console for all events sent. | ||
// - "null": an implementation that does nothing | ||
@@ -987,6 +1013,9 @@ transmission: "base", | ||
_responseCallback(responses) { | ||
let queue = this._responseQueue; | ||
if (queue.length < this._options.maxResponseQueueSize) { | ||
this._responseQueue = this._responseQueue.concat(responses); | ||
} | ||
const [queue, limit] = [ | ||
this._responseQueue, | ||
this._options.maxResponseQueueSize | ||
]; | ||
this._responseQueue = concatWithMaxLimit(queue, responses, limit); | ||
this.emit("response", this._responseQueue); | ||
@@ -1151,5 +1180,5 @@ } | ||
try { | ||
postData = JSON.stringify(event.data); | ||
postData = JSON.parse(JSON.stringify(event.data)); | ||
} catch (e) { | ||
console.error("error converting event data to JSON: " + e); | ||
console.error("error cloning event data: " + e); | ||
return null; | ||
@@ -1319,3 +1348,8 @@ } | ||
case "writer": | ||
console.warn( | ||
"writer implementation is deprecated. Please switch to console implementation." | ||
); | ||
return WriterTransmission; | ||
case "console": | ||
return ConsoleTransmission; | ||
default: | ||
@@ -1338,3 +1372,3 @@ throw new Error( | ||
throw new Error( | ||
".transmission must be one of 'base'/'worker'/'mock'/'writer'/'null' or a constructor." | ||
".transmission must be one of 'base'/'worker'/'mock'/'writer'/'console'/'null' or a constructor." | ||
); | ||
@@ -1367,2 +1401,31 @@ } | ||
/** | ||
* Concatenates two arrays while keeping the length of the returned result | ||
* less than the limit. As many elements from arr2 will be appended onto the | ||
* end of arr1 as will remain under the limit. If arr1 is already too long it | ||
* will be truncated to match the limit. Order is preserved; arr2's contents | ||
* will appear after those already in arr1. | ||
* | ||
* Modifies and returns arr1. | ||
*/ | ||
function concatWithMaxLimit(arr1, arr2, limit) { | ||
// if queue is full or somehow over the max | ||
if (arr1.length >= limit) { | ||
//return up to the max length | ||
return arr1.slice(0, limit); | ||
} | ||
// if queue is not yet full but incoming responses | ||
// would put the queue over | ||
if (arr1.length + arr2.length > limit) { | ||
// find the difference and return only enough responses to fill the queue | ||
const diff = limit - arr1.length; | ||
const slicedArr2 = arr2.slice(0, diff); | ||
return arr1.concat(slicedArr2); | ||
} | ||
// otherwise assume it'll all fit, combine the responses with the queue | ||
return arr1.concat(arr2); | ||
} | ||
module.exports = Libhoney; |
@@ -196,3 +196,3 @@ 'use strict'; | ||
const USER_AGENT = "libhoney-js/2.2.0"; | ||
const USER_AGENT = "libhoney-js/2.2.1"; | ||
@@ -264,3 +264,3 @@ const _global = | ||
try { | ||
let encodedEvent = ev.toJSON(); // directly call toJSON, not JSON.stringify, because the latter wraps it in an additional set of quotes | ||
let encodedEvent = JSON.stringify(ev); | ||
numEncoded++; | ||
@@ -304,2 +304,16 @@ let newAcc = acc + (!first ? "," : "") + encodedEvent; | ||
toJSON() { | ||
let json = {}; | ||
if (this.timestamp) { | ||
json.time = this.timestamp; | ||
} | ||
if (this.sampleRate) { | ||
json.samplerate = this.sampleRate; | ||
} | ||
if (this.postData) { | ||
json.data = this.postData; | ||
} | ||
return json; | ||
} | ||
toBrokenJSON() { | ||
let fields = []; | ||
@@ -313,3 +327,3 @@ if (this.timestamp) { | ||
if (this.postData) { | ||
fields.push(`"data":${this.postData}`); | ||
fields.push(`"data":${JSON.stringify(this.postData)}`); | ||
} | ||
@@ -340,4 +354,15 @@ return `{${fields.join(",")}}`; | ||
// deprecated. Use ConsoleTransmission instead. | ||
class WriterTransmission { | ||
sendEvent(ev) { | ||
console.log(JSON.stringify(ev.toBrokenJSON())); | ||
} | ||
sendPresampledEvent(ev) { | ||
console.log(JSON.stringify(ev.toBrokenJSON())); | ||
} | ||
} | ||
class ConsoleTransmission { | ||
sendEvent(ev) { | ||
console.log(JSON.stringify(ev)); | ||
@@ -925,3 +950,4 @@ } | ||
// - "mock": an implementation that accumulates all events sent | ||
// - "writer": an implementation that logs to the console all events sent | ||
// - "writer": an implementation that logs to the console all events sent (deprecated. use "console" instead) | ||
// - "console": an implementation that logs correct json objects to the console for all events sent. | ||
// - "null": an implementation that does nothing | ||
@@ -1011,6 +1037,9 @@ transmission: "base", | ||
_responseCallback(responses) { | ||
let queue = this._responseQueue; | ||
if (queue.length < this._options.maxResponseQueueSize) { | ||
this._responseQueue = this._responseQueue.concat(responses); | ||
} | ||
const [queue, limit] = [ | ||
this._responseQueue, | ||
this._options.maxResponseQueueSize | ||
]; | ||
this._responseQueue = concatWithMaxLimit(queue, responses, limit); | ||
this.emit("response", this._responseQueue); | ||
@@ -1175,5 +1204,5 @@ } | ||
try { | ||
postData = JSON.stringify(event.data); | ||
postData = JSON.parse(JSON.stringify(event.data)); | ||
} catch (e) { | ||
console.error("error converting event data to JSON: " + e); | ||
console.error("error cloning event data: " + e); | ||
return null; | ||
@@ -1343,3 +1372,8 @@ } | ||
case "writer": | ||
console.warn( | ||
"writer implementation is deprecated. Please switch to console implementation." | ||
); | ||
return WriterTransmission; | ||
case "console": | ||
return ConsoleTransmission; | ||
default: | ||
@@ -1362,3 +1396,3 @@ throw new Error( | ||
throw new Error( | ||
".transmission must be one of 'base'/'worker'/'mock'/'writer'/'null' or a constructor." | ||
".transmission must be one of 'base'/'worker'/'mock'/'writer'/'console'/'null' or a constructor." | ||
); | ||
@@ -1391,2 +1425,31 @@ } | ||
/** | ||
* Concatenates two arrays while keeping the length of the returned result | ||
* less than the limit. As many elements from arr2 will be appended onto the | ||
* end of arr1 as will remain under the limit. If arr1 is already too long it | ||
* will be truncated to match the limit. Order is preserved; arr2's contents | ||
* will appear after those already in arr1. | ||
* | ||
* Modifies and returns arr1. | ||
*/ | ||
function concatWithMaxLimit(arr1, arr2, limit) { | ||
// if queue is full or somehow over the max | ||
if (arr1.length >= limit) { | ||
//return up to the max length | ||
return arr1.slice(0, limit); | ||
} | ||
// if queue is not yet full but incoming responses | ||
// would put the queue over | ||
if (arr1.length + arr2.length > limit) { | ||
// find the difference and return only enough responses to fill the queue | ||
const diff = limit - arr1.length; | ||
const slicedArr2 = arr2.slice(0, diff); | ||
return arr1.concat(slicedArr2); | ||
} | ||
// otherwise assume it'll all fit, combine the responses with the queue | ||
return arr1.concat(arr2); | ||
} | ||
module.exports = Libhoney; |
@@ -173,3 +173,3 @@ import superagent from 'superagent'; | ||
const USER_AGENT = "libhoney-js/2.2.0"; | ||
const USER_AGENT = "libhoney-js/2.2.1"; | ||
@@ -241,3 +241,3 @@ const _global = | ||
try { | ||
let encodedEvent = ev.toJSON(); // directly call toJSON, not JSON.stringify, because the latter wraps it in an additional set of quotes | ||
let encodedEvent = JSON.stringify(ev); | ||
numEncoded++; | ||
@@ -281,2 +281,16 @@ let newAcc = acc + (!first ? "," : "") + encodedEvent; | ||
toJSON() { | ||
let json = {}; | ||
if (this.timestamp) { | ||
json.time = this.timestamp; | ||
} | ||
if (this.sampleRate) { | ||
json.samplerate = this.sampleRate; | ||
} | ||
if (this.postData) { | ||
json.data = this.postData; | ||
} | ||
return json; | ||
} | ||
toBrokenJSON() { | ||
let fields = []; | ||
@@ -290,3 +304,3 @@ if (this.timestamp) { | ||
if (this.postData) { | ||
fields.push(`"data":${this.postData}`); | ||
fields.push(`"data":${JSON.stringify(this.postData)}`); | ||
} | ||
@@ -317,4 +331,15 @@ return `{${fields.join(",")}}`; | ||
// deprecated. Use ConsoleTransmission instead. | ||
class WriterTransmission { | ||
sendEvent(ev) { | ||
console.log(JSON.stringify(ev.toBrokenJSON())); | ||
} | ||
sendPresampledEvent(ev) { | ||
console.log(JSON.stringify(ev.toBrokenJSON())); | ||
} | ||
} | ||
class ConsoleTransmission { | ||
sendEvent(ev) { | ||
console.log(JSON.stringify(ev)); | ||
@@ -902,3 +927,4 @@ } | ||
// - "mock": an implementation that accumulates all events sent | ||
// - "writer": an implementation that logs to the console all events sent | ||
// - "writer": an implementation that logs to the console all events sent (deprecated. use "console" instead) | ||
// - "console": an implementation that logs correct json objects to the console for all events sent. | ||
// - "null": an implementation that does nothing | ||
@@ -988,6 +1014,9 @@ transmission: "base", | ||
_responseCallback(responses) { | ||
let queue = this._responseQueue; | ||
if (queue.length < this._options.maxResponseQueueSize) { | ||
this._responseQueue = this._responseQueue.concat(responses); | ||
} | ||
const [queue, limit] = [ | ||
this._responseQueue, | ||
this._options.maxResponseQueueSize | ||
]; | ||
this._responseQueue = concatWithMaxLimit(queue, responses, limit); | ||
this.emit("response", this._responseQueue); | ||
@@ -1152,5 +1181,5 @@ } | ||
try { | ||
postData = JSON.stringify(event.data); | ||
postData = JSON.parse(JSON.stringify(event.data)); | ||
} catch (e) { | ||
console.error("error converting event data to JSON: " + e); | ||
console.error("error cloning event data: " + e); | ||
return null; | ||
@@ -1320,3 +1349,8 @@ } | ||
case "writer": | ||
console.warn( | ||
"writer implementation is deprecated. Please switch to console implementation." | ||
); | ||
return WriterTransmission; | ||
case "console": | ||
return ConsoleTransmission; | ||
default: | ||
@@ -1339,3 +1373,3 @@ throw new Error( | ||
throw new Error( | ||
".transmission must be one of 'base'/'worker'/'mock'/'writer'/'null' or a constructor." | ||
".transmission must be one of 'base'/'worker'/'mock'/'writer'/'console'/'null' or a constructor." | ||
); | ||
@@ -1368,2 +1402,31 @@ } | ||
/** | ||
* Concatenates two arrays while keeping the length of the returned result | ||
* less than the limit. As many elements from arr2 will be appended onto the | ||
* end of arr1 as will remain under the limit. If arr1 is already too long it | ||
* will be truncated to match the limit. Order is preserved; arr2's contents | ||
* will appear after those already in arr1. | ||
* | ||
* Modifies and returns arr1. | ||
*/ | ||
function concatWithMaxLimit(arr1, arr2, limit) { | ||
// if queue is full or somehow over the max | ||
if (arr1.length >= limit) { | ||
//return up to the max length | ||
return arr1.slice(0, limit); | ||
} | ||
// if queue is not yet full but incoming responses | ||
// would put the queue over | ||
if (arr1.length + arr2.length > limit) { | ||
// find the difference and return only enough responses to fill the queue | ||
const diff = limit - arr1.length; | ||
const slicedArr2 = arr2.slice(0, diff); | ||
return arr1.concat(slicedArr2); | ||
} | ||
// otherwise assume it'll all fit, combine the responses with the queue | ||
return arr1.concat(arr2); | ||
} | ||
export default Libhoney; |
{ | ||
"name": "libhoney", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": " Honeycomb.io Javascript library", | ||
@@ -5,0 +5,0 @@ "bugs": "https://github.com/honeycombio/libhoney-js/issues", |
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
144156
3806