01
ScriptsWrite the code that does the work.
Plain TypeScript with typed input and output. Scripts live in your repository and ship in the same bundle as everything else.
- TypeScript
- zod schemas
- kept in git
export const findUnpaid = defineScript({
description: "Invoices unpaid for more than two weeks.",
input: z.object({ clinic: Clinic }),
tables: [invoices],
async run(input, ctx) {
return ctx.table(invoices).find({
filter: { and: [
{ column: "clinic", value: input.clinic },
{ column: "status", value: "unpaid" },
{ column: "issued", op: "lt", value: daysAgo(14) },
] },
});
},
});