Tinylib
DiscoverDocsSign in
Sign in
Tinylib
AboutDiscoverDocsMake an appPricingTermsPrivacyDeveloper TermsContact

Start

  • Quickstart
  • How Tinylib works

Guides

  • Data
  • Rooms and rules
  • Games
  • Friends
  • Places and links
  • Reminders and notifications
  • Publishing
  • Errors and offline
  • Platforms

Client API

  • tinylib
  • tinylib.data
  • tinylib.rooms
  • tinylib.invitations
  • tinylib.friends
  • tinylib.places
  • tinylib.reminders
  • Types
    • Register
    • DataKey
    • DataValue
    • RoomKind
    • RoomView
    • RoomEvent
    • Member
    • Audience
  • tinylib-sdk/kits

Rules API

  • Kinds
  • ctx

Reference

  • tinylib.json
  • Command line
  • Limits

Plain text

  • llms.txt
  • llms-full.txt

Types

Register

interface Register
Declares your app's data and room types, so the calls of tinylib use them. data maps each key, or key template, to its value's type. rooms maps each kind to the type its view returns and the type of the events its rules emit.

Declare it in a file with an import or export, such as the import type line below. In a file with neither, declare module 'tinylib-sdk' replaces the package's types instead of adding to them.

tinylib-env.d.ts
import type {} from 'tinylib-sdk' type GameView = { board: string[]; turn: 'x' | 'o'; winner: 'x' | 'o' | 'draw' | null; you: 'x' | 'o' | null } declare module 'tinylib-sdk' { interface Register { data: { best: number; [key: `entry/${string}`]: string } rooms: { game: { view: GameView; event: { sound: string } } } } }
app.ts
const best = tinylib.data.get('best') // number | undefined tinylib.rooms.follow<'game'>(id, ({ view }) => { if (view) drawBoard(view.board) // view is a GameView })

DataKey

type DataKey = keyof DataShape & string type DataShape = Register extends { data: infer D } ? D : Record<string, unknown>
A key of tinylib.data: one that data in Register declares, or any string when it declares none.

DataValue

type DataValue<K extends string> = K extends keyof DataShape ? DataShape[K] : unknown type DataShape = Register extends { data: infer D } ? D : Record<string, unknown>
The type of the value under key K, as data in Register declares it, or unknown when it doesn't.

RoomKind

type RoomKind = keyof RoomShape & string type RoomShape = Register extends { rooms: infer R } ? R : Record<string, unknown>
A kind: one that rooms in Register declares, or any string when it declares none.

RoomView

type RoomView<K extends string> = RoomTypes<K> extends { view: infer V } ? V : unknown type RoomTypes<K extends string> = K extends keyof RoomShape ? RoomShape[K] : unknown type RoomShape = Register extends { rooms: infer R } ? R : Record<string, unknown>
The type of a member's view in rooms of kind K, as rooms in Register declares it, or unknown when it doesn't.

RoomEvent

type RoomEvent<K extends string> = RoomTypes<K> extends { event: infer E } ? E : unknown type RoomTypes<K extends string> = K extends keyof RoomShape ? RoomShape[K] : unknown type RoomShape = Register extends { rooms: infer R } ? R : Record<string, unknown>
The type of the events the rules emit in rooms of kind K, as rooms in Register declares it, or unknown when it doesn't.

Member

interface Member
A user as your app sees them: in ctx.members in the rules, and in tinylib.friends.list and an invitation's from in your client.

Properties

idstring
The same in every room of your app.
namestring
Names change and aren't unique, so keep id in state, not name.
guestboolean
True for a guest: a user without a Tinylib account, known only on the device they use. A guest has data and acts in rooms like anyone, and gets no notifications or invitations.

Audience

type Audience = 'me' | 'friends'
Who can read a value: 'me', the user alone, or 'friends', the user and their friends who have the app.
Previoustinylib.remindersNexttinylib-sdk/kits

On this page

  • Register
  • DataKey
  • DataValue
  • RoomKind
  • RoomView
  • RoomEvent
  • Member
  • Audience