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

PropertyType
personaPersona
connectionConnection
placesPlaces
dataData
friendsFriends
roomsRooms
invitationsInvitations
remindersReminders

tinylib.persona

The person inside this app, always current.

Properties

PropertyTypeDescription
idstringOnly this app sees it: the same person has a different id in every app.
namestringThe person's name, the one they gave Tinylib. They change it on their profile in Tinylib, not in an app.
notificationsOnbooleanWhether 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
ParameterType
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
ParameterType
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

PropertyType
onlineboolean

tinylib.connection.onChange()

onChange(fn): () => void;

Calls fn after online changes. Returns a function that stops it.

Parameters
ParameterType
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

PropertyTypeDescription
addressstringThe 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
ParameterType
addressstring
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
ParameterType
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
ParameterType
addressstring
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
ParameterType
keyK
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
ParameterType
keyK
valueDataValue<K>
options?{ audience?: Audience; }
options.audience?Audience
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
ParameterType
keystring
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
ParameterType
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
ParameterType
prefix?string
Returns

string[]

tinylib.data.values()

values(prefix?): unknown[];

The values under the keys that start with prefix, in entries' order.

Parameters
ParameterType
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
ParameterType
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

PropertyTypeDescription
dataobjectFriends' 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.getPromise<Map<string, FriendValue>>-
data.ofRemoteStore<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

PropertyTypeDescription
valueunknown-
changedAtnumberWhen 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
ParameterType
keystring
Returns

Promise<V | undefined>

RemoteStore.keys()

keys(prefix?): Promise<string[]>;

Resolves with the keys that start with prefix, sorted.

Parameters
ParameterType
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
ParameterType
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
ParameterType
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
ParameterType
kindstring
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 ParameterDefault type
K extends stringstring
Parameters
ParameterType
idstring
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
ParameterType
codestring
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
ParameterType
idstring
personaId?string
Returns

Promise<void>

Example
await tinylib.rooms.invite(id, friend.id)
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
ParameterType
idstring
options?{ code?: boolean; }
options.code?boolean
Returns

Promise<{ url: string; code: string | null; }>

Example
const { url, code } = await tinylib.rooms.getLink(id, { code: true })
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
ParameterType
idstring
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
ParameterType
idstring
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
ParameterType
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
ParameterType
roomIdstring
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 ParameterDefault type
Munknown

Properties

PropertyTypeDescription
idstring-
kindstringThe kind's name, the rules.js export it runs.
endedboolean-
leftbooleanTrue 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
ParameterType
actionstring
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
ParameterType
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
ParameterType
fn() => void
Returns

() => void

RoomListItem

type RoomListItem = RoomItem;

One of the persona's rooms, as rooms.list() gives it.

Properties

PropertyTypeDescription
idstring-
kindstring-
namestring | nullThe name the rules gave the room, or null until they do.
statusstring | nullThe line the rules last set for the persona with ctx.status, or null.
waitingbooleanWhether that status says the room waits on the persona.
membersMember[]The current members; for a past room, the members at its end.
endedboolean-
closedbooleanTrue for a room Tinylib closed because it sat unused or everyone left. Such a room shows no status.
leftbooleanTrue once the persona left or was removed.
endedAtnumber | nullWhen 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
ParameterType
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

PropertyTypeDescription
idstring-
fromobject-
from.idstring-
from.namestring-
kindstring-
namestring | nullThe room's name, or null until the rules give it one.
atnumberWhen 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
ParameterType
namestring
optionsReminderOptions
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
ParameterType
timestring
Returns

Repeat

tinylib.reminders.weekly()

weekly(days, time): Repeat;

On each of days at time. Throws a TypeError for no days, a day twice, or a time that isn't 'HH:MM'.

Parameters
ParameterType
daysDay[]
timestring
Returns

Repeat

Example
tinylib.reminders.weekly(['mon', 'tue', 'wed', 'thu', 'fri'], '09:30')

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
ParameterType
daynumber
timestring
Returns

Repeat

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
ParameterType
namestring
Returns

Promise<void>

ReminderOptions

Properties

PropertyTypeDescription
titlestring-
text?string-
at?string | numberA local date and time such as '2026-10-06T18:00', or a time on Tinylib's clock.
repeat?RepeatFrom daily, weekly or monthly. A reminder has exactly one of at and repeat.
address?stringWhere the reminder lands; '' is the start screen.

Reminder

type Reminder = ReminderItem;

One of the persona's reminders, as reminders.list() gives it.

Properties

PropertyTypeDescription
namestring-
titlestring-
textstring | null-
addressstring-
atstring | number | nullA local date and time such as '2026-10-06T18:00', or a time on Tinylib's clock; null when it repeats.
repeatRepeat | null-
timeZonestringThe time zone it was set in.
nextnumber | nullWhen 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
ParameterType
personaIdstring
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
ParameterType
personaIdstring
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