scopedStore() — astro Function Reference
Architecture documentation for the scopedStore() function in mutable-data-store.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD f03b05d5_a06a_1438_1154_d1d6dcdbbdb9["scopedStore()"] ecb98618_124a_e276_dd98_561beaedc6ea["MutableDataStore"] f03b05d5_a06a_1438_1154_d1d6dcdbbdb9 -->|defined in| ecb98618_124a_e276_dd98_561beaedc6ea e8128657_5ca2_5835_1b1d_0ba8f6e44da0["addAssetImports()"] f03b05d5_a06a_1438_1154_d1d6dcdbbdb9 -->|calls| e8128657_5ca2_5835_1b1d_0ba8f6e44da0 3a21f321_74af_4ffd_6753_e5d73c2415a9["addModuleImport()"] f03b05d5_a06a_1438_1154_d1d6dcdbbdb9 -->|calls| 3a21f321_74af_4ffd_6753_e5d73c2415a9 0387bc4c_3a64_034b_f25c_ea4d3808bd47["set()"] f03b05d5_a06a_1438_1154_d1d6dcdbbdb9 -->|calls| 0387bc4c_3a64_034b_f25c_ea4d3808bd47 70d207ce_27e5_2bdf_8c16_f5599477168b["clear()"] f03b05d5_a06a_1438_1154_d1d6dcdbbdb9 -->|calls| 70d207ce_27e5_2bdf_8c16_f5599477168b 46376fa6_b848_94c4_1def_bd808a3a4fec["addAssetImport()"] f03b05d5_a06a_1438_1154_d1d6dcdbbdb9 -->|calls| 46376fa6_b848_94c4_1def_bd808a3a4fec style f03b05d5_a06a_1438_1154_d1d6dcdbbdb9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/content/mutable-data-store.ts lines 287–359
scopedStore(collectionName: string): DataStore {
return {
get: <TData extends Record<string, unknown> = Record<string, unknown>>(key: string) =>
this.get<DataEntry<TData>>(collectionName, key),
entries: () => this.entries(collectionName),
values: () => this.values(collectionName),
keys: () => this.keys(collectionName),
set: ({ id: key, data, body, filePath, deferredRender, digest, rendered, assetImports }) => {
if (!key) {
throw new Error(`ID must be a non-empty string`);
}
const id = String(key);
if (digest) {
const existing = this.get<DataEntry>(collectionName, id);
if (existing && existing.digest === digest) {
return false;
}
}
const foundAssets = new Set<string>(assetImports);
// Check for image imports in the data. These will have been prefixed during schema parsing
new Traverse(data).forEach((_, val) => {
if (typeof val === 'string' && val.startsWith(IMAGE_IMPORT_PREFIX)) {
const src = val.replace(IMAGE_IMPORT_PREFIX, '');
foundAssets.add(src);
}
});
const entry: DataEntry = {
id,
data,
};
// We do it like this so we don't waste space stringifying
// the fields if they are not set
if (body) {
entry.body = body;
}
if (filePath) {
if (filePath.startsWith('/')) {
throw new Error(`File path must be relative to the site root. Got: ${filePath}`);
}
entry.filePath = filePath;
}
if (foundAssets.size) {
entry.assetImports = Array.from(foundAssets);
this.addAssetImports(entry.assetImports, filePath);
}
if (digest) {
entry.digest = digest;
}
if (rendered) {
entry.rendered = rendered;
}
if (deferredRender) {
entry.deferredRender = deferredRender;
if (filePath) {
this.addModuleImport(filePath);
}
}
this.set(collectionName, id, entry);
return true;
},
delete: (key: string) => this.delete(collectionName, key),
clear: () => this.clear(collectionName),
has: (key: string) => this.has(collectionName, key),
addAssetImport: (assetImport: string, fileName: string) =>
this.addAssetImport(assetImport, fileName),
addAssetImports: (assets: Array<string>, fileName: string) =>
this.addAssetImports(assets, fileName),
addModuleImport: (fileName: string) => this.addModuleImport(fileName),
};
}
Domain
Subdomains
Source
Frequently Asked Questions
What does scopedStore() do?
scopedStore() is a function in the astro codebase, defined in packages/astro/src/content/mutable-data-store.ts.
Where is scopedStore() defined?
scopedStore() is defined in packages/astro/src/content/mutable-data-store.ts at line 287.
What does scopedStore() call?
scopedStore() calls 5 function(s): addAssetImport, addAssetImports, addModuleImport, clear, set.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free