1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-License-Identifier: 0BSD
import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
import ky from "npm:ky";
import * as v from "npm:valibot";
export { HTTPError } from "npm:ky";
const PositiveIntegerSchema = v.number([v.integer(), v.minValue(0)]);
const ValSchema = v.object({
id: v.string([v.uuid()]),
author: v.object({
id: v.string([v.uuid()]),
username: v.string(),
}),
name: v.string(),
code: v.string(),
version: PositiveIntegerSchema,
runEndAt: v.nullish(v.coerce(v.date(), (d) => new Date(d))),
createdAt: v.coerce(v.date(), (d) => new Date(d)),
readme: v.nullish(v.string()),
likeCount: PositiveIntegerSchema,
referenceCount: PositiveIntegerSchema,
});
export async function fetchVal(author: string, name: string) {
const prefixUrl = new URL("/v1/alias", API_URL);
const resp = await ky.get(`${author}/${name}`, { prefixUrl }).json();
return v.parse(ValSchema, resp);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
March 30, 2024