@irtio/schema
v4.4.0
Published
irtio schema DSL, type inference, canonical hash, codec, change tracking, and schema diff
Readme
@irtio/schema
Define shared multiplayer state, typed RPCs, and messages. The same schema supplies TypeScript types and binary encoding for your room and its clients.
npm install @irtio/schemaDefine state and an RPC
Create irtio/schema.ts:
import { defineSchema, entity, f32, server, singleton, u32 } from '@irtio/schema';
export const schema = defineSchema(
{
players: entity({ x: f32, y: f32 }),
match: singleton({ round: u32 }),
},
{
roles: ['player'] as const,
rpc: {
nextRound: server({}),
},
},
);players contains records addressed by id. match is one server-owned object. nextRound
declares a client-to-server call; implement it with defineRoom from @irtio/server.
For a deployed project, use the project id generated by irtio init in the schema options.
Choose a schema primitive
| Export | Use |
| --- | --- |
| entity(fields, options?) | Records with ids, ownership, and optional visibility rules |
| singleton(fields, options?) | One object, written by the server |
| bool, u8, u16, u32, i32, f32, f64 | Boolean and numeric fields |
| str(maxBytes) | A UTF-8 string with a byte limit |
| enumOf(...), struct(...), list(...), ref(...) | Enums, nested values, bounded lists, and references |
| server(spec), client(spec) | RPC declarations in either direction |
| State<typeof schema> | The inferred server state type |
A schema validates shape and bounds. Authorize actions and validate gameplay in room handlers. Append new RPCs and messages to their declaration maps to preserve existing wire ids.
For codec and tooling integrations, the package also exports state creation, snapshot and delta codecs, change tracking, canonical schema reconstruction, and schema diffing. Use the client SDK and room API to manage these during normal gameplay.
See the schema reference for field signatures, collection options, defaults, and migration rules, or start with the quickstart.
