MutableDataStore Class — astro Architecture
Architecture documentation for the MutableDataStore class in mutable-data-store.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD ecb98618_124a_e276_dd98_561beaedc6ea["MutableDataStore"] fc8b2048_232d_51e7_d71d_a83969632b6f["mutable-data-store.ts"] ecb98618_124a_e276_dd98_561beaedc6ea -->|defined in| fc8b2048_232d_51e7_d71d_a83969632b6f 0387bc4c_3a64_034b_f25c_ea4d3808bd47["set()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| 0387bc4c_3a64_034b_f25c_ea4d3808bd47 8d12acf1_bfab_90a4_6086_65c243d3c193["delete()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| 8d12acf1_bfab_90a4_6086_65c243d3c193 70d207ce_27e5_2bdf_8c16_f5599477168b["clear()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| 70d207ce_27e5_2bdf_8c16_f5599477168b d05bc76d_a29e_4916_8686_93bba2b13bfd["clearAll()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| d05bc76d_a29e_4916_8686_93bba2b13bfd 46376fa6_b848_94c4_1def_bd808a3a4fec["addAssetImport()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| 46376fa6_b848_94c4_1def_bd808a3a4fec e8128657_5ca2_5835_1b1d_0ba8f6e44da0["addAssetImports()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| e8128657_5ca2_5835_1b1d_0ba8f6e44da0 3a21f321_74af_4ffd_6753_e5d73c2415a9["addModuleImport()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| 3a21f321_74af_4ffd_6753_e5d73c2415a9 ec29fa5b_8500_e9fa_d0e6_bf5cc1eaaae7["writeAssetImports()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| ec29fa5b_8500_e9fa_d0e6_bf5cc1eaaae7 f6050d12_aaac_bf6a_aa07_a369f7316c68["writeModuleImports()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| f6050d12_aaac_bf6a_aa07_a369f7316c68 869c30f5_afd6_31bc_2889_1e8921cb5502["clearTimeout()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| 869c30f5_afd6_31bc_2889_1e8921cb5502 effd8772_74ef_ad7d_4e58_038798d1ffa2["filePath()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| effd8772_74ef_ad7d_4e58_038798d1ffa2 f03b05d5_a06a_1438_1154_d1d6dcdbbdb9["scopedStore()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| f03b05d5_a06a_1438_1154_d1d6dcdbbdb9 6b11ff6e_f913_32c0_d605_318d04c32b6b["metaStore()"] ecb98618_124a_e276_dd98_561beaedc6ea -->|method| 6b11ff6e_f913_32c0_d605_318d04c32b6b
Relationship Graph
Source Code
packages/astro/src/content/mutable-data-store.ts lines 18–446
export class MutableDataStore extends ImmutableDataStore {
#file?: PathLike;
#assetsFile?: PathLike;
#modulesFile?: PathLike;
#saveTimeout: NodeJS.Timeout | undefined;
#assetsSaveTimeout: NodeJS.Timeout | undefined;
#modulesSaveTimeout: NodeJS.Timeout | undefined;
#savePromise: Promise<void> | undefined;
#savePromiseResolve: (() => void) | undefined;
#dirty = false;
#assetsDirty = false;
#modulesDirty = false;
#assetImports = new Set<string>();
#moduleImports = new Map<string, string>();
set(collectionName: string, key: string, value: unknown) {
const collection = this._collections.get(collectionName) ?? new Map();
collection.set(String(key), value);
this._collections.set(collectionName, collection);
this.#saveToDiskDebounced();
}
delete(collectionName: string, key: string) {
const collection = this._collections.get(collectionName);
if (collection) {
collection.delete(String(key));
this.#saveToDiskDebounced();
}
}
clear(collectionName: string) {
this._collections.delete(collectionName);
this.#saveToDiskDebounced();
}
clearAll() {
this._collections.clear();
this.#saveToDiskDebounced();
}
addAssetImport(assetImport: string, filePath?: string) {
const id = imageSrcToImportId(assetImport, filePath);
if (id) {
this.#assetImports.add(id);
// We debounce the writes to disk because addAssetImport is called for every image in every file,
// and can be called many times in quick succession by a filesystem watcher. We only want to write
// the file once, after all the imports have been added.
this.#writeAssetsImportsDebounced();
}
}
addAssetImports(assets: Array<string>, filePath?: string) {
assets.forEach((asset) => this.addAssetImport(asset, filePath));
}
addModuleImport(fileName: string) {
const id = contentModuleToId(fileName);
if (id) {
this.#moduleImports.set(fileName, id);
// We debounce the writes to disk because addAssetImport is called for every image in every file,
// and can be called many times in quick succession by a filesystem watcher. We only want to write
// the file once, after all the imports have been added.
this.#writeModulesImportsDebounced();
}
}
async writeAssetImports(filePath: PathLike) {
this.#assetsFile = filePath;
if (this.#assetImports.size === 0) {
try {
await this.#writeFileAtomic(filePath, 'export default new Map();');
} catch (err) {
throw new AstroError(AstroErrorData.UnknownFilesystemError, { cause: err });
}
}
Domain
Source
Frequently Asked Questions
What is the MutableDataStore class?
MutableDataStore is a class in the astro codebase, defined in packages/astro/src/content/mutable-data-store.ts.
Where is MutableDataStore defined?
MutableDataStore is defined in packages/astro/src/content/mutable-data-store.ts at line 18.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free