neverstew avatar
thisValUrl
@neverstew
Script
This Val URL Returns the URL of the val that calls this function. See https://www.val.town/v/neverstew.thisValUrlExample
stevekrouse avatar
limit
@stevekrouse
Script
This is a non-usable fork of https://www.val.town/v/rlimit.limit - use that one instead
stevekrouse avatar
open_in_valtown
@stevekrouse
Script
* @param handler Fetch handler
postpostscript avatar
lock
@postpostscript
Script
lock: distributed lock Forked from @stevekrouse/dlock ! ๐Ÿ™ Example: import { acquireLock } from "https://esm.town/v/postpostscript/lock"; using exampleLock = await acquireLock(); // lock will be released when it goes out of context Full Example Options: using exampleLock = await acquireLock({ id: "lockExample", retries: 0, ttl: 5, // seconds retryTimeout: 1000, // ms });
stevekrouse avatar
gpt4
@stevekrouse
Script
An interactive, runnable TypeScript val by stevekrouse
stevekrouse avatar
rlimit
@stevekrouse
Script
An interactive, runnable TypeScript val by stevekrouse
stevekrouse avatar
thisEmail
@stevekrouse
Script
An interactive, runnable TypeScript val by stevekrouse
neverstew avatar
migrate
@neverstew
Script
Val Town Migrations By calling this val, you can easily handle migrations in your Val Town Turso Database. Getting started Make sure you have your Val Town API Token saved in your secrets. See more about authentication to understand how to generate a token. Make sure you've set up your turso database ๐Ÿ‘†Fork this val How it works Each time the val is run, a new migration will be created and tracked in your database in the migrations table. There will be one migration per val, per version. You can do anything you want in the function passed to migrate ; create or alter tables, populate data... whatever! Migrating backwards Vals don't have the concept of decreasing versions and neither does this migration tool. Made a mistake? Write a new version of your val to fix it!
sdan avatar
thisValUrl
@sdan
Script
// Forked from @neverstew.thisValUrl
neverstew avatar
thisWebEndpoint
@neverstew
Script
// Forked from @stevekrouse.thisEmail
stevekrouse avatar
reloadOnSave
@stevekrouse
Script
Live reload in new tabs When you're working on an HTML HTTP val in a new tab, it's annoying to have to manually reload the tab on every save. In the Val Town editor, you can hit cmd+enter, but there's nothing like that for a val in a new tab because Val Town doesn't control that new tab (like we control the iframe in the browser preview). However, you control that HTML via the fetch handler you're writing, so you can add a script that polls the Val Town API for the current version number of your val, and reload itself if it detects a new version. This val has a collection of helpers to help you do just that. Usage import { html } from "https://esm.town/v/stevekrouse/html"; import { reloadOnSaveFetchMiddleware } from "https://esm.town/v/stevekrouse/reloadOnSave"; export default reloadOnSaveFetchMiddleware(async function(req: Request): Promise<Response> { return html(`<h1>Hello!!</h1>`); })
karfau avatar
testRunner
@karfau
Script
Test runner to be able to run a number of tests (e.g. on a different val). check the references for seeing how it is used. It is extracted into a val to avoid having all that clutter in the same val as your tests. Each test is a named function (which can be async), the name is used as the name for the test. the input passed as the first argument is passed to each test, great for importing assertion methods, stubs, fixed values, ... everything that you do not mutate during a test if a function is async (it returns a promise) there is a timeout of 2 seconds before the test is marked as failed. all tests are called in the declared order, but async tests run in parallel afterwards, so don't assume any order if a test starts with skip it is not executed if a test fails it throws the output, so it appears in the read box below the val and the evaluation/run is marked red if all tests pass it returns the output, so it appears in the grey box and the evaluation/run is marked green. Note: If you are using the test runner to store the result in that val, as described above, it is considered a "JSON val" and has a run button, but it also means that another of your vals could update the val with just any other (JSON) state. Alternatively you can define a function val that calls the test runner and have a separete val to keep the curretn test results, but it means after updating the tests you need to fest save that val and then reevaluate to val storing the test state.
stevekrouse avatar
thisWebURL
@stevekrouse
Script
An interactive, runnable TypeScript val by stevekrouse
stevekrouse avatar
exponentialBackoffMiddleware
@stevekrouse
Script
Exponential backoff middleware If your server returns a 5xx error, it will wait 1, 2, 4, 8, 16, 32, 64, 128... seconds before retrying Usage import { exponentialBackoffMiddleware } from "https://esm.town/v/stevekrouse/exponentialBackoffMiddleware" export default exponentialBackoffMiddleware(() => { /* your normal http handler * / }) Example usage: https://www.val.town/v/stevekrouse/BIGweather?v=164#L114
stevekrouse avatar
thisValURL
@stevekrouse
Script
An interactive, runnable TypeScript val by stevekrouse
stevekrouse avatar
ssr_react_mini
@stevekrouse
Script
Server-side Render React Mini Framework This is very experimental, more of a prototype of an architecture, than a true framework Example: https://www.val.town/v/stevekrouse/TodoApp
v7
January 17, 2024