PreferenceStore Class — astro Architecture
Architecture documentation for the PreferenceStore class in store.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 545e9f22_8ccd_6843_90f2_ff38e9751de3["PreferenceStore"] 69ae2ed7_e083_0f3f_9bf3_4eaec5462411["store.ts"] 545e9f22_8ccd_6843_90f2_ff38e9751de3 -->|defined in| 69ae2ed7_e083_0f3f_9bf3_4eaec5462411 7774f287_66c7_fcc3_18ef_6242ee5e7cec["constructor()"] 545e9f22_8ccd_6843_90f2_ff38e9751de3 -->|method| 7774f287_66c7_fcc3_18ef_6242ee5e7cec d894cc72_af05_8a28_ccd1_f0e9c968d4a1["store()"] 545e9f22_8ccd_6843_90f2_ff38e9751de3 -->|method| d894cc72_af05_8a28_ccd1_f0e9c968d4a1 1778b2ce_672d_cdaf_e4ff_ce16ef0a36d7["write()"] 545e9f22_8ccd_6843_90f2_ff38e9751de3 -->|method| 1778b2ce_672d_cdaf_e4ff_ce16ef0a36d7 51dd56c8_cf72_96a8_3be0_6f00851b3182["clear()"] 545e9f22_8ccd_6843_90f2_ff38e9751de3 -->|method| 51dd56c8_cf72_96a8_3be0_6f00851b3182 70c8bec5_7efe_41e3_53ff_67360e91c7a7["delete()"] 545e9f22_8ccd_6843_90f2_ff38e9751de3 -->|method| 70c8bec5_7efe_41e3_53ff_67360e91c7a7 d462a3a2_c265_aa24_a419_a6146421ecaa["get()"] 545e9f22_8ccd_6843_90f2_ff38e9751de3 -->|method| d462a3a2_c265_aa24_a419_a6146421ecaa f87194ce_e3b3_790e_3a0f_54728a40d09a["has()"] 545e9f22_8ccd_6843_90f2_ff38e9751de3 -->|method| f87194ce_e3b3_790e_3a0f_54728a40d09a 41296f42_2e23_0b22_1d5e_360adb2d2b67["set()"] 545e9f22_8ccd_6843_90f2_ff38e9751de3 -->|method| 41296f42_2e23_0b22_1d5e_360adb2d2b67 308f2ea7_0905_f1a5_a9d9_b44610b31e4c["getAll()"] 545e9f22_8ccd_6843_90f2_ff38e9751de3 -->|method| 308f2ea7_0905_f1a5_a9d9_b44610b31e4c
Relationship Graph
Source Code
packages/astro/src/preferences/store.ts lines 7–63
export class PreferenceStore {
private file: string;
constructor(
private dir: string,
filename = SETTINGS_FILE,
) {
this.file = path.join(this.dir, filename);
}
private _store?: Record<string, any>;
private get store(): Record<string, any> {
if (this._store) return this._store;
if (fs.existsSync(this.file)) {
try {
this._store = JSON.parse(fs.readFileSync(this.file).toString());
} catch {}
}
if (!this._store) {
this._store = {};
this.write();
}
return this._store;
}
private set store(value: Record<string, any>) {
this._store = value;
this.write();
}
write() {
if (!this._store || Object.keys(this._store).length === 0) return;
fs.mkdirSync(this.dir, { recursive: true });
fs.writeFileSync(this.file, JSON.stringify(this.store, null, '\t'));
}
clear(): void {
this.store = {};
fs.rmSync(this.file, { recursive: true });
}
delete(key: string): boolean {
dset(this.store, key, undefined);
this.write();
return true;
}
get(key: string): any {
return dget(this.store, key);
}
has(key: string): boolean {
return typeof this.get(key) !== 'undefined';
}
set(key: string, value: any): void {
if (this.get(key) === value) return;
dset(this.store, key, value);
this.write();
}
getAll(): Record<string, any> {
return this.store;
}
}
Domain
Defined In
Source
Frequently Asked Questions
What is the PreferenceStore class?
PreferenceStore is a class in the astro codebase, defined in packages/astro/src/preferences/store.ts.
Where is PreferenceStore defined?
PreferenceStore is defined in packages/astro/src/preferences/store.ts at line 7.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free