createGetEntry() — astro Function Reference
Architecture documentation for the createGetEntry() function in runtime.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 502cda50_ba7d_1037_6310_4ddccd2d2939["createGetEntry()"] 73d13646_8e80_972f_3adc_f28448b64e4d["runtime.ts"] 502cda50_ba7d_1037_6310_4ddccd2d2939 -->|defined in| 73d13646_8e80_972f_3adc_f28448b64e4d af38561f_e2ef_063d_2ce7_1d90fd8f0008["updateImageReferencesInData()"] 502cda50_ba7d_1037_6310_4ddccd2d2939 -->|calls| af38561f_e2ef_063d_2ce7_1d90fd8f0008 871d315d_89b6_b15a_b2ea_2f875ce674b2["warnForPropertyAccess()"] 502cda50_ba7d_1037_6310_4ddccd2d2939 -->|calls| 871d315d_89b6_b15a_b2ea_2f875ce674b2 cff854b7_cf64_aa23_950e_b772af18e460["render()"] 502cda50_ba7d_1037_6310_4ddccd2d2939 -->|calls| cff854b7_cf64_aa23_950e_b772af18e460 style 502cda50_ba7d_1037_6310_4ddccd2d2939 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/content/runtime.ts lines 159–230
export function createGetEntry({ liveCollections }: { liveCollections: LiveCollectionConfigMap }) {
return async function getEntry(
// Can either pass collection and identifier as 2 positional args,
// Or pass a single object with the collection and identifier as properties.
// This means the first positional arg can have different shapes.
collectionOrLookupObject: string | EntryLookupObject,
lookup?: string | Record<string, unknown>,
): Promise<ContentEntryResult | DataEntryResult | undefined> {
let collection: string, lookupId: string | Record<string, unknown>;
if (typeof collectionOrLookupObject === 'string') {
collection = collectionOrLookupObject;
if (!lookup)
throw new AstroError({
...AstroErrorData.UnknownContentCollectionError,
message: '`getEntry()` requires an entry identifier as the second argument.',
});
lookupId = lookup;
} else {
collection = collectionOrLookupObject.collection;
// Identifier could be `slug` for content entries, or `id` for data entries
lookupId =
'id' in collectionOrLookupObject
? collectionOrLookupObject.id
: collectionOrLookupObject.slug;
}
if (collection in liveCollections) {
throw new AstroError({
...AstroErrorData.UnknownContentCollectionError,
message: `Collection "${collection}" is a live collection. Use getLiveEntry() instead of getEntry().`,
});
}
if (typeof lookupId === 'object') {
throw new AstroError({
...AstroErrorData.UnknownContentCollectionError,
message: `The entry identifier must be a string. Received object.`,
});
}
const store = await globalDataStore.get();
if (store.hasCollection(collection)) {
const entry = store.get<DataEntry>(collection, lookupId);
if (!entry) {
console.warn(`Entry ${collection} → ${lookupId} was not found.`);
return;
}
// @ts-expect-error virtual module
const { default: imageAssetMap } = await import('astro:asset-imports');
entry.data = updateImageReferencesInData(entry.data, entry.filePath, imageAssetMap);
const result = {
...entry,
collection,
} as DataEntryResult | ContentEntryResult;
// TODO: remove in Astro 7
warnForPropertyAccess(
result.data,
'slug',
`[content] Attempted to access deprecated property on "${collection}" entry.\nThe "slug" property is no longer automatically added to entries. Please use the "id" property instead.`,
);
// TODO: remove in Astro 7
warnForPropertyAccess(
result,
'render',
`[content] Invalid attempt to access "render()" method on "${collection}" entry.\nTo render an entry, use "render(entry)" from "astro:content".`,
);
return result;
}
return undefined;
};
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does createGetEntry() do?
createGetEntry() is a function in the astro codebase, defined in packages/astro/src/content/runtime.ts.
Where is createGetEntry() defined?
createGetEntry() is defined in packages/astro/src/content/runtime.ts at line 159.
What does createGetEntry() call?
createGetEntry() calls 3 function(s): render, updateImageReferencesInData, warnForPropertyAccess.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free