test_dlockmain.tsx15 matches
14),
15ttl: 1,
16fetchStub:
17(data = {}, { status = 200, ok = status < 400 } = {}) => async () =>
18Promise.resolve({ ok, status, json: async () => data } as const),
19throwingFetchStub: async () => {
20throw new Error("sync from test_dlock::throwingFetchStub");
21},
22...await import("https://deno.land/std/assert/mod.ts"),
28id,
29ttl,
30throwingFetchStub,
31assertEquals,
32assertRejects,
36},
37) {
38const fetchSpy = spy(throwingFetchStub);
39const err = await assertRejects(() => dlock({ id, ttl }, fetchSpy));
40assertEquals(err.message, "sync from test_dlock::throwingFetchStub");
41assertSpyCalls(fetchSpy, 5);
42assertSpyCall(fetchSpy, 4, {
43args: [`https://dlock.univalent.net/lock/${id}/aquire?ttl=${ttl}`],
44});
45},
46async function should_reject_ttl_of_0(
47{ dlock, id, ttl, fetchStub, assertMatch, assertRejects },
48) {
49const err = await assertRejects(() => dlock({ id, ttl: 0 }, fetchStub()));
50assertMatch(err.message, /ttl/);
51},
52async function should_return_lock_on_successful_request(
53{ dlock, deadline, fetchStub, assertFalse, assertEquals },
54) {
55const lease = 375;
56const lock = await dlock({}, fetchStub({ lease, deadline }));
57assertEquals(lock.lease, lease, "lease");
58assertEquals(lock.deadline, deadline, "deadline");
64// runs into endless loop!
65async function skip_should_reject_when_id_is_locked(
66{ dlock, id, ttl, deadline, fetchStub, assertRejects, assertEquals },
67) {
68const error = "lock is acquired by another client";
69const err = await assertRejects(() =>
70dlock({ id, ttl }, fetchStub({ error, deadline }, { status: 409 }))
71);
72assertEquals(err.message, error);
1import { fetch } from "https://esm.town/v/std/fetch";
23export let fetchCat = async () => {
4const result = await fetch("https://aws.random.cat/meow");
5const json = await result.json();
6return json.file;
twitterJSONmain.tsx2 matches
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
23export let twitterJSON = ({url, bearerToken}) => fetchJSON(
4url,
5{headers: {authorization: `Bearer ${bearerToken}`}}
1import { parseXML } from "https://esm.town/v/stevekrouse/parseXML";
2import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
34export const fetchRSS = (url: string) =>
5fetchText(url)
6.then(parseXML)
7.then(({ rss }) => rss);
convertCurrencymain.tsx3 matches
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
23export let convertCurrency = async (desired, base = "usd", amount = 1) => {
4let { rates } = await fetchJSON(
5`https://open.er-api.com/v6/latest/${base}`,
6);
8return amount * (rates[desired.toUpperCase()]);
9else {
10let { rates } = await fetchJSON(
11"https://api.coingecko.com/api/v3/exchange_rates",
12);
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
23export function val({ token, id }: {
29}
30: {};
31return fetchJSON(
32"https://api.val.town/v1/vals/" + id,
33{ headers },
1import { fetch } from "https://esm.town/v/std/fetch";
2import { parseAuthorizationHeader } from "https://esm.town/v/pomdtr/parseAuthorizationHeader";
327}
28}
29const resp = await fetch(url.toString(), {
30method: req.method,
31body: body || undefined,
storeTodaysDatemain.tsx2 matches
1import { fetchAndStore } from "https://esm.town/v/tal/fetchAndStore";
2import { currentDateValues } from "https://esm.town/v/tal/currentDateValues";
34export let storeTodaysDate = (async () => {
5const today = currentDateValues();
6await fetchAndStore({
7...today,
8menuType: "pre-k---8-lunch-menu",
paginateAPImain.tsx3 matches
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
23export const paginateAPI = async (
4url: string,
5options: Parameters<typeof fetch>[1],
6) => {
7let result: any[] = [];
8let nextUrl = url;
9while (nextUrl) {
10const { data, links } = await fetchJSON(
11nextUrl,
12options,
honoGameTestmain.tsx1 match
9return c.html(html`<div style="background-color: pink;">Hello!</div>`);
10});
11return app.fetch(req);
12}