-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Murilo Portescheller
committed
Aug 12, 2019
1 parent
09b5b19
commit 53d064b
Showing
12 changed files
with
58 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"env": { | ||
"es6": true, | ||
"mocha": true, | ||
"node": true | ||
}, | ||
"extends": ["@naturacosmeticos/eslint-config-natura"], | ||
"parserOptions": { | ||
"ecmaVersion": 2017, | ||
"ecmaFeatures": { | ||
"experimentalObjectRestSpread": true | ||
} | ||
}, | ||
"settings": { | ||
"import/resolver": { | ||
"node": { | ||
"paths": ["src", "test"] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
const { promisify } = require('util'); | ||
const zlib = require('zlib'); | ||
|
||
const gzip = promisify(zlib.gzip); | ||
const gunzip = promisify(zlib.gunzip); | ||
|
||
class GzipEngine { | ||
async compress(input) { | ||
const buff = await gzip(input,{level:zlib.constants.Z_MAX_LEVEL}); | ||
const buff = await gzip(input, { level: zlib.constants.Z_MAX_LEVEL }); | ||
|
||
return buff.toString('base64'); | ||
} | ||
|
||
async decompress(input) { | ||
const debased = Buffer.from(input, 'base64'); | ||
const unziped = await gunzip(debased); | ||
|
||
return unziped.toString(); | ||
} | ||
} | ||
|
||
module.exports = GzipEngine; | ||
module.exports = GzipEngine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
const AsyncHooksStorage = require('@naturacosmeticos/async-hooks-storage'); | ||
|
||
class CorrelationEngine { | ||
static wrapMessage(unwrappedMessageJSON) { | ||
const correlationId = AsyncHooksStorage.getEntry('correlation-id'); | ||
const wrappedMessage = correlationId ? { correlationId, message: unwrappedMessageJSON } : unwrappedMessageJSON; | ||
return wrappedMessage; | ||
} | ||
static wrapMessage(unwrappedMessageJSON) { | ||
const correlationId = AsyncHooksStorage.getEntry('correlation-id'); | ||
const wrappedMessage = correlationId ? { correlationId, message: unwrappedMessageJSON } : unwrappedMessageJSON; | ||
|
||
static unwrapMessage(wrappedMessageJSON) { | ||
const isCorrelationIdWrappedMessage = (wrappedMessageJSON && wrappedMessageJSON.correlationId && wrappedMessageJSON.message && Object.keys(wrappedMessageJSON).length===2); | ||
const body = isCorrelationIdWrappedMessage ? wrappedMessageJSON.message : wrappedMessageJSON; | ||
const correlationId = isCorrelationIdWrappedMessage ? wrappedMessageJSON.correlationId : undefined; | ||
return { correlationId, body }; | ||
} | ||
return wrappedMessage; | ||
} | ||
|
||
static unwrapMessage(wrappedMessageJSON) { | ||
const isCorrelationIdWrappedMessage = (wrappedMessageJSON && wrappedMessageJSON.correlationId && wrappedMessageJSON.message && Object.keys(wrappedMessageJSON).length === 2); | ||
const body = isCorrelationIdWrappedMessage ? wrappedMessageJSON.message : wrappedMessageJSON; | ||
const correlationId = isCorrelationIdWrappedMessage ? wrappedMessageJSON.correlationId : undefined; | ||
|
||
return { correlationId, body }; | ||
} | ||
} | ||
|
||
module.exports = CorrelationEngine; | ||
module.exports = CorrelationEngine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters