Shared - valtownGeocities

Shared types, interfaces, and utilities used across both frontend and backend.

Types

Core Data Types

WebsiteData

Represents the HTML content and metadata stored in blob storage:

interface WebsiteData { html: string; // The HTML content createdAt: string; // ISO timestamp of creation updatedAt: string; // ISO timestamp of last update size: number; // Size in bytes }

PageRecord

Represents a page record in the SQLite database:

interface PageRecord { id: number; // Auto-increment primary key key: string; // Unique page identifier password_hash: string | null; // Hashed password (null if not protected) created_at: string; // ISO timestamp of creation updated_at: string; // ISO timestamp of last update size: number; // Size in bytes is_public: number; // 1 for public, 0 for private (currently all public) }

PublishResponse

Response format when publishing a website:

interface PublishResponse { key: string; // The page key size: number; // Size in bytes createdAt: string; // ISO timestamp of creation updatedAt: string; // ISO timestamp of last update message: string; // Success message passwordProtected: boolean; // Whether the page is password protected }

PageSummary

Simplified page information for the index:

interface PageSummary { key: string; // The page key createdAt: string; // ISO timestamp of creation updatedAt: string; // ISO timestamp of last update size: number; // Size in bytes }

ApiError

Standard error response format:

interface ApiError { error: string; // Error message }

Validation Constants

VALIDATION

Centralized validation rules:

const VALIDATION = { MAX_KEY_LENGTH: 100, // Maximum key length MIN_PASSWORD_LENGTH: 4, // Minimum password length MAX_FILE_SIZE: 10 * 1024 * 1024, // 10MB file size limit KEY_PATTERN: /^[a-zA-Z0-9_-]{1,100}$/ // Valid key pattern } as const;

Usage

In Backend

import { WebsiteData, PageRecord, VALIDATION } from "../shared/types.ts"; // Validate key if (!VALIDATION.KEY_PATTERN.test(key)) { throw new Error("Invalid key format"); } // Type-safe data handling const websiteData: WebsiteData = { html: processedHtml, createdAt: now, updatedAt: now, size: processedHtml.length };

In Frontend

// Types are available for TypeScript development // but the frontend currently uses vanilla JavaScript // for broader compatibility // Example of how types would be used: interface InitialData { pages: PageSummary[]; } declare global { interface Window { __INITIAL_DATA__: InitialData; } }

Design Principles

  1. Type Safety: All data structures are properly typed
  2. Consistency: Same interfaces used across frontend and backend
  3. Validation: Centralized validation rules prevent inconsistencies
  4. Extensibility: Easy to add new fields or modify existing ones
  5. Documentation: All types are well-documented with comments

Future Enhancements

Potential additions to shared types:

  • User authentication types
  • Advanced page metadata (tags, categories)
  • Analytics data structures
  • API versioning types
  • Webhook payload types