Home / File/ index.ts — astro Source File

index.ts — astro Source File

Architecture documentation for index.ts, a typescript file in the astro codebase. 4 imports, 0 dependents.

File typescript 4 imports

Entity Profile

Dependency Diagram

graph LR
  2623462f_7b5c_364f_8aeb_3700bc55c89b["index.ts"]
  f92f4288_d2a3_264d_4379_34b9b9c2c7f4["astro:db"]
  2623462f_7b5c_364f_8aeb_3700bc55c89b --> f92f4288_d2a3_264d_4379_34b9b9c2c7f4
  58a2600d_f5df_9651_e0d8_9010ddeef24d["astro:actions"]
  2623462f_7b5c_364f_8aeb_3700bc55c89b --> 58a2600d_f5df_9651_e0d8_9010ddeef24d
  0f49b6f2_8b44_baf8_7812_a8fa2dd0ca84["zod"]
  2623462f_7b5c_364f_8aeb_3700bc55c89b --> 0f49b6f2_8b44_baf8_7812_a8fa2dd0ca84
  48f80d01_e646_3924_78f6_a9d836644746["astro:content"]
  2623462f_7b5c_364f_8aeb_3700bc55c89b --> 48f80d01_e646_3924_78f6_a9d836644746
  style 2623462f_7b5c_364f_8aeb_3700bc55c89b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { db, Comment, Likes, eq, sql } from 'astro:db';
import { ActionError, defineAction } from 'astro:actions';
import { z } from 'astro/zod';
import { getCollection } from 'astro:content';

export const server = {
	logout: defineAction({
		handler: async () => {
			await new Promise((r) => setTimeout(r, 500));
		},
	}),
	blog: {
		like: defineAction({
			input: z.object({ postId: z.string() }),
			handler: async ({ postId }) => {
				await new Promise((r) => setTimeout(r, 500));

				const result  = await db
					.update(Likes)
					.set({
						likes: sql`${Likes.likes} + 1`,
					})
					.where(eq(Likes.postId, postId))
					.returning()
					.get();

				return result?.likes;
			},
		}),

		comment: defineAction({
			accept: 'form',
			input: z.object({
				postId: z.string(),
				author: z.string(),
				body: z.string().min(10),
			}),
			handler: async ({ postId, author, body }) => {
				if (!(await getCollection('blog')).find((b) => b.id === postId)) {
					throw new ActionError({
						code: 'NOT_FOUND',
						message: 'Post not found',
					});
				}

				const comment = await db
					.insert(Comment)
					.values({
						postId,
						body,
						author,
					})
					.returning()
					.get();
				return comment;
			},
		}),

		apply: defineAction({
			accept: 'form',
			input: z.object({
				name: z.string().min(2),
				email: z.string().email(),
			}),
			handler: async ({ name, email }) => {
				return { name, email, submitted: true };
			},
		}),

		lotsOfStuff: defineAction({
			accept: 'form',
			input: z.object({
				one: z.string().min(3),
				two: z.string().min(3),
				three: z.string().min(3),
				four: z.string().min(3),
				five: z.string().min(3),
				six: z.string().min(3),
				seven: z.string().min(3),
				eight: z.string().min(3),
				nine: z.string().min(3),
				ten: z.string().min(3),
			}),
			handler(form) {
				return form;
			},
		}),
	},
	sum: defineAction({
		accept: 'form',
		input: z.object({
			a: z.number(),
			b: z.number(),
		}),
		async handler({ a, b }) {
			return a + b;
		},
	}),
};

Dependencies

  • astro:actions
  • astro:content
  • astro:db
  • zod

Frequently Asked Questions

What does index.ts do?
index.ts is a source file in the astro codebase, written in typescript.
What does index.ts depend on?
index.ts imports 4 module(s): astro:actions, astro:content, astro:db, zod.
Where is index.ts in the architecture?
index.ts is located at packages/astro/e2e/fixtures/actions-blog/src/actions/index.ts (directory: packages/astro/e2e/fixtures/actions-blog/src/actions).

Analyze Your Own Codebase

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

Try Supermodel Free