Comparing version 1.8.4 to 1.9.0
@@ -6,14 +6,24 @@ const DEFAULT_MAX_AGE = 3e3; | ||
const udf = void 0; | ||
const deepFreeze = (obj) => { | ||
if (!obj) | ||
return obj; | ||
if (typeof obj !== "object") | ||
return obj; | ||
Object.keys(obj).forEach((property) => { | ||
if (typeof obj[property] === "object" && !Object.isFrozen(obj[property])) { | ||
deepFreeze(obj[property]); | ||
const defineReactive = (obj, key, value) => { | ||
readonly(value); | ||
Object.defineProperty(obj, key, { | ||
get: () => value, | ||
set: (newValue) => { | ||
const msg = `[idmp error] The data is read-only, set ${key.toString()}=${JSON.stringify( | ||
newValue | ||
)} is not allow`; | ||
console.error(`%c ${msg}`, "font-weight: lighter; color: red"); | ||
throw new Error(msg); | ||
} | ||
}); | ||
return Object.freeze(obj); | ||
}; | ||
const readonly = (obj) => { | ||
if (obj === null || typeof obj !== "object") { | ||
return obj; | ||
} | ||
Object.keys(obj).forEach((key) => { | ||
defineReactive(obj, key, obj[key]); | ||
}); | ||
return obj; | ||
}; | ||
const getRange = (maxAge) => { | ||
@@ -37,3 +47,3 @@ if (maxAge < 0) | ||
if (process.env.NODE_ENV !== "production") { | ||
options = deepFreeze(options); | ||
options = readonly(options); | ||
} | ||
@@ -252,3 +262,3 @@ const { | ||
/* resData */ | ||
] = deepFreeze(data); | ||
] = readonly(data); | ||
} else { | ||
@@ -255,0 +265,0 @@ cache[ |
{ | ||
"name": "idmp", | ||
"version": "1.8.4", | ||
"version": "1.9.0", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "cache response", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67561
1055