introducing tinyzod - a typesafe tinybird nodejs client
tinybird is undoubtedly one of the best analytics tools out there. sadly, i find its usage a bit...stressing. why is that? let me first put this out there, the tinybird documentation is very good. its just a pain having to look for that one single endpoint i use to send events to my datasource every single time i need it. which is why i wrote tinyzod. all the endpoints you need, accessible from designated functions. no more doom scrolling through the tinybird documentation
what is tinyzod?
it's a typesafe tinybird client package that lets you use tinybird's apis from your nodejs app without having to call their endpoints manually everytime.
tinyzod:
- is small in size (< 53kb)
- is typesafe
- is tree-shakable
- supports validation libraries like zod
- supports request caching and revalidation
- provides request retrys (wip)
- and overall requires minimal setup
you mentioned validation?
yes, tinyzod has built-in support for zod. i'm working on adding support for other validation libraries like yup, etc. with this you are confident your data is validated before reaching tinybird
tinyzod is opensource. looking forward to your feedback and contributions :)
usage
it's dead simple. initialize the tinyzod client, pass in your tinybird token, call the functions you need with the required parameters.
import { z } from 'zod';
import { TinyZodClient, publishToDatasource, queryPipeWithDynamicParam } from 'tinyzod';
// initialize the tinyzod client
const tz = new TinyZodClient({
showLogs: true,
token: 'TINYBIRD-TOKEN',
/* other config */
});
// create your schema
const schema = z.object({
id: z.number(),
value: z.string(),
date: z.string(),
message: z.string(),
});
// publish an event to a datasource
const publish_ = await publishToDatasource({
schema,
client: tz,
validator: 'zod',
datasource: 'demo__v1',
mode: 'append',
data: {
/* some data */
},
});
thanks for reading. see you in the next article. feel free to connect with me on twitter(x)