Home / File/ post-loader.ts — astro Source File

post-loader.ts — astro Source File

Architecture documentation for post-loader.ts, a typescript file in the astro codebase. 2 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  0e04d4be_ef0b_7b26_b83b_e833aa6e47ee["post-loader.ts"]
  0f49b6f2_8b44_baf8_7812_a8fa2dd0ca84["zod"]
  0e04d4be_ef0b_7b26_b83b_e833aa6e47ee --> 0f49b6f2_8b44_baf8_7812_a8fa2dd0ca84
  d47373dc_6761_5858_3027_a4a6472dd795["loaders"]
  0e04d4be_ef0b_7b26_b83b_e833aa6e47ee --> d47373dc_6761_5858_3027_a4a6472dd795
  style 0e04d4be_ef0b_7b26_b83b_e833aa6e47ee fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { z } from 'astro/zod';
import type { Loader } from "astro/loaders"

export interface PostLoaderConfig {
	url: string;
}

export function loader(config:PostLoaderConfig): Loader {
	return {
		name: "post-loader",
		load: async ({
			store, meta, logger
		}) => {
			logger.info('Loading posts');

			const lastSynced = meta.get('lastSynced');

			// Don't sync more than once a minute
			if (lastSynced && (Date.now() - Number(lastSynced) < 1000 * 60)) {
					logger.info('Skipping sync');
					return;
			}

			const posts = await fetch(config.url)
				.then((res) => res.json());

			store.clear();

			for (const data of posts) {
				store.set({id: data.id, data});
			}
			meta.set('lastSynced', String(Date.now()));
		},
		createSchema: async () => {
			// Simulate a delay
			await new Promise((resolve) => setTimeout(resolve, 1000));
			return {
				schema: z.object({
				title: z.string(),
				body: z.string(),
				userId: z.number(),
				id: z.number(),
			}),
			types: /* ts */`export interface Entry {
	title: string;
	body: string;
	userId: number;
	id: number;
}`
			}
		}
	};
}

Subdomains

Functions

Dependencies

  • loaders
  • zod

Frequently Asked Questions

What does post-loader.ts do?
post-loader.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 post-loader.ts?
post-loader.ts defines 1 function(s): loader.
What does post-loader.ts depend on?
post-loader.ts imports 2 module(s): loaders, zod.
Where is post-loader.ts in the architecture?
post-loader.ts is located at packages/astro/test/fixtures/content-layer/src/loaders/post-loader.ts (domain: IntegrationAdapters, subdomain: SsrAdapters, directory: packages/astro/test/fixtures/content-layer/src/loaders).

Analyze Your Own Codebase

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

Try Supermodel Free