rlesser
Product Engineer at https://nomic.ai | Building ways to clear the fog
Joined January 28, 2023
Public vals
27
sqliteTableExportUtils
@rlesser
Script
SQLite Table Export Utils This allows for a val.town-hosted SQLite table to be exported as: JSON ( Record<string, unknown>[] ) Arrow IPC ( Uint8Array ) TODO: Others? This can then be used by a HTTP endpoint, like so: import { exportSQLiteTable, SQLiteTableExportFormat } from "https://esm.town/v/rlesser/sqliteTableExportUtils";
export default async function(req: Request): Promise<Response> {
const tableName = new URL(req.url).searchParams.get("table");
if (!tableName) {
return new Response("Table name is required", { status: 400 });
}
const format = (new URL(req.url).searchParams.get("format") || "arrowIPC") as SQLiteTableExportFormat;
const data = await exportSQLiteTable(tableName, format);
if (data instanceof Uint8Array) {
return new Response(data, {
headers: { "Content-Type": "application/octet-stream" },
});
} else {
return Response.json(data);
}
} TODO Specify limit and offset of export, for pagination Smart assessment of if the export is going to be over the val.town limit of 10MB, adjust to paginated of so. Support other export formats. PRs welcome!
getDependencyGraph
@rlesser
Script
Dependency Graph Explorer This val allows for dependency graph exploration. getDependencyGraph Iteratively explores the dependency graph of a val and its children, returning the results. arguments valUrlOrSlug string - the full val url or slug ( author/name ) of the val returns An object containing: dependencyMap Map<string, string[]> - A map of vals (by id) to dependencies (vals or non-val id) moduleMap Map<string, Module> - A map of modules (by val or non-val id) to module information. Module object contains: slug string - the slug of the module, how it should be displayed visually id string - the id of the module, corresponding to how it's displayed in the code, normally as a url. websiteUrl string - the website link for the module, a normally a link to either valtown or npm. category string|null - the category of the module, such as "valtown", "esm.sh", or "npm". Those without a predefined category are in null.
getNextSSR
@rlesser
Script
getNextSSR - fetch data from Next.js SSR-based sites Many modern websites use Next.js and Server-side Rendering (SSR) to serve their website and the data to populate it. Instead of standard API calls, this manifests in the browser as calls routed through dynamic endpoints. This val handles the url construction and response parsing, giving you access to the endpoint and data. Input websiteUrl - The website's url, like google.com or val.town
let getNextSSR: (websiteUrl: string) => Promise<(endpoint: string) => Promise<Record<string, any>>> Returns fetching function - A function that takes in an endpoint and returns the endpoint's response data: Input endpoint - The endpoint string, like results.json or trending.json?page=2 Returns data - The endpoint response data, without NextJS artifacts. Example const fetch = await @rlesser.getNextSSR("example.com");
const data = fetch("results.json");
return data;
Resy_getVenueCalendar
@rlesser
Script
Get a Venue's Calendar on Resy This function fetches the calendar for a given venue on Resy, which gives information on which days the venue is available, sold-out, or closed. Inputs An object containing: venue_id - The Resy venue id, either fetched from the website's network data or from @rlesser_getFavorites (Todo: add venue id from url function) . num_seats - The number of seats you are checking for availability for. Use 2 as a default if you just want to know when the restaurant is closed. Returns A VenueCalendar object, containing: last_calendar_day - A string representing the last day the restaurant has made their calendar available for (normally a few weeks out from today). scheduled - An object containing a list of dates and restaurant statuses. See type below. See other Resy vals I've made.
Resy_getFavorites
@rlesser
Script
Get Favorites on Resy This function fetches your favorite restaurants and venues, as specified in your Hit List . Inputs An object containing: authToken - Your authentication token, normally generated from @rlesser.Resy_authenticate . Returns A Favorites object, containing the ids of your favorite venues, defined in the type below. See other Resy vals I've made.
Resy_authenticate
@rlesser
Script
Authenticate with Resy This function can be used to generate an authentication token for Resy, which can be used to view favorites, set notifies, or even make reservations. Inputs An AuthParams object containing: email - The email address for your Resy account. Probably best to keep private. password - The password for your Resy account. Definitely keep this private, and place it in a secret . Returns An AuthResponse object containing: id - Your Resy account id. token - Your Resy account token, used to authenticate you in subsequent API calls. See other Resy vals I've made.