tinylib
The object Tinylib puts in every page of an app before the page's own scripts run, with the persona and their data loaded.
Properties
| Property | Type |
|---|---|
persona | Persona |
connection | Connection |
places | Places |
data | Data |
friends | Friends |
rooms | Rooms |
invitations | Invitations |
reminders | Reminders |
tinylib.persona
The person inside this app, always current.
Properties
| Property | Type | Description |
|---|---|---|
id | string | Only this app sees it: the same person has a different id in every app. |
name | string | The person's name, the one they gave Tinylib. They change it on their profile in Tinylib, not in an app. |
notificationsOn | boolean | Whether this app's notifications are on, the one setting an app can ask about. |
tinylib.persona.onChange()
onChange(fn): () => void;
Calls fn after the name or the notifications switch changes. Returns a function that stops it.
Parameters
| Parameter | Type |
|---|---|
fn | () => void |
Returns
() => void
Example
tinylib.persona.onChange(() => (title.textContent = tinylib.persona.name))
tinylib.persona.edit()
edit(setting): Promise<boolean>;
Opens Tinylib's card for this app's notifications switch, where the person changes it. Resolves with the switch's
value when the card closes, unchanged if the person backed out. Rejects with offline. Throws a TypeError for any
setting but 'notifications'.
Parameters
| Parameter | Type |
|---|---|
setting | "notifications" |
Returns
Promise<boolean>
Example
button.onclick = async () => (button.hidden = await tinylib.persona.edit('notifications'))
tinylib.connection
Whether Tinylib's servers can be reached. Rooms and the calls that reach the servers need them; tinylib.data doesn't.
Properties
| Property | Type |
|---|---|
online | boolean |
tinylib.connection.onChange()
onChange(fn): () => void;
Calls fn after online changes. Returns a function that stops it.
Parameters
| Parameter | Type |
|---|---|
fn | () => void |
Returns
() => void
Example
tinylib.connection.onChange(() => (offline.hidden = tinylib.connection.online))
tinylib.now()
now(): number;
Milliseconds on Tinylib's clock, the clock the rules' ctx.now uses. Date.now() is the device's own.
Returns
number
Example
const left = view.deadline - tinylib.now()
tinylib.places
Where the person is in the app. An address is the page's path without its first /, with any ? part; the #
part stays in the page. An app with its own router uses the router instead.
Properties
| Property | Type | Description |
|---|---|---|
address | string | The current place, '' for the start screen, with any ? part. |
tinylib.places.go()
go(address, options?): void;
Moves to address without loading a page, as a link to it does. replace replaces the current place in the
history instead of adding one. Throws a TypeError for an address that starts with /.
Parameters
| Parameter | Type |
|---|---|
address | string |
options? | { replace?: boolean; } |
options.replace? | boolean |
Returns
void
Example
tinylib.places.go(`game/${id}`)
tinylib.places.onChange()
onChange(fn): () => void;
Calls fn after any move: the page's own, back and forward, or Tinylib landing the person on an address. Returns
a function that stops it.
Parameters
| Parameter | Type |
|---|---|
fn | () => void |
Returns
() => void
Example
tinylib.places.onChange(route)
tinylib.places.share()
share(address, text?): Promise<void>;
Opens Tinylib's share sheet with a link to address in the app, and text with it. Resolves when the sheet
closes.
Parameters
| Parameter | Type |
|---|---|
address | string |
text? | string |
Returns
Promise<void>
Example
await tinylib.places.share(`list/${id}`, 'Our shopping list')
tinylib.data
The persona's data in this app, kept on the device and synced to their other devices. Values are anything JSON holds. Every call is synchronous.
tinylib.data.get()
get<K>(key): DataValue<K> | undefined;
The value under key, or undefined.
Type Parameters
| Type Parameter |
|---|
K extends string |
Parameters
| Parameter | Type |
|---|---|
key | K |
Returns
DataValue<K> | undefined
tinylib.data.set()
set<K>(
key,
value,
options?
): void;
Saves value under key on the device at once, and syncs it after. audience: 'friends' shows it to the
persona's friends who have the app; 'me', the default, keeps it to the persona. Throws a TypeError for a value
JSON can't hold or a key tinylib.json declares for the rules, and a TinylibError with limit past the data cap.
A save that fails after reaches onChange with its error.
Type Parameters
| Type Parameter |
|---|
K extends string |
Parameters
Returns
void
Example
tinylib.data.set('best', 42, { audience: 'friends' })
tinylib.data.remove()
remove(key): void;
Removes the value under key. Throws a TypeError for a key tinylib.json declares for the rules.
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
void
tinylib.data.entries()
entries(prefix?): [string, unknown][];
[key, value] for every key that starts with prefix, sorted by key. Without prefix, every key.
Parameters
| Parameter | Type |
|---|---|
prefix? | string |
Returns
[string, unknown][]
Example
const entries = tinylib.data.entries('entry/')
tinylib.data.keys()
keys(prefix?): string[];
The keys that start with prefix, in entries' order.
Parameters
| Parameter | Type |
|---|---|
prefix? | string |
Returns
string[]
tinylib.data.values()
values(prefix?): unknown[];
The values under the keys that start with prefix, in entries' order.
Parameters
| Parameter | Type |
|---|---|
prefix? | string |
Returns
unknown[]
tinylib.data.onChange()
onChange(fn): () => void;
Calls fn(keys) after values change from another device or the rules, and fn(keys, error) after a save this
page made fails, with those keys back to what the store holds. Returns a function that stops it.
Parameters
| Parameter | Type |
|---|---|
fn | (keys, error?) => void |
Returns
() => void
Example
tinylib.data.onChange((keys, error) => (error ? toast(error.message) : draw()))
tinylib.friends
The persona's friends who have this app. Needs "friends" in tinylib.json's uses.
Properties
| Property | Type | Description |
|---|---|---|
data | object | Friends' values saved for friends, by their page or the rules. Every call rejects with offline. Example const best = await tinylib.friends.data.get('best') // Map of friend's id to { value, changedAt } |
data.get | Promise<Map<string, FriendValue>> | - |
data.of | RemoteStore<FriendValue> | - |
tinylib.friends.list()
list(): Promise<object[]>;
Resolves with the persona's friends who have the app. Rejects with offline.
Returns
Promise<object[]>
Example
const friends = await tinylib.friends.list()
tinylib.friends.sendApp()
sendApp(): Promise<void>;
Opens Tinylib's Send sheet, where the person sends the app to friends. Resolves when it closes, without saying who
was picked. Rejects with offline or limit.
Returns
Promise<void>
FriendValue
A friend's value.
Properties
| Property | Type | Description |
|---|---|---|
value | unknown | - |
changedAt | number | When it last changed, on Tinylib's clock. |
RemoteStore
A read-only store that lives on Tinylib's servers, read with tinylib.data's verbs, each async.
Type Parameters
| Type Parameter |
|---|
V |
RemoteStore.get()
get(key): Promise<V | undefined>;
Resolves with the value under key, or undefined.
Parameters
| Parameter | Type |
|---|---|
key | string |
Returns
Promise<V | undefined>
RemoteStore.keys()
keys(prefix?): Promise<string[]>;
Resolves with the keys that start with prefix, sorted.
Parameters
| Parameter | Type |
|---|---|
prefix? | string |
Returns
Promise<string[]>
RemoteStore.values()
values(prefix?): Promise<V[]>;
Resolves with the values under the keys that start with prefix, in keys' order.
Parameters
| Parameter | Type |
|---|---|
prefix? | string |
Returns
Promise<V[]>
RemoteStore.entries()
entries(prefix?): Promise<[string, V][]>;
Resolves with [key, value] for every key that starts with prefix, sorted by key.
Parameters
| Parameter | Type |
|---|---|
prefix? | string |
Returns
Promise<[string, V][]>
tinylib.rooms
The persona's rooms in this app, each by its id. Acting in a room is on the room open resolves with.
tinylib.rooms.create()
create(kind, options?): Promise<{
id: string;
}>;
Creates a room of kind, the name of a rules.js export, with the persona as its first member and options passed
to the kind's create. Resolves with the room's id. Rejects with refused when the rules refuse it, limit, or
offline. Throws a TypeError for options JSON can't hold.
Parameters
| Parameter | Type |
|---|---|
kind | string |
options? | unknown |
Returns
Promise<{
id: string;
}>
Example
const { id } = await tinylib.rooms.create('game')
tinylib.rooms.open()
open<K>(id): Promise<OpenRoom<RoomMessage<K>>>;
Opens the room on this page and connects the persona to it. Resolves with the open room. Rejects with
not_member, ended, offline or failed.
Type Parameters
| Type Parameter | Default type |
|---|---|
K extends string | string |
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<OpenRoom<RoomMessage<K>>>
Example
const room = await tinylib.rooms.open(id)
tinylib.rooms.join()
join(code): Promise<{
id: string;
}>;
Joins the room a short code names. Resolves with its id. Rejects with not_found for a code no room of the app
has, refused when the rules refuse the join, limit after too many codes, or offline.
Parameters
| Parameter | Type |
|---|---|
code | string |
Returns
Promise<{
id: string;
}>
Example
const { id } = await tinylib.rooms.join('K7QD')
tinylib.rooms.invite()
invite(id, personaId?): Promise<void>;
Invites personaId, a friend or someone from the persona's rooms. Without personaId, opens Tinylib's invite
sheet for the room, which also shares its link. Resolves once sent, or when the sheet closes. Inviting someone who
blocked the persona resolves as if sent. Rejects with refused when the rules refuse it, not_member, ended,
limit, or offline.
Parameters
| Parameter | Type |
|---|---|
id | string |
personaId? | string |
Returns
Promise<void>
Example
await tinylib.rooms.invite(id, friend.id)
tinylib.rooms.getLink()
getLink(id, options?): Promise<{
url: string;
code: string | null;
}>;
Resolves with the room's one link, made if it has none, and its short code, or null. code: true adds a short
code to the same link if it has none. Rejects with refused when the rules refuse it, not_member, ended, or
offline.
Parameters
| Parameter | Type |
|---|---|
id | string |
options? | { code?: boolean; } |
options.code? | boolean |
Returns
Promise<{
url: string;
code: string | null;
}>
Example
const { url, code } = await tinylib.rooms.getLink(id, { code: true })
tinylib.rooms.deleteLink()
deleteLink(id): Promise<void>;
Stops the room's link and its short code for good; getLink makes a new one. Rejects with refused when the rules
refuse it, not_member, ended, or offline.
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<void>
tinylib.rooms.leave()
leave(id): Promise<void>;
Takes the persona out of the room, which stays in list() marked left. Rejects with offline.
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<void>
tinylib.rooms.list()
list(): Promise<RoomItem[]>;
Resolves with the persona's rooms in this app: current ones, then past ones.
Returns
Promise<RoomItem[]>
Example
const waiting = (await tinylib.rooms.list()).filter((room) => room.waiting)
tinylib.rooms.onChange()
onChange(fn): () => void;
Calls fn with the list after it changes. Returns a function that stops it.
Parameters
| Parameter | Type |
|---|---|
fn | (list) => void |
Returns
() => void
tinylib.rooms.data()
data(roomId): RemoteStore<unknown>;
The data the rules keep with the room, for its members during the room and after. Someone who left reads it as it
was when they left. Each call rejects with not_member for a room the persona was never in, or offline.
Parameters
| Parameter | Type |
|---|---|
roomId | string |
Returns
RemoteStore<unknown>
Example
const moves = await tinylib.rooms.data(id).values('move/')
room
A room the page has open, from tinylib.rooms.open.
Type Parameters
| Type Parameter | Default type |
|---|---|
M | unknown |
Properties
| Property | Type | Description |
|---|---|---|
id | string | - |
kind | string | The kind's name, the rules.js export it runs. |
ended | boolean | - |
left | boolean | True once the persona is no longer in the room. |
room.close()
close(): void;
Closes the room on this page. The persona stays connected while another page or device has it open.
Returns
void
room.send()
send(action, data?): Promise<void>;
Sends the action action, with data, to the rules. Resolves once the rules accept it. Rejects with refused and
the rules' sentence when they refuse it, and with ended, not_member, offline, or failed once the page closed
the room. Throws a TypeError for an action that isn't a string, or data JSON can't hold.
Parameters
| Parameter | Type |
|---|---|
action | string |
data? | unknown |
Returns
Promise<void>
Example
await room.send('move', { square: 4 })
room.onMessage()
onMessage(fn): () => void;
Calls fn with everything the rules send this member. Messages that come while the room has no listener wait,
in order, for the next one added. Returns a function that stops it.
Parameters
| Parameter | Type |
|---|---|
fn | (message) => void |
Returns
() => void
Example
room.onMessage(({ view }) => draw(view))
room.onChange()
onChange(fn): () => void;
Calls fn when the room ends or the persona is no longer in it. Returns a function that stops it.
Parameters
| Parameter | Type |
|---|---|
fn | () => void |
Returns
() => void
RoomListItem
type RoomListItem = RoomItem;
One of the persona's rooms, as rooms.list() gives it.
Properties
| Property | Type | Description |
|---|---|---|
id | string | - |
kind | string | - |
name | string | null | The name the rules gave the room, or null until they do. |
status | string | null | The line the rules last set for the persona with ctx.status, or null. |
waiting | boolean | Whether that status says the room waits on the persona. |
members | Member[] | The current members; for a past room, the members at its end. |
ended | boolean | - |
closed | boolean | True for a room Tinylib closed because it sat unused or everyone left. Such a room shows no status. |
left | boolean | True once the persona left or was removed. |
endedAt | number | null | When it ended, on Tinylib's clock, or null. |
tinylib.invitations
The persona's invitations to rooms of this app.
tinylib.invitations.list()
list(): Promise<Invitation[]>;
Resolves with every invitation, without taking any from Tinylib's card.
Returns
Promise<Invitation[]>
tinylib.invitations.handle()
handle(pick, fn): () => void;
Takes the invitations pick returns true for: fn gets them now and after every change, and Tinylib shows its own
card only for those no handler takes. An invitation two handlers pick goes to both. Returns a function that stops
it. Throws a TypeError unless both are functions.
Parameters
| Parameter | Type |
|---|---|
pick | (invitation) => boolean |
fn | (invitations) => void |
Returns
() => void
Example
tinylib.invitations.handle((invitation) => invitation.from.id === opponent.id, showRematch)
invitation
An invitation to a room.
Properties
| Property | Type | Description |
|---|---|---|
id | string | - |
from | object | - |
from.id | string | - |
from.name | string | - |
kind | string | - |
name | string | null | The room's name, or null until the rules give it one. |
at | number | When it was sent, on Tinylib's clock. |
invitation.accept()
accept(): Promise<{
id: string;
}>;
Joins the room. Resolves with its id. Rejects with refused when the rules refuse the join, ended, or offline.
Returns
Promise<{
id: string;
}>
invitation.dismiss()
dismiss(): Promise<void>;
Turns the invitation down. Rejects with offline.
Returns
Promise<void>
tinylib.reminders
The persona's reminders in this app, each by its name. Needs "notifications" in tinylib.json's uses.
tinylib.reminders.set()
set(name, options): Promise<void>;
Sets the reminder name, replacing one set under that name before. With the app's notifications switch off,
Tinylib asks the person first. Rejects with notifications_off if they leave it off, and with refused or limit
for one Tinylib can't set. Throws a TypeError for options that don't have a title and exactly one of at and
repeat.
Parameters
| Parameter | Type |
|---|---|
name | string |
options | ReminderOptions |
Returns
Promise<void>
Example
await tinylib.reminders.set('evening', { title: 'Journal', text: 'How was today?', repeat: tinylib.reminders.daily('18:00') })
tinylib.reminders.daily()
daily(time): Repeat;
Every day at time, 'HH:MM' where the reminder is set. Throws a TypeError for another time.
Parameters
| Parameter | Type |
|---|---|
time | string |
Returns
tinylib.reminders.weekly()
tinylib.reminders.monthly()
monthly(day, time): Repeat;
On day day, 1 to 31, of every month at time. Throws a TypeError for another day or time.
Parameters
| Parameter | Type |
|---|---|
day | number |
time | string |
Returns
tinylib.reminders.list()
list(): Promise<ReminderItem[]>;
Resolves with the persona's reminders in this app.
Returns
Promise<ReminderItem[]>
tinylib.reminders.cancel()
cancel(name): Promise<void>;
Cancels the reminder name.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
Promise<void>
ReminderOptions
Properties
| Property | Type | Description |
|---|---|---|
title | string | - |
text? | string | - |
at? | string | number | A local date and time such as '2026-10-06T18:00', or a time on Tinylib's clock. |
repeat? | Repeat | From daily, weekly or monthly. A reminder has exactly one of at and repeat. |
address? | string | Where the reminder lands; '' is the start screen. |
Reminder
type Reminder = ReminderItem;
One of the persona's reminders, as reminders.list() gives it.
Properties
| Property | Type | Description |
|---|---|---|
name | string | - |
title | string | - |
text | string | null | - |
address | string | - |
at | string | number | null | A local date and time such as '2026-10-06T18:00', or a time on Tinylib's clock; null when it repeats. |
repeat | Repeat | null | - |
timeZone | string | The time zone it was set in. |
next | number | null | When it next goes off, on Tinylib's clock. |
Repeat
type Repeat =
| {
every: "day";
time: string;
}
| {
every: "week";
days: Day[];
time: string;
}
| {
every: "month";
day: number;
time: string;
};
Day
type Day = "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun";
tinylib.block()
block(personaId): Promise<boolean>;
Opens Tinylib's confirmation to block personaId. Resolves true if the person blocked them, false if they backed
out. Rejects with offline.
Parameters
| Parameter | Type |
|---|---|
personaId | string |
Returns
Promise<boolean>
Example
if (await tinylib.block(opponent.id)) tinylib.places.go('')
tinylib.report()
report(personaId): Promise<boolean>;
Opens Tinylib's report sheet for personaId. Resolves true if the person sent a report, false if they backed out.
Rejects with offline or limit.
Parameters
| Parameter | Type |
|---|---|
personaId | string |
Returns
Promise<boolean>
Types
Register
Types an app's data and rooms, in one declaration in the app:
declare module 'tinylib-sdk' {
interface Register {
data: { score: number; [key: `entry/${string}`]: string }
rooms: { game: { view: GameView } } // what each kind's rules send
}
}
DataKey
type DataKey = keyof DataShape & string;
A key of Register's data, or any string without one.
DataValue
type DataValue<K> = K extends keyof DataShape ? DataShape[K] : unknown;
The value Register's data gives a key, or unknown.
Type Parameters
| Type Parameter |
|---|
K extends string |
RoomKind
type RoomKind = keyof RoomShape & string;
A kind of room Register's rooms names, or any string without one.
RoomMessage
type RoomMessage<K> = K extends keyof RoomShape ? RoomShape[K] : unknown;
The messages Register's rooms gives a kind, or unknown.
Type Parameters
| Type Parameter |
|---|
K extends string |