Skip to content

TypeScript

The Bazaar JS SDK is written in TypeScript and ships its type definitions. No extra package is needed.

Pass your doc type to collection. It must have an id of type string:

type Task = {
id: string;
name: string;
completed: boolean;
};
const tasks = bzr.collection<Task>("tasks");
await tasks.insertOne({ name: "Write docs", completed: false }); // id is optional
const all = await tasks.getAll(); // Task[]
await tasks.updateOne(all[0].id, { completed: true }); // partial Task

Contexts work the same way: ctx.collection<Task>("tasks").

All types are exported, e.g. Doc, FilterObject, NewPermission, SubscribeListener, User, Product, and BazaarFile:

import type { FilterObject, SubscribeListener } from "@bzr/bazaar";
const filter: FilterObject = { completed: false };
const listener: SubscribeListener<Task> = {
onAdd: (task) => console.log(task.name),
};
await tasks.subscribeAll(filter, listener);

Enums such as PermissionType, GranteeType, OrderByType, LoginType, and SendNotification are exported as values. Their values are plain strings, e.g. PermissionType.READ is "read".

See the API reference for every type.