6// $SECRET should be high quality random base64
7const baseKey = decodeBase64(Deno.env.get("SECRET"));
8function deriveKey(usage: string) {
9 const tag = encoder.encode(usage);
10 const hash = nacl.hash(concat([tag, baseKey]));
11 return hash;
12}
13export function encrypt(usage: string, data: Uint8Array): Uint8Array {
14 const nonce = nacl.randomBytes(nacl.secretbox.nonceLength);
15 const key = deriveKey(usage).slice(0, nacl.secretbox.keyLength);
16 return concat([nonce, nacl.secretbox(data, nonce, key)]);
17}
18export function decrypt(usage: string, encrypted: Uint8Array): Uint8Array {
19 const box = encrypted.slice(nacl.secretbox.nonceLength);
20 const nonce = encrypted.slice(0, nacl.secretbox.nonceLength);
24 return data;
25}
26export function encryptString(usage: string, data: string) {
27 return encodeBase64(encrypt(usage, encoder.encode(data)));
28}
29export function decryptString(usage: string, encrypted: string) {
30 return decoder.decode(decrypt(usage, decodeBase64(encrypted)));
31}
2
3// @see: https://github.com/jshttp/accepts#simple-type-negotiation
4export default async function(req: Request): Promise<Response> {
5 const accept = accepts(req);
6 const headers = new Headers();
10const app = new Hono();
11
12function createTorus(radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2) {
13 const indicesArray = [];
14 const positionArray = [];
3import nodeAccepts from "npm:accepts";
4
5export function accepts(req: Request) {
6 const headers = {
7 accept: req.headers.get("accept"),
77 let styled: JSX.Element[] = [];
78 let css: string = "";
79 function flush() {
80 if (out.length) {
81 styled.push(css ? <span style={css}>{out}</span> : <>{out}</>);
166 );
167};
168function transpose(matrix) {
169 return matrix[0].map((col, i) => matrix.map((row) => row[i]));
170}
220 const value = resultData[k];
221 const primitive = value === null
222 || (typeof value !== "function" && typeof value !== "object");
223 if (properties === undefined && primitive) {
224 hasPrimitives = true;
379 return (
380 <li>
381 at {item.functionName
382 ? (
383 <>
384 {item.functionName} ({file})
385 </>
386 )
808 stack: string;
809};
810async function execute(code: string): Promise<{ logs: Log[] }> {
811 try {
812 const blob = new Blob([code], {
816 const markStackStart = crypto.randomUUID();
817 const markStackEnd = crypto.randomUUID();
818 function cleanStack(stack: string) {
819 let lines: string[] = [];
820 for (const line of stack.split("\n")) {
831 get(target, key) {
832 const real = target[key];
833 if (typeof real === "function" && typeof key === "string") {
834 const fn = function(...args: any[]) {
835 logs.push({
836 type: key,
849 },
850 });
851 async function run() {
852 try {
853 await import(url);
1/// Create a handler function that displays the mermaid diagram.
2export function displayMermaid(mermaid: string): (req: Request) => Response {
3 function handler(req: Request): Response {
4 return new Response(
5 `
32};
33
34export async function gfm(markdown: string, options?: { title?: string; favicon?: string }) {
35 const html = await unified()
36 .use(remarkParse)
1import { gfm } from "https://esm.town/v/saolsen/gfm";
2
3export async function displayMarkdown(markdown: string): Promise<(req: Request) => Response> {
4 const html = await gfm(markdown);
5 function handler(req: Request): Response {
6 return new Response(html, { headers: { "content-type": "text/html" } });
7 }
17};
18
19async function serializeRequest(request: Request): Promise<SerializedRequest> {
20 return {
21 url: request.url,
55};
56
57export function httpClient(next: (req: Request) => Response | Promise<Response>, options: {
58 path: string;
59 bookmarks: Bookmark[];
69}
70
71export default async function(req: Request) {
72 const bookmarks = [{ label: "Dummy Request", request: new Request("https://dummyjson.com/products") }];
73 return html(await getBody(bookmarks));
17};
18
19async function serializeRequest(request: Request): Promise<SerializedRequest> {
20 return {
21 url: request.url,
55};
56
57export function httpClient(next: (req: Request) => Response | Promise<Response>, options: {
58 path: string;
59 bookmarks: Bookmark[];
69}
70
71export default async function(req: Request) {
72 const bookmarks = [{ label: "Dummy Request", request: new Request("https://dummyjson.com/products") }];
73 return html(await getBody(bookmarks));