vtProjectSearchutils.tsx2 matches
1// Format date to relative time
2export function formatRelativeTime(dateString: string): string {
3const date = new Date(dateString);
4const now = new Date();
3738// Format date for tooltip (full date)
39export function formatFullDate(dateString: string): string {
40const date = new Date(dateString);
41return date.toLocaleDateString("en-US", {
vtProjectSearchdocsearch.ts2 matches
62* @param query Search query
63*/
64export async function searchDocsCount(
65query: string
66): Promise<number> {
85* @param fetchData Whether to fetch the full data for each result
86*/
87export async function searchDocs(
88query: string,
89page: number = 1,
vtProjectSearchdeno.lock4 matches
145"dependencies": [
146"es-errors",
147"function-bind"
148]
149},
230]
231},
232"function-bind@1.1.2": {
233"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="
234},
240"es-errors",
241"es-object-atoms",
242"function-bind",
243"get-proto",
244"gopd",
270"integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
271"dependencies": [
272"function-bind"
273]
274},
vtProjectSearchdb.ts23 matches
910/**
11* Wraps an async function to measure its execution time
12*/
13export async function withTiming<T>(
14fn: () => Promise<T>,
15): Promise<[T, number]> {
2627// Load all usernames and project paths into memory for fast typeahead
28export async function loadTypeaheadDataIntoMemory(): Promise<void> {
29console.log("Loading typeahead data into memory...");
3060* Search typeahead data by prefix
61*/
62export function searchTypeahead(query: string, limit: number = 10): string[] {
63const lowerQuery = query.toLowerCase();
64const results: string[] = [];
77* Get activity data for the last 6 months
78*/
79export async function getActivityHeatmap(): Promise<{
80date: string;
81count: number;
114* Get top contributors based on recency
115*/
116export async function getTopContributors(limit: number = 10): Promise<{
117username: string;
118projectCount: number;
152* Get most active projects based on recency and file count
153*/
154export async function getMostActiveProjects(limit: number = 10): Promise<{
155name: string;
156username: string;
192* Get database statistics for the homepage
193*/
194export async function getSearchStats(): Promise<{
195totalProjects: number;
196totalFiles: number;
402};
403404// Helper functions for project and file management
405406/**
407* Get a user by ID
408*/
409export async function getUser(userId: string): Promise<User | null> {
410const result = await sqlite.execute(
411`SELECT * FROM ${tablePrefix}_users WHERE id = ?`,
426* Insert or update a user if it's newer than existing data
427*/
428export async function upsertUser(user: User): Promise<boolean> {
429// Check if user exists and compare timestamps
430const existingUser = await getUser(user.id);
469* Get a project by ID
470*/
471async function getProject(projectId: string): Promise<Project | null> {
472const result = await sqlite.execute(
473`SELECT * FROM ${tablePrefix}_projects WHERE id = ?`,
488* Insert or update a project if it's newer than existing data
489*/
490export async function upsertProject(project: Project): Promise<boolean> {
491// Convert Date object to string if needed
492const updatedAt = project.updated_at;
540* Get a file by ID
541*/
542async function getFile(fileId: string): Promise<File | null> {
543const result = await sqlite.execute(
544`SELECT * FROM ${tablePrefix}_files WHERE id = ?`,
559* Insert or update a file if it's newer than existing data
560*/
561export async function upsertFile(file: File): Promise<boolean> {
562// Convert Date object to string if needed
563608* Extract matched lines with context around matches
609*/
610function extractMatchedLines(
611content: string,
612searchText: string,
668* Search for files containing specific text
669*/
670export async function searchFileContent(
671searchText: string,
672): Promise<FileSearchResult[]> {
716* Count total file search results
717*/
718export async function countFileSearchResults(searchText: string): Promise<number> {
719const searchPattern = `%${searchText}%`;
720734* Count total project search results
735*/
736export async function countProjectSearchResults(searchText: string): Promise<number> {
737const searchPattern = `%${searchText}%`;
738751* Count total user search results
752*/
753export async function countUserSearchResults(searchText: string): Promise<number> {
754const searchPattern = `%${searchText}%`;
755768* Search for projects matching the query
769*/
770export async function searchProjects(
771searchText: string,
772page: number = 1,
803* Search for users matching the query
804*/
805export async function searchUsers(
806searchText: string,
807page: number = 1,
844* Enhanced search that returns matched content with context and pagination
845*/
846export async function searchFileContentWithContext(
847searchText: string,
848contextLines: number = 2,
vtProjectSearch.cursorrules12 matches
45- Ask clarifying questions when requirements are ambiguous
6- Provide complete, functional solutions rather than skeleton implementations
7- Test your logic against edge cases before presenting the final solution
8- Ensure all code follows Val Town's specific platform requirements
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
19- Follow modern ES6+ conventions and functional programming practices if possible
2021## Types of triggers
2829```ts
30export default async function (req: Request) {
31return new Response("Hello World");
32}
4243```ts
44export default async function () {
45// Scheduled task code
46}
5657```ts
58export default async function (email: Email) {
59// Process email
60}
66## Val Town Standard Libraries
6768Val Town provides several hosted services and utility functions.
6970### Blob Storage
120```
121122## Val Town Utility Functions
123124Val Town provides several utility functions to help with common project tasks.
125126### Importing Utilities
200โ โโโ database/
201โ โ โโโ migrations.ts # Schema definitions
202โ โ โโโ queries.ts # DB query functions
203โ โ โโโ README.md
204โ โโโ routes/ # Route modules
219โโโ shared/
220โโโ README.md
221โโโ utils.ts # Shared types and functions
222```
223226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
229```ts
230import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
262- Export clear query functions with proper TypeScript typing
263264## Common Gotchas and Solutions
vtProjectSearchcomponents.tsx14 matches
1718// Define the Activity Heatmap component
19export function ActivityHeatmap({ activityData }: { activityData: { date: string; count: number }[] }) {
20// Convert activity data to a map for easier lookup
21const activityMap = new Map(activityData.map(item => [item.date, item.count]));
157158// Helper to highlight the search terms in the code
159export function highlightText(text: string, searchTerm: string): JSX.Element {
160if (!searchTerm) return <>{text}</>;
161178179// CodeBlock component for displaying code with line numbers
180export function CodeBlock(
181{ matchedLines, searchTerm, totalMatches: _totalMatches }: {
182matchedLines: EnhancedSearchResult["matchedLines"];
204205// File search result component
206export function FileSearchResultComponent(
207{ result, searchTerm }: { result: EnhancedSearchResult; searchTerm: string },
208) {
282283// Project search result component
284export function ProjectSearchResultComponent(
285{ result, searchTerm }: { result: ProjectSearchResult; searchTerm: string },
286) {
356357// User search result component
358export function UserSearchResultComponent(
359{ result, searchTerm }: { result: UserSearchResult; searchTerm: string },
360) {
415416// Sub-section result for docs
417export function SubDocResultComponent(
418{ result, _searchTerm }: { result: SubDocResult; _searchTerm: string },
419) {
436437// Doc search result component
438export function DocSearchResultComponent(
439{ result, searchTerm }: { result: DocSearchResult; searchTerm: string },
440) {
491492// Result count tabs component
493export function ResultTypeTabs({
494totalFileResults,
495totalProjectResults,
539540// Pagination component
541export function Pagination({
542currentPage,
543totalPages,
644645// Sample results component for preview of other result types
646export function SampleResultsSection({
647title,
648linkText,
681682// Main search page component
683export function SearchPage({
684fileResults,
685projectResults,
1244<a href="?q=database" className="example-link">database</a>
1245<a href="?q=image" className="example-link">image</a>
1246<a href="?q=function" className="example-link">function</a>
1247<a href="?q=discord" className="example-link">discord</a>
1248<a href="?q=openai" className="example-link">openai</a>
1399<a href="?q=database" className="example-link">database</a>
1400<a href="?q=image" className="example-link">image</a>
1401<a href="?q=function" className="example-link">function</a>
1402<a href="?q=discord" className="example-link">discord</a>
1403<a href="?q=openai" className="example-link">openai</a>
vtProjectSearchclient.tsx12 matches
1// Client-side script for typeahead and keyboard navigation
2export const clientScript = `
3document.addEventListener('DOMContentLoaded', function() {
4const searchInput = document.getElementById('search-input');
5const resultsContainer = document.getElementById('typeahead-results');
11let selectedIndex = -1;
1213// Function to fetch typeahead results
14async function fetchTypeahead(query) {
15if (query.length < 1) {
16hideResults();
61}
6263// Function to display results
64function displayResults(results, query) {
65// Clear previous results
66resultsContainer.innerHTML = '';
102}
103104// Function to hide results
105function hideResults() {
106resultsContainer.classList.remove('active');
107selectedIndex = -1;
109110// Input event to trigger typeahead
111searchInput.addEventListener('input', function() {
112const query = this.value.trim();
113135136// Handle keyboard navigation
137searchInput.addEventListener('keydown', function(e) {
138const items = resultsContainer.querySelectorAll('.typeahead-item');
139167168// Update selection highlight
169function updateSelection(items) {
170items.forEach((item, i) => {
171if (i === selectedIndex) {
178179// Close results when clicking outside
180document.addEventListener('click', function(e) {
181if (!searchInput.contains(e.target) && !resultsContainer.contains(e.target)) {
182hideResults();
185186// Handle mouse movement to keep the search term item highlighted
187resultsContainer.addEventListener('mouseover', function(e) {
188// Find the search term item (last child)
189const searchItem = resultsContainer.querySelector('.search-term');
vtProjectSearchapi.tsx2 matches
1415// Handle typeahead API requests
16export function handleTypeahead(req: Request): Response {
17const url = new URL(req.url);
18const searchTerm = url.searchParams.get("q") || "";
4647// Main request handler
48export async function handler(req: Request): Promise<Response> {
49const url = new URL(req.url);
50
web-appindex.http.tsx1 match
128});
129130export default async function (req: Request): Promise<Response> {
131return await app.fetch(req);
132}
untitled-1131hume-auth.ts1 match
6*/
78export default async function(req: Request): Promise<Response> {
9try {
10// Get API key and Secret key from environment variables