10import { marked } from "https://esm.sh/marked";
11
12function App() {
13 const [compliments, setCompliments] = useState<string>("");
14 const [isLoading, setIsLoading] = useState(false);
160}
161
162function client() {
163 console.log("Client-side rendering started");
164 createRoot(document.getElementById("root")!).render(<App />);
171}
172
173async function server(request: Request): Promise<Response> {
174 console.log("Server received request:", request.method, new URL(request.url).pathname);
175
4import { generateId, Scrypt } from "npm:lucia";
5
6export async function createTables(userTable: string, sessionTable: string) {
7 return sqlite.batch([
8 `CREATE TABLE ${userTable} (
20}
21
22async function safeExecute({ userTable, sessionTable, query, error }: {
23 userTable: string;
24 sessionTable: string;
38}
39
40export async function createUser({ userTable, sessionTable, username, password }: {
41 userTable: string;
42 sessionTable: string;
58}
59
60export async function getUser(
61 { userTable, sessionTable, username },
62): Promise<{ id: string; username: string; hashed_password: string } | null> {
74}
75
76export async function verifyPassword(hashed_password: string, password: string): Promise<boolean> {
77 return new Scrypt().verify(hashed_password, password);
78}
5import { nominatimSearch } from "https://esm.town/v/stevekrouse/nominatimSearch";
6
7function absoluteURL(url) {
8 if (url.startsWith("http://") || url.startsWith("https://"))
9 return url;
25let linkClass = "text-sky-600 hover:text-sky-500";
26
27function httpsIfy(url: string) {
28 if (!url.startsWith("http://") && !url.startsWith("https://")) {
29 return `https://${url}`;
33
34// TODO - refactor this into a Cell React component
35function renderCell(header, row) {
36 let data = row[header];
37 if (header === "Name") {
47}
48
49function convertParams(url) {
50 const params = new URL(url).searchParams;
51 const search = {
62const metersInMile = 1609.34;
63
64function withinRadius(
65 profileLocation: string[],
66 searchLocation: { lat: number; lon: number },
75}
76
77export async function loader({ request }) {
78 "use server"; // this is not a real feature; just me reminding myself I'm on the server
79 const { zip } = await import("npm:lodash-es");
117}
118
119export function Browse() {
120 const search = convertParams(window.location.href);
121 const { profiles } = useLoaderData() as any; // TODO - get good typing
31
32// ------------
33// Functions
34// ------------
35
36async function execute(statement: InStatement): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
48}
49
50async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
51 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
52 method: "POST",
62}
63
64function createResError(body: string) {
65 try {
66 const e = zLibsqlError.parse(JSON.parse(body));
113 *
114 * The types are currently shown for types declared in a SQL table. For
115 * column types of function calls, for example, an empty string is
116 * returned.
117 */
3const php = new PhpWeb();
4
5export default async function(req: Request): Promise<Response> {
6 let output = "";
7 let headers = new Headers();
55
56 // Simple router
57 function route($uri, $method) {
58 switch ($uri) {
59 case '/api':
79 <title>Greeting Form</title>
80 <script>
81 async function submitForm(event) {
82 event.preventDefault();
83 const form = event.target;
3
4// Get the title of the top story on Hacker News
5export async function hnTopStory() {
6 const topStories: Number[] = await fetch(
7 "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty",
4
5/**
6 * Provides functions for interacting with your account's blob storage.
7 * Blobs can store any data type (text, JSON, images, etc.) and allow
8 * retrieval across different vals using the same key.
80};
81
82async function list(prefix?: string): Promise<{ key: string; size: number; lastModified: string }[]> {
83 let querystring = prefix ? `?prefix=${encodeURIComponent(prefix)}` : "";
84 const res = await fetch(`${API_URL}/v1/blob${querystring}`, {
94}
95
96async function delete_(key: string) {
97 const res = await fetch(`${API_URL}/v1/blob/${encodeURIComponent(key)}`, {
98 method: "DELETE",
107}
108
109async function get(key: string) {
110 const res = await fetch(`${API_URL}/v1/blob/${encodeURIComponent(key)}`, {
111 headers: {
123}
124
125async function set(key: string, value: BodyInit) {
126 const res = await fetch(`${API_URL}/v1/blob/${encodeURIComponent(key)}`, {
127 method: "POST",
137}
138
139async function copy(previous: string, next: string) {
140 const res = await get(previous);
141 await set(next, res.body);
142}
143
144async function move(previous: string, next: string) {
145 await copy(previous, next);
146 await delete_(previous);
147}
148
149async function getJSON<T = unknown>(key: string): Promise<T> {
150 try {
151 const res = await get(key);
159}
160
161async function setJSON(key: string, value: any) {
162 return set(key, JSON.stringify(value));
163}
3const QuickJS = await newQuickJSWASMModuleFromVariant(releaseVariant);
4
5async function main() {
6 const vm = QuickJS.newContext();
7
127}
128
129function transformIntoDatabaseSession(raw: SessionSchema): DatabaseSession {
130 const { id, user_id: userId, expires_at: expiresAtUnix, ...attributes } = raw;
131 return {
137}
138
139function transformIntoDatabaseUser(raw: UserSchema): DatabaseUser {
140 const { id, ...attributes } = raw;
141 return {
145}
146
147function escapeName(val: string): string {
148 return "`" + val + "`";
149}
18})();
19
20export default async function(req: Request): Promise<Response> {
21 await init;
22 await pg.query(`