valtownGeocities
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data β all from the browser, and deployed in milliseconds.
Shared types, interfaces, and utilities used across both frontend and backend.
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
}
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)
}
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
}
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
}
Standard error response format:
interface ApiError {
error: string; // Error message
}
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;
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
};
// 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;
}
}
- Type Safety: All data structures are properly typed
- Consistency: Same interfaces used across frontend and backend
- Validation: Centralized validation rules prevent inconsistencies
- Extensibility: Easy to add new fields or modify existing ones
- Documentation: All types are well-documented with comments
Potential additions to shared types:
- User authentication types
- Advanced page metadata (tags, categories)
- Analytics data structures
- API versioning types
- Webhook payload types