Unlisted
Back
Version 67
7/25/2024
import { Hono } from 'npm:hono@3'
import { cors } from 'npm:hono@3/cors'
import { sqlite } from "https://esm.town/v/std/sqlite"
const app = new Hono()
interface Entry {
id: number
parentId: number
content: string
}
interface Story {
entries: Entry[]
}
const REPLACEMENTS = {
'’': '\'',
'‘': '\'',
'“': '"',
'”': '"',
}
const ALLOWED_PUNCTUATION = '!?.,-:;\"'
const ALLOWED_CHARS = new Set((' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\'' + ALLOWED_PUNCTUATION).split(''))
const SPLIT_REGEX = new RegExp(`[ ${ALLOWED_PUNCTUATION.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&')}]+`)
async function getStory(id: number): Promise<Story | undefined> {
const result = await sqlite.execute({
sql: `
WITH RECURSIVE descendants AS (
SELECT id, parent_id, content FROM sws_stories WHERE id = :id
UNION ALL
SELECT n.id, n.parent_id, n.content FROM sws_stories n, descendants d WHERE n.id = d.parent_id
)
SELECT * FROM descendants;
`,
samwho-sixwordstory.web.val.run
Updated: July 26, 2024