Skip to content

Commit

Permalink
Tell serialize fn if it's being used on arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Zenith00 committed Apr 22, 2024
1 parent 4eb6826 commit 8a0e0f2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export interface MemoizerOptions {
noBody: boolean
throwError: boolean
retryOnInvalidCache: boolean
serialize: (val: unknown) => string
serialize: (val: unknown, isArgs: boolean) => string
deserialize: (val: string) => unknown
}

function serialize(val: unknown) {
function serialize(val: unknown, _isArgs: boolean) {

Check failure on line 25 in src/index.ts

View workflow job for this annotation

GitHub Actions / Test with Node v20

'_isArgs' is defined but never used
const circRefColl: unknown[] = []
return JSON.stringify(val, function (name, value) {
if (typeof value === 'function') {
Expand Down Expand Up @@ -60,7 +60,7 @@ export function getCacheFilePath(
fnStr = options.astBody ? JSON.stringify(fnStr) : fnStr
}

const argsStr = options.serialize(args)
const argsStr = options.serialize(args, true)
const hash = crypto
.createHash('md5')
.update(fnStr + argsStr + salt)
Expand Down Expand Up @@ -127,7 +127,7 @@ async function writeResult(
let resultString
if ((r && typeof r === 'object') || typeof r === 'string') {
resultObj = { data: r }
resultString = optExt.serialize(resultObj)
resultString = optExt.serialize(resultObj, false)
} else {
resultString = '{"data":' + r + '}'
}
Expand Down

0 comments on commit 8a0e0f2

Please sign in to comment.