Skip to content

Commit 8c99364

Browse files
committed
refactor: simplify getAll method in CachedStorage
1 parent a425952 commit 8c99364

2 files changed

Lines changed: 2 additions & 33 deletions

File tree

src/storage/cached-storage.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -80,35 +80,6 @@ export class CachedStorage extends PropertyStorage {
8080
return value;
8181
}
8282

83-
/**
84-
* Retrieves all key-value pairs that match the specified pattern.
85-
* @param pattern - A pattern to filter keys.
86-
* @param deserialize - Whether to deserialize the values.
87-
* @param options - Optional deserialization options.
88-
* @returns An array of key-value pair objects.
89-
*/
90-
getAll(
91-
pattern?: string,
92-
deserialize?: boolean,
93-
options?: DeserializationOptions,
94-
): Record<string, any>[] {
95-
const properties: Record<string, any>[] = [];
96-
const keys = this.getStorage().getDynamicPropertyIds();
97-
if (!pattern) pattern = this.prefix;
98-
else pattern = this.prefix + pattern;
99-
for (let key of keys) {
100-
if (key.startsWith(pattern)) {
101-
key = key.slice(this.prefix.length);
102-
let value = this.cache.get(key);
103-
if (!value) value = this.getStorage().getDynamicProperty(key);
104-
if (typeof value === "string" && deserialize)
105-
properties.push({ [key]: this.deserialize(value, options) });
106-
else properties.push({ [key]: value });
107-
}
108-
}
109-
return properties;
110-
}
111-
11283
/**
11384
* Retrieves a sub-storage instance with a given prefix.
11485
* @param prefix - The sub-storage identifier.

src/storage/property-storage.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,8 @@ export class PropertyStorage {
141141
for (let key of keys) {
142142
if (key.startsWith(pattern)) {
143143
key = key.slice(this.prefix.length);
144-
const value = this.getStorage().getDynamicProperty(key);
145-
if (typeof value === "string" && deserialize)
146-
properties.push({ [key]: this.deserialize(value, options) });
147-
else properties.push({ [key]: value });
144+
let value = this.get(key, deserialize, undefined, options);
145+
properties.push({ [key]: value });
148146
}
149147
}
150148
return properties;

0 commit comments

Comments
 (0)