From 5ef962a70f62e2351ad3ff7d3b37e20365ac2d22 Mon Sep 17 00:00:00 2001 From: ben-pr-p Date: Mon, 20 Jan 2020 16:02:41 -0500 Subject: [PATCH] fix: deserialize dates --- package.json | 3 ++- src/lib/memoizer.ts | 7 ++++++- yarn.lock | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 229ebb6..c4d0b97 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "memoredis", - "version": "1.0.3", + "version": "1.0.4", "description": "Redis memoization library with good Typescript generics, locking, and argument-wide bulk invalidation", "main": "build/main/index.js", "typings": "build/main/index.d.ts", @@ -51,6 +51,7 @@ "node": ">=8.9" }, "dependencies": { + "json-date-parser": "^1.0.1", "json-stable-stringify": "^1.0.1", "redis": "^2.8.0", "redis-lock": "^0.1.4", diff --git a/src/lib/memoizer.ts b/src/lib/memoizer.ts index 02c1eb7..cea9365 100644 --- a/src/lib/memoizer.ts +++ b/src/lib/memoizer.ts @@ -3,6 +3,7 @@ import jsonStableStringify from 'json-stable-stringify'; import redis, { ClientOpts, RedisClient } from 'redis'; import redisLock from 'redis-lock'; import { String } from 'runtypes'; +import { jsonDateParser } from 'json-date-parser'; const SafeString = String.withConstraint( s => !s.includes(':') && !s.includes('|') @@ -72,7 +73,11 @@ export const createMemoizer = (instanceOpts: MemoizerOpts) => { client.get(key, (err, reply) => err ? reject(err) - : resolve(reply !== null ? (JSON.parse(reply) as T) : (reply as null)) + : resolve( + reply !== null + ? (JSON.parse(reply, jsonDateParser) as T) + : (reply as null) + ) ) ); diff --git a/yarn.lock b/yarn.lock index a959ad6..8f102ac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2995,6 +2995,11 @@ json-buffer@3.0.0: resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.0.tgz#5b1f397afc75d677bde8bcfc0e47e1f9a3d9a898" integrity sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg= +json-date-parser@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/json-date-parser/-/json-date-parser-1.0.1.tgz#b70eb47c898f3b16643ad63ffb8d9620fd784f85" + integrity sha1-tw60fImPOxZkOtY/+42WIP14T4U= + json-parse-better-errors@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"