pet-shop 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +3 -3
- package/dist/index.js +11 -16
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,8 +18,8 @@ interface PetShopInstance<T extends Record<string, any> = object> {
|
|
|
18
18
|
}
|
|
19
19
|
export declare function PetShop<T extends Record<string, any> = object>({ storage, namespace, json, }: PetShopOptions): PetShopInstance<T>;
|
|
20
20
|
export declare function createProxy<T extends Record<string, any> = object>(storage: PetShopInstance<T>): T;
|
|
21
|
-
type CacheInstance<T extends Record<string, any
|
|
21
|
+
type CacheInstance<T extends Record<string, any>, Keys extends (keyof T)[]> = Record<Keys[number], T[Keys[number]]> & {
|
|
22
22
|
clear(): void;
|
|
23
|
-
}
|
|
24
|
-
export declare function createCache<T extends Record<string, any> = object>(storage: PetShopInstance<T
|
|
23
|
+
};
|
|
24
|
+
export declare function createCache<T extends Record<string, any> = object, Keys extends (keyof T)[] = (keyof T)[]>(storage: PetShopInstance<T>, keys: Keys): CacheInstance<T, Keys>;
|
|
25
25
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -122,44 +122,39 @@ export function PetShop({ storage, namespace, json = false, }) {
|
|
|
122
122
|
export function createProxy(storage) {
|
|
123
123
|
return new Proxy({}, {
|
|
124
124
|
get(_target, key) {
|
|
125
|
-
if (typeof key !== 'string') {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
125
|
return storage.get(key);
|
|
129
126
|
},
|
|
130
127
|
set(_target, key, value) {
|
|
131
|
-
if (
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
storage.remove(key);
|
|
137
|
-
}
|
|
128
|
+
if (value !== null && value !== undefined) {
|
|
129
|
+
storage.set(key, value);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
storage.remove(key);
|
|
138
133
|
}
|
|
139
134
|
return true;
|
|
140
135
|
},
|
|
141
136
|
deleteProperty(_target, key) {
|
|
142
|
-
|
|
143
|
-
storage.remove(key);
|
|
144
|
-
}
|
|
137
|
+
storage.remove(key);
|
|
145
138
|
return true;
|
|
146
139
|
},
|
|
147
140
|
});
|
|
148
141
|
}
|
|
149
|
-
export function createCache(storage) {
|
|
142
|
+
export function createCache(storage, keys) {
|
|
150
143
|
return Object.defineProperties({
|
|
151
144
|
clear() {
|
|
152
145
|
storage.clear();
|
|
153
146
|
},
|
|
154
|
-
}, Object.fromEntries(
|
|
147
|
+
}, Object.fromEntries(keys.map((key) => {
|
|
155
148
|
return [
|
|
156
149
|
key,
|
|
157
150
|
{
|
|
151
|
+
enumerable: false,
|
|
152
|
+
configurable: true,
|
|
158
153
|
get() {
|
|
159
154
|
return storage.get(key);
|
|
160
155
|
},
|
|
161
156
|
set(value) {
|
|
162
|
-
if (value
|
|
157
|
+
if (value !== undefined && value !== null) {
|
|
163
158
|
storage.set(key, value);
|
|
164
159
|
}
|
|
165
160
|
else {
|