store.ts — astro Source File
Architecture documentation for store.ts, a typescript file in the astro codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 69ae2ed7_e083_0f3f_9bf3_4eaec5462411["store.ts"] da9bb8e1_9de1_7cb3_1c17_0e28541a8180["./constants.js"] 69ae2ed7_e083_0f3f_9bf3_4eaec5462411 --> da9bb8e1_9de1_7cb3_1c17_0e28541a8180 e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"] 69ae2ed7_e083_0f3f_9bf3_4eaec5462411 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415 c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"] 69ae2ed7_e083_0f3f_9bf3_4eaec5462411 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62 d9073335_b3f3_9f7a_62f3_5035edaf179b["dlv"] 69ae2ed7_e083_0f3f_9bf3_4eaec5462411 --> d9073335_b3f3_9f7a_62f3_5035edaf179b 3c9937a8_1aa7_fe65_44ce_7b303421a398["dset"] 69ae2ed7_e083_0f3f_9bf3_4eaec5462411 --> 3c9937a8_1aa7_fe65_44ce_7b303421a398 style 69ae2ed7_e083_0f3f_9bf3_4eaec5462411 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import fs from 'node:fs';
import path from 'node:path';
import dget from 'dlv';
import { dset } from 'dset';
import { SETTINGS_FILE } from './constants.js';
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
Subdomains
Classes
Dependencies
- ./constants.js
- dlv
- dset
- node:fs
- node:path
Source
Frequently Asked Questions
What does store.ts do?
store.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What does store.ts depend on?
store.ts imports 5 module(s): ./constants.js, dlv, dset, node:fs, node:path.
Where is store.ts in the architecture?
store.ts is located at packages/astro/src/preferences/store.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/preferences).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free