Comparing version 1.0.0 to 1.0.1
@@ -20,3 +20,3 @@ "use strict"; | ||
var AuditMerger = (function (Transform) { | ||
function AuditMerger(defaultAudit, isStream) { | ||
function AuditMerger(defaultAudit, isWriteableStream) { | ||
_classCallCheck(this, AuditMerger); | ||
@@ -26,3 +26,3 @@ | ||
this.defaultAudit = defaultAudit; | ||
this._isStream = isStream; | ||
this._isWritableStream = isWriteableStream; | ||
} | ||
@@ -36,3 +36,3 @@ | ||
var audit = Object.assign(chunck, this.defaultAudit); | ||
if (this._isStream) { | ||
if (this._isWritableStream) { | ||
this.push(JSON.stringify(audit) + "\n"); | ||
@@ -71,3 +71,3 @@ } else { | ||
var payload = Object.seal({ | ||
timestamp: Date.now(), | ||
timestamp: new Date().toISOString(), | ||
area: this.name, | ||
@@ -87,9 +87,11 @@ actor: actor, | ||
value: function connect(action, defaultAudit) { | ||
var isStream = typeof action !== "function"; | ||
var mergedStream = this.stream.pipe(new AuditMerger(defaultAudit, isStream)); | ||
var isWriteableStream = typeof action.on === "function" && action.writable; | ||
var mergedStream = this.stream.pipe(new AuditMerger(defaultAudit, isWriteableStream)); | ||
if (isStream) { | ||
if (isWriteableStream) { | ||
mergedStream.pipe(action); | ||
} else if (typeof action === "function") { | ||
mergedStream.pipe(through(action)); | ||
} else { | ||
mergedStream.pipe(through(action)); | ||
throw new TypeError("sti.connect only accepts functions or writeable streams"); | ||
} | ||
@@ -96,0 +98,0 @@ }, |
{ | ||
"name": "sti", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Audit trail for node", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -7,6 +7,6 @@ 'use strict'; | ||
class AuditMerger extends Transform { | ||
constructor( defaultAudit, isStream ) { | ||
constructor( defaultAudit, isWriteableStream ) { | ||
super({ objectMode: true }); | ||
this.defaultAudit = defaultAudit; | ||
this._isStream = isStream; | ||
this._isWritableStream = isWriteableStream; | ||
} | ||
@@ -16,3 +16,3 @@ | ||
let audit = Object.assign(chunck, this.defaultAudit ); | ||
if (this._isStream) { | ||
if (this._isWritableStream) { | ||
this.push(JSON.stringify(audit) + '\n'); | ||
@@ -39,3 +39,3 @@ } | ||
let payload = Object.seal({ | ||
timestamp: Date.now(), | ||
timestamp: new Date().toISOString(), | ||
area: this.name, | ||
@@ -52,13 +52,19 @@ actor, | ||
connect(action, defaultAudit) { | ||
let isStream = typeof action !== 'function'; | ||
let mergedStream = this.stream.pipe( new AuditMerger(defaultAudit, isStream) ); | ||
const isWriteableStream = typeof action.on === 'function' && action.writable; | ||
const mergedStream = this.stream.pipe( | ||
new AuditMerger(defaultAudit, isWriteableStream) | ||
); | ||
if ( isStream) { | ||
if ( isWriteableStream ) { | ||
mergedStream.pipe( action ); | ||
} | ||
else { | ||
else if ( typeof action === 'function' ) { | ||
mergedStream.pipe( through(action) ); | ||
} | ||
else { | ||
throw new TypeError('sti.connect only accepts functions or writeable streams'); | ||
} | ||
} | ||
} |
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
9554
186