6// File: TestFilteringCommentsVal.js
7export const testFilteringCommentsVal = (() => {
8 const innerAsyncFunction = async () => {
9 logMessage("debug", "Initialization of innerAsyncFunction");
10 const lastRunAt = new Date("2013-10-14T16:07:01.000Z");
11 // Construct the URL with the desired parameters
41 );
42 }
43 return filteredComments; // Return the filtered comments from innerAsyncFunction
44 };
45 return innerAsyncFunction();
46})();
6// expect(firstStar(``), "*1 sample 2").to.equal("?");
7
8function firstStar(input: string) {
9 return "expected output"; // implement :)
10}
14expect(secondStar(``), "*2 sample 1").to.equal("?");
15// expect(secondStar(``), "*1 sample 2").to.equal("?");
16function secondStar(input: string) {
17 return "?";
18}
19console.log("solution *2:", secondStar(input()));
20
21function input() {
22 return `turn on 887,9 through 959,629
23turn on 454,398 through 844,448
323
324// [0,1,2,3].reduce(sum, 0) => 6
325function sum(sum: number, current: number) {
326 return sum + current;
327}
328// wrap a value to print and return it
329function debug<T>(value: T, msg = "debug"): T {
330 console.log(msg, value);
331 return value;
5type createClient = Awaited<ReturnType<typeof tursoImport>>["createClient"];
6
7export function turso(keys, handle?) {
8 let val = "@std.tursoAPI";
9 let f = (method) => (...args) =>
21}
22
23export const endpoint = function(req, res) {
24 res.end("hello, world!");
25};
171. [Generate your keypair](https://www.val.town/embed/new?code=import+%7B+set+%7D+from+%22https%3A%2F%2Fesm.town%2Fv%2Fstd%2Fset%22%3B%0Aimport+%7B+generateKeys+%7D+from+%22https%3A%2F%2Fesm.town%2Fv%2Fstevekrouse%2FgenerateKeys%22%3B%0A%0Alet+keys+%3D+await+generateKeys%28%29%0A%0Aexport+let+exportedKeySetter+%3D+Promise.all%28%5B%0A++set%28%22exportedKeys%22%2C+keys%29%2C%0A++set%28%22publicKey%22%2C+keys.publicKey%29%0A%5D%29)
182. On [your publicKey](https://www.val.town/v/me/publicKey) click the lock icon🔒 to change the permissions to `Unlisted`.
193. [Fork this helper function](https://www.val.town/v/stevekrouse.turso/fork) replacing `stevekrouse` with your own username
204. [Try out some queries!](https://www.val.town/v/stevekrouse.tursoExamples/fork)
21
35## Architecture
36
37This @std.turso function is the client or SDK to @std.tursoAPI, which acts as a "proxy" to Turso. It handles authentication, creates databases, and forwards on your SQL queries. You can get lower latency (~200ms vs ~800ms), more storage, databases, CLI & API access by having your own Turso account.
2
3// Fetches a random joke.
4function fetchRandomJoke() {
5 const SAMPLE_JOKE = {
6 "setup": "What do you call a group of disorganized cats?",
1import { refs } from "https://esm.town/v/stevekrouse/refs";
2
3function a() {
4 console.log(refs());
5}
1import { get_bilibili } from "https://esm.town/v/rebelpotato/bilibili_methods";
2
3function randint(x) {
4 return Math.floor(Math.random() * x);
5}
7const video_url = "https://api.bilibili.com/x/web-interface/dynamic/region?ps=6&rid=1";
8
9export async function get_random_video(cookie) {
10 let videos = (await get_bilibili(video_url, cookie)).archives;
11 let video = videos[randint(videos.length)];
1function getBilibiliHeaders(cookie) {
2 return new Headers({
3 "connection": "keep-alive",
9}
10
11function postBilibiliHeaders(cookie) {
12 return new Headers({
13 "connection": "keep-alive",
22}
23
24export function get_bilibili(url, cookie) {
25 return fetch(url, {
26 method: "GET",
39}
40
41function post_encode(params) {
42 return Object.keys(params).map(key => encodeURIComponent(key) + "=" + encodeURIComponent(params[key])).join("&");
43}
44
45export function post_bilibili(url, post_data, cookie) {
46 return fetch(url, {
47 method: "POST",
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
1## Create an API from a [lowdb blob](https://www.val.town/v/pomdtr/lowdb)
2
3This val exports a function that takes a lowdb instance and returns a [Hono](https://hono.dev) router that can be used to interact with the data. This is the beginning of an implementation of something like [json-server](https://github.com/typicode/json-server) for Val Town.
4
5The resulting server also comes with a frontend at `/`. The code for the frontend can be found [here](https://www.val.town/v/nbbaier/dbToAPIFrontend).