Home / File/ live.config.ts — astro Source File

live.config.ts — astro Source File

Architecture documentation for live.config.ts, a typescript file in the astro codebase. 3 imports, 0 dependents.

File typescript IntegrationAdapters SsrAdapters 3 imports 2 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  2bc94997_492e_a0e0_e675_f88ddaa59347["live.config.ts"]
  48f80d01_e646_3924_78f6_a9d836644746["astro:content"]
  2bc94997_492e_a0e0_e675_f88ddaa59347 --> 48f80d01_e646_3924_78f6_a9d836644746
  0f49b6f2_8b44_baf8_7812_a8fa2dd0ca84["zod"]
  2bc94997_492e_a0e0_e675_f88ddaa59347 --> 0f49b6f2_8b44_baf8_7812_a8fa2dd0ca84
  d47373dc_6761_5858_3027_a4a6472dd795["loaders"]
  2bc94997_492e_a0e0_e675_f88ddaa59347 --> d47373dc_6761_5858_3027_a4a6472dd795
  style 2bc94997_492e_a0e0_e675_f88ddaa59347 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { defineLiveCollection } from 'astro:content';
import { z } from 'astro/zod';
import type { LiveLoader } from 'astro/loaders';

type Entry = {
	title: string;
	age?: number;
};

interface CollectionFilter {
	addToAge?: number;
	returnInvalid?: boolean;
}

type EntryFilter = {
	id: keyof typeof entries;
	addToAge?: number;
};

const entries = {
	'123': {
		id: '123',
		data: { title: 'Page 123', age: 10 },
		rendered: { html: '<h1>Page 123</h1><p>This is rendered content.</p>' }
	},
	'456': { id: '456', data: { title: 'Page 456', age: 20 } },
	'789': { id: '789', data: { title: 'Page 789', age: 30 } },
};

class CustomError extends Error {
	constructor(message: string) {
		super(message);
		this.name = 'CustomError';
	}
}

const loader: LiveLoader<Entry, EntryFilter, CollectionFilter, CustomError> = {
	name: 'test-loader',
	loadEntry: async ({ filter, collection }) => {
		const entry = entries[filter.id];
		if (!entry) {
			return {
				error: new CustomError(`Entry ${filter.id} not found`),
			};
		}
		return {
			...entry,
			data: {
				title: entry.data.title,
				collection,
				age: filter?.addToAge
					? entry.data.age
						? entry.data.age + filter.addToAge
						: filter.addToAge
					: entry.data.age,
			},
			cacheHint: {
				tags: [`page:${filter.id}`],
				lastModified: new Date('2025-01-01T00:00:00.000Z'),
			},
		};
	},
	loadCollection: async ({ filter, collection }) => {
		return {
			entries: filter?.addToAge
				? Object.values(entries).map((entry) => ({
						...entry,
						data: {
							title: filter.returnInvalid ? 99 as any : entry.data.title,
							age: entry.data.age ? entry.data.age + filter!.addToAge! : undefined,
							collection
						},
					}))
				: Object.values(entries),
			cacheHint: {
				tags: ['page'],
				lastModified: new Date('2025-01-02T00:00:00.000Z'),
			},
		};
	},
};

const liveStuff = defineLiveCollection({
	loader,
	schema: z.object({
		title: z.string(),
		age: z.number().optional(),
		collection: z.string().optional(),
	}),
});

export const collections = { liveStuff };

Subdomains

Classes

Dependencies

  • astro:content
  • loaders
  • zod

Frequently Asked Questions

What does live.config.ts do?
live.config.ts is a source file in the astro codebase, written in typescript. It belongs to the IntegrationAdapters domain, SsrAdapters subdomain.
What functions are defined in live.config.ts?
live.config.ts defines 2 function(s): loader.loadCollection, loader.loadEntry.
What does live.config.ts depend on?
live.config.ts imports 3 module(s): astro:content, loaders, zod.
Where is live.config.ts in the architecture?
live.config.ts is located at packages/astro/test/fixtures/live-loaders/src/live.config.ts (domain: IntegrationAdapters, subdomain: SsrAdapters, directory: packages/astro/test/fixtures/live-loaders/src).

Analyze Your Own Codebase

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

Try Supermodel Free