From 6c2d4e4a86f75b7dd21e72c56b88a54cf1fe97b4 Mon Sep 17 00:00:00 2001 From: Julien SCHMITT Date: Thu, 27 Jan 2022 16:00:13 +0100 Subject: [PATCH] Fix for issue #38 Add method desymbolize for options passed in CircularJSON.stringify method --- lib/index.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 0735583..7efc2a3 100644 --- a/lib/index.js +++ b/lib/index.js @@ -6,6 +6,22 @@ var crypto = require('crypto'); module.exports = Cacher; +function desymbolize(options) { + if (Array.isArray(options)) { + return options.map(desymbolize); + } else if (typeof options != "object") { + return options; + } else { + let d = Object.assign(Object.create(Object.getPrototypeOf(options)), options); + Object.getOwnPropertySymbols(options).forEach(k => { + d[`<${Symbol.keyFor(k)}>`] = options[k]; + delete d[k]; + }); + Object.keys(d).forEach(k => d[k] = desymbolize(d[k])); + return d; + } +} + /** * Constructor for cacher */ @@ -240,7 +256,7 @@ Cacher.prototype.key = function key(sql) { return [this.cachePrefix, '__raw__', 'query', hash].join(':'); } hash = crypto.createHash('sha1') - .update(CircularJSON.stringify(this.options, jsonReplacer)) + .update(CircularJSON.stringify(desymbolize(this.options), jsonReplacer)) .digest('hex'); return [this.cachePrefix, this.modelName, this.method, hash].join(':'); };