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
31
32
33
34
35
36
37
38
import { tableify } from "https://esm.town/v/stevekrouse/tableify";
import { email } from "https://esm.town/v/std/email?v=9";
import { upstash } from "https://esm.town/v/stevekrouse/upstash";
// Customizable notifications
// Example usage: @stevekrouse.dateMeNotify
export function notifyNew<A>({ getData, name }: {
getData: (d?: Date) => A[] | Promise<A[]>;
name: string;
}) {
return async function ({ lastRunAt }: Interval) {
const oldData = await upstash(name);
const currentData = await getData(lastRunAt);
if (!oldData) {
await upstash(name, currentData);
await email({
html: await tableify(currentData.slice(0, 10)),
subject: `Notification Setup: ${name}`,
});
return;
}
console.log("oldData.length", oldData.length);
console.log("currentData.length", currentData.length);
const _ = await import("npm:lodash-es");
let newData = _.differenceBy(
currentData,
oldData,
(d) => JSON.stringify(d),
);
if (newData.length) {
await email({
html: await tableify(newData),
subject: `New ${name}`,
});
await upstash(name, currentData);
}
};
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
4
kora avatar

Why use upstash here? Why not just blob?

stevekrouse avatar

I think this val may have predated blob storage by a month or so

kora avatar

And why so few comments and likes. These are all great.... or am I really early here?

stevekrouse avatar

Thank you! Hopefully it's because you're early :) We are hopeful that Val Town will become a more flourishing community very soon

October 23, 2023