redis-json
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -0,1 +1,4 @@ | ||
# v3.2.0 | ||
* Now supports `.`(Dot) in object property (Ex. {'a.b': 'c'}) | ||
# v3.0.0 | ||
@@ -2,0 +5,0 @@ * Usage of typescript |
@@ -88,3 +88,4 @@ (function (global, factory) { | ||
Object.entries(obj).forEach(([key, val]) => { | ||
const currPath = path ? `${path}.${key}` : key; | ||
const encodedKey = encodeKey(key); | ||
const currPath = path ? `${path}.${encodedKey}` : encodedKey; | ||
handleVal(val, currPath, result); | ||
@@ -103,6 +104,5 @@ }); | ||
function unflatten(target) { | ||
const delimiter = '.'; | ||
const result = {}; | ||
Object.entries(target).forEach(([key, val]) => { | ||
const split = key.split(delimiter); | ||
const split = splitKey(key); | ||
let i = 0; | ||
@@ -151,4 +151,13 @@ // Get first and next key in the split key path | ||
const parsedKey = Number(key); | ||
return isNaN(parsedKey) ? key : parsedKey; | ||
return isNaN(parsedKey) ? decodeKey(key) : parsedKey; | ||
} | ||
function encodeKey(key) { | ||
return key.replace(/\./g, '/.'); | ||
} | ||
function decodeKey(key) { | ||
return key ? key.replace(/\/./g, '.') : key; | ||
} | ||
function splitKey(key) { | ||
return key.split(/(?<!\/)\./); | ||
} | ||
@@ -155,0 +164,0 @@ class JSONCache { |
@@ -15,2 +15,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).JSONCache=t()}(this,(function(){"use strict"; | ||
and limitations under the License. | ||
***************************************************************************** */function e(e,t,i,n){return new(i||(i=Promise))((function(s,r){function o(e){try{c(n.next(e))}catch(e){r(e)}}function l(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){e.done?s(e.value):new i((function(t){t(e.value)})).then(o,l)}c((n=n.apply(e,t||[])).next())}))}const t={undefined:!0,null:!0,false:!0,true:!0};function i(e,n="",s={}){return Object.entries(e).forEach(([e,r])=>{!function e(n,s,r){const o=Array.isArray(n);n instanceof Object&&!o?0===Object.keys(n).length?r[s]="{}":i(n,s,r):o?0===n.length?r[s]="[]":n.forEach((t,i)=>{e(t,`${s}.${i}`,r)}):r[s]=t[n]?n+"":n}(r,n?`${n}.${e}`:e,s)}),s}const n={"{}":()=>({}),"[]":()=>[],undefined:()=>void 0,null:()=>null,true:()=>!0,false:()=>!1};function s(e){const t=Number(e);return isNaN(t)?e:t}return class{constructor(e,t={}){this.redisClient=e,this.options=t,this.options.prefix=t.prefix||"jc:"}set(t,n,s={}){return e(this,void 0,void 0,(function*(){const e=i(n);e.__jc_root__="0",yield this.redisClient.hmset.call(this.redisClient,this.getKey(t),e),s.expire&&(yield this.redisClient.expire.call(this.redisClient,this.getKey(t),s.expire))}))}get(t,...i){return e(this,void 0,void 0,(function*(){const e=yield this.redisClient[i.length>0?"hmget":"hgetall"].call(this.redisClient,this.getKey(t),...i);if(0!==Object.keys(e).length)return delete e.__jc_root__,i.length>0?i.reduce((t,i,n)=>(t[i]=e[n],t),{}):function(e){const t={};return Object.entries(e).forEach(([e,i])=>{const r=e.split(".");let o=0,l=s(r[o]),c=s(r[o+1]),d=t;for(;void 0!==c;){d[l]instanceof Object||(d[l]="number"==typeof c?[]:{}),d=d[l],++o<r.length&&(l=s(r[o]),c=s(r[o+1]))}d[l]=n[i]?n[i]():i}),t}(e)}))}rewrite(t,i){return e(this,void 0,void 0,(function*(){yield this.redisClient.del.call(this.redisClient,this.getKey(t)),yield this.set(t,i)}))}clearAll(){return e(this,void 0,void 0,(function*(){const e=yield this.redisClient.keys.call(this.redisClient,`${this.options.prefix}*`);yield this.redisClient.multi(e.map(e=>["del",e])).exec()}))}getKey(e){return`${this.options.prefix}${e}`}}})); | ||
***************************************************************************** */function e(e,t,i,n){return new(i||(i=Promise))((function(r,s){function o(e){try{l(n.next(e))}catch(e){s(e)}}function c(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){e.done?r(e.value):new i((function(t){t(e.value)})).then(o,c)}l((n=n.apply(e,t||[])).next())}))}const t={undefined:!0,null:!0,false:!0,true:!0};function i(e,n="",r={}){return Object.entries(e).forEach(([e,s])=>{const o=function(e){return e.replace(/\./g,"/.")}(e);!function e(n,r,s){const o=Array.isArray(n);n instanceof Object&&!o?0===Object.keys(n).length?s[r]="{}":i(n,r,s):o?0===n.length?s[r]="[]":n.forEach((t,i)=>{e(t,`${r}.${i}`,s)}):s[r]=t[n]?n+"":n}(s,n?`${n}.${o}`:o,r)}),r}const n={"{}":()=>({}),"[]":()=>[],undefined:()=>void 0,null:()=>null,true:()=>!0,false:()=>!1};function r(e){const t=Number(e);return isNaN(t)?function(e){return e?e.replace(/\/./g,"."):e}(e):t}return class{constructor(e,t={}){this.redisClient=e,this.options=t,this.options.prefix=t.prefix||"jc:"}set(t,n,r={}){return e(this,void 0,void 0,(function*(){const e=i(n);e.__jc_root__="0",yield this.redisClient.hmset.call(this.redisClient,this.getKey(t),e),r.expire&&(yield this.redisClient.expire.call(this.redisClient,this.getKey(t),r.expire))}))}get(t,...i){return e(this,void 0,void 0,(function*(){const e=yield this.redisClient[i.length>0?"hmget":"hgetall"].call(this.redisClient,this.getKey(t),...i);if(0!==Object.keys(e).length)return delete e.__jc_root__,i.length>0?i.reduce((t,i,n)=>(t[i]=e[n],t),{}):function(e){const t={};return Object.entries(e).forEach(([e,i])=>{const s=function(e){return e.split(/(?<!\/)\./)}(e);let o=0,c=r(s[o]),l=r(s[o+1]),u=t;for(;void 0!==l;){u[c]instanceof Object||(u[c]="number"==typeof l?[]:{}),u=u[c],++o<s.length&&(c=r(s[o]),l=r(s[o+1]))}u[c]=n[i]?n[i]():i}),t}(e)}))}rewrite(t,i){return e(this,void 0,void 0,(function*(){yield this.redisClient.del.call(this.redisClient,this.getKey(t)),yield this.set(t,i)}))}clearAll(){return e(this,void 0,void 0,(function*(){const e=yield this.redisClient.keys.call(this.redisClient,`${this.options.prefix}*`);yield this.redisClient.multi(e.map(e=>["del",e])).exec()}))}getKey(e){return`${this.options.prefix}${e}`}}})); |
@@ -100,3 +100,4 @@ /*! ***************************************************************************** | ||
Object.entries(obj).forEach(([key, val]) => { | ||
const currPath = path ? `${path}.${key}` : key; | ||
const encodedKey = encodeKey(key); | ||
const currPath = path ? `${path}.${encodedKey}` : encodedKey; | ||
handleVal(val, currPath, result); | ||
@@ -115,6 +116,5 @@ }); | ||
function unflatten(target) { | ||
const delimiter = '.'; | ||
const result = {}; | ||
Object.entries(target).forEach(([key, val]) => { | ||
const split = key.split(delimiter); | ||
const split = splitKey(key); | ||
let i = 0; | ||
@@ -163,4 +163,13 @@ // Get first and next key in the split key path | ||
const parsedKey = Number(key); | ||
return isNaN(parsedKey) ? key : parsedKey; | ||
return isNaN(parsedKey) ? decodeKey(key) : parsedKey; | ||
} | ||
function encodeKey(key) { | ||
return key.replace(/\./g, '/.'); | ||
} | ||
function decodeKey(key) { | ||
return key ? key.replace(/\/./g, '.') : key; | ||
} | ||
function splitKey(key) { | ||
return key.split(/(?<!\/)\./); | ||
} | ||
@@ -167,0 +176,0 @@ class JSONCache { |
@@ -102,3 +102,4 @@ 'use strict'; | ||
Object.entries(obj).forEach(([key, val]) => { | ||
const currPath = path ? `${path}.${key}` : key; | ||
const encodedKey = encodeKey(key); | ||
const currPath = path ? `${path}.${encodedKey}` : encodedKey; | ||
handleVal(val, currPath, result); | ||
@@ -117,6 +118,5 @@ }); | ||
function unflatten(target) { | ||
const delimiter = '.'; | ||
const result = {}; | ||
Object.entries(target).forEach(([key, val]) => { | ||
const split = key.split(delimiter); | ||
const split = splitKey(key); | ||
let i = 0; | ||
@@ -165,4 +165,13 @@ // Get first and next key in the split key path | ||
const parsedKey = Number(key); | ||
return isNaN(parsedKey) ? key : parsedKey; | ||
return isNaN(parsedKey) ? decodeKey(key) : parsedKey; | ||
} | ||
function encodeKey(key) { | ||
return key.replace(/\./g, '/.'); | ||
} | ||
function decodeKey(key) { | ||
return key ? key.replace(/\/./g, '.') : key; | ||
} | ||
function splitKey(key) { | ||
return key.split(/(?<!\/)\./); | ||
} | ||
@@ -169,0 +178,0 @@ class JSONCache { |
{ | ||
"name": "redis-json", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "A wrapper library to store JSON Objects in redis-hashsets and retrieve it back as JSON objects", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
113012
1392