Home / Function/ createGetCollection() — astro Function Reference

createGetCollection() — astro Function Reference

Architecture documentation for the createGetCollection() function in runtime.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  c3b432ee_24ad_0873_191d_cc98094301d1["createGetCollection()"]
  73d13646_8e80_972f_3adc_f28448b64e4d["runtime.ts"]
  c3b432ee_24ad_0873_191d_cc98094301d1 -->|defined in| 73d13646_8e80_972f_3adc_f28448b64e4d
  af38561f_e2ef_063d_2ce7_1d90fd8f0008["updateImageReferencesInData()"]
  c3b432ee_24ad_0873_191d_cc98094301d1 -->|calls| af38561f_e2ef_063d_2ce7_1d90fd8f0008
  style c3b432ee_24ad_0873_191d_cc98094301d1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/content/runtime.ts lines 93–140

export function createGetCollection({
	liveCollections,
}: {
	liveCollections: LiveCollectionConfigMap;
}) {
	return async function getCollection(
		collection: string,
		filter?: ((entry: any) => unknown) | Record<string, unknown>,
	) {
		if (collection in liveCollections) {
			throw new AstroError({
				...AstroErrorData.UnknownContentCollectionError,
				message: `Collection "${collection}" is a live collection. Use getLiveCollection() instead of getCollection().`,
			});
		}

		const hasFilter = typeof filter === 'function';
		const store = await globalDataStore.get();
		if (store.hasCollection(collection)) {
			// @ts-expect-error	virtual module
			const { default: imageAssetMap } = await import('astro:asset-imports');

			const result = [];
			for (const rawEntry of store.values<DataEntry>(collection)) {
				const data = updateImageReferencesInData(rawEntry.data, rawEntry.filePath, imageAssetMap);

				let entry = {
					...rawEntry,
					data,
					collection,
				};

				if (hasFilter && !filter(entry)) {
					continue;
				}
				result.push(entry);
			}
			return result;
		} else {
			console.warn(
				`The collection ${JSON.stringify(
					collection,
				)} does not exist or is empty. Please check your content config file for errors.`,
			);
			return [];
		}
	};
}

Subdomains

Frequently Asked Questions

What does createGetCollection() do?
createGetCollection() is a function in the astro codebase, defined in packages/astro/src/content/runtime.ts.
Where is createGetCollection() defined?
createGetCollection() is defined in packages/astro/src/content/runtime.ts at line 93.
What does createGetCollection() call?
createGetCollection() calls 1 function(s): updateImageReferencesInData.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free