Lib
@probability-nz/lib
Section titled “@probability-nz/lib”Non-React utilities and types for Probability plugins. Usable in Node, server-side validators, or non-React clients.
pnpm buildShared utilities, types, and pure functions for Probability plugins.
Defined in: packages/types/dist/doc.d.ts:11
A named orientation of a piece (e.g. die face)
Properties
Section titled “Properties”name:
string
Defined in: packages/types/dist/doc.d.ts:12
rotation
Section titled “rotation”rotation:
Vector3Tuple
Defined in: packages/types/dist/doc.d.ts:13
GameState
Section titled “GameState”Defined in: packages/types/dist/doc.d.ts:177
The Automerge document shape — a digital analog of the physical game. Pieces are stacked on each other and positioned relatively.
Example
Section titled “Example”// A token, sitting on a card, sitting on a chessboard{ "$schema": "https://registry.probability.nz/npm/@probability-nz/types/-/types-0.0.0.tgz/dist/analog.json", "templates": {}, "children": [ { "name": "Chess Board", "position": [0, 0.1, 0], "locked": true, "src": "Chess_Board.glb", "children": [ { "name": "card", "position": [0, 0.002, 0], "children": [ { "name": "pawn", "position": [0, 0.3, 0], "children": [] } ] } ] } ]}Properties
Section titled “Properties”__automergeMoves?
Section titled “__automergeMoves?”
optional__automergeMoves:__AutomergeMoves
Defined in: packages/types/dist/doc.d.ts:185
Tracks Automerge objectId changes when pieces are reparented.
$schema
Section titled “$schema”$schema:
"https://registry.probability.nz/npm/@probability-nz/types/-/types-0.0.0.tgz/dist/analog.json"
Defined in: packages/types/dist/doc.d.ts:178
children
Section titled “children”children:
Piece[]
Defined in: packages/types/dist/doc.d.ts:179
templates
Section titled “templates”templates:
Templates
Defined in: packages/types/dist/doc.d.ts:180
HashProps
Section titled “HashProps”Defined in: packages/types/dist/hashroute.d.ts:19
Connection context passed to plugins via the URL hash.
Example
Section titled “Example”https://example.com/plugin#{"doc":"automerge:...","sync":["wss://..."],"delegation":"..."}Properties
Section titled “Properties”delegation?
Section titled “delegation?”
optionaldelegation:string
Defined in: packages/types/dist/hashroute.d.ts:28
Will be a base64url-encoded KeyHive/Beelay
Ed25519 Signed<Delegation>.
doc:
AutomergeUrl
Defined in: packages/types/dist/hashroute.d.ts:21
Automerge document URL
sync: [
string,...string[]]
Defined in: packages/types/dist/hashroute.d.ts:23
Sync server WebSocket URLs
Defined in: packages/types/dist/doc.d.ts:59
A game piece in a manifest or document
Extends
Section titled “Extends”Properties
Section titled “Properties”children?
Section titled “children?”
optionalchildren:Piece[]
Defined in: packages/types/dist/doc.d.ts:60
color?
Section titled “color?”
optionalcolor:string|null
Defined in: packages/types/dist/doc.d.ts:46
CSS color string, or null for no tint
Default
Section titled “Default”"#808080"Inherited from
Section titled “Inherited from”faces?
Section titled “faces?”
optionalfaces:Face[]
Defined in: packages/types/dist/doc.d.ts:53
Named face orientations (e.g. for dice)
Inherited from
Section titled “Inherited from”locked?
Section titled “locked?”
optionallocked:boolean
Defined in: packages/types/dist/doc.d.ts:51
Make piece non-interactive?
Default
Section titled “Default”falseInherited from
Section titled “Inherited from”
optionalname:string
Defined in: packages/types/dist/doc.d.ts:20
Inherited from
Section titled “Inherited from”position?
Section titled “position?”
optionalposition:Vector3Tuple
Defined in: packages/types/dist/doc.d.ts:31
World position in meters.
Default
Section titled “Default”[0, 0, 0]Inherited from
Section titled “Inherited from”rotation?
Section titled “rotation?”
optionalrotation:Vector3Tuple
Defined in: packages/types/dist/doc.d.ts:41
Euler rotation (degrees)
Default
Section titled “Default”[0, 0, 0]Inherited from
Section titled “Inherited from”scale?
Section titled “scale?”
optionalscale:Vector3Tuple
Defined in: packages/types/dist/doc.d.ts:36
Unitless multiplier applied to the model.
Default
Section titled “Default”[1, 1, 1]Inherited from
Section titled “Inherited from”
optionalsrc:string
Defined in: packages/types/dist/doc.d.ts:22
Path to a glTF/GLB model
Inherited from
Section titled “Inherited from”template?
Section titled “template?”
optionaltemplate:string
Defined in: packages/types/dist/doc.d.ts:26
Key into the sibling templates object to inherit defaults from
Inherited from
Section titled “Inherited from”PieceTemplate
Section titled “PieceTemplate”Defined in: packages/types/dist/doc.d.ts:19
Piece template — shared fields for pieces
Extended by
Section titled “Extended by”Properties
Section titled “Properties”color?
Section titled “color?”
optionalcolor:string|null
Defined in: packages/types/dist/doc.d.ts:46
CSS color string, or null for no tint
Default
Section titled “Default”"#808080"faces?
Section titled “faces?”
optionalfaces:Face[]
Defined in: packages/types/dist/doc.d.ts:53
Named face orientations (e.g. for dice)
locked?
Section titled “locked?”
optionallocked:boolean
Defined in: packages/types/dist/doc.d.ts:51
Make piece non-interactive?
Default
Section titled “Default”false
optionalname:string
Defined in: packages/types/dist/doc.d.ts:20
position?
Section titled “position?”
optionalposition:Vector3Tuple
Defined in: packages/types/dist/doc.d.ts:31
World position in meters.
Default
Section titled “Default”[0, 0, 0]rotation?
Section titled “rotation?”
optionalrotation:Vector3Tuple
Defined in: packages/types/dist/doc.d.ts:41
Euler rotation (degrees)
Default
Section titled “Default”[0, 0, 0]scale?
Section titled “scale?”
optionalscale:Vector3Tuple
Defined in: packages/types/dist/doc.d.ts:36
Unitless multiplier applied to the model.
Default
Section titled “Default”[1, 1, 1]
optionalsrc:string
Defined in: packages/types/dist/doc.d.ts:22
Path to a glTF/GLB model
template?
Section titled “template?”
optionaltemplate:string
Defined in: packages/types/dist/doc.d.ts:26
Key into the sibling templates object to inherit defaults from
Templates
Section titled “Templates”Templates =
Record<string,PieceTemplate>
Defined in: packages/types/dist/doc.d.ts:83
Reusable piece defaults, keyed by template name. Templates can inherit from
other templates via the template field, and share syntax with pieces minus
a children property.
Example
Section titled “Example”{ "$schema": "https://registry.probability.nz/npm/@probability-nz/types/-/types-0.0.0.tgz/dist/analog.json", "templates": { "defaults": { "scale": [0.1, 0.1, 0.1] }, "redToken": { "template": "defaults", "name": "Red token", "src": "redToken.glb" } }, "children": [ { "template": "redToken", "position": [0.0, 0, 0] }, { "template": "redToken", "position": [0.1, 0, 0] }, { "template": "redToken", "position": [0.2, 0, 0] } ]}parseHashProps()
Section titled “parseHashProps()”parseHashProps(
hash):HashProps|undefined
Defined in: packages/lib/src/parseHashProps.ts:17
Parse plugin context from the URL hash.
Parameters
Section titled “Parameters”string
Expects location.hash format (with # prefix).
Returns
Section titled “Returns”HashProps | undefined
undefined if the hash is missing or unparseable.
Presence
Section titled “Presence”FocusOp
Section titled “FocusOp”Defined in: packages/types/dist/presence.d.ts:27
Cursor focus (what the user is looking at) — no automerge equivalent
Properties
Section titled “Properties”action
Section titled “action”action:
"focus"
Defined in: packages/types/dist/presence.d.ts:28
path:
AnchoredPath
Defined in: packages/types/dist/presence.d.ts:29
MoveOp
Section titled “MoveOp”Defined in: packages/types/dist/presence.d.ts:45
Move — no automerge equivalent yet (planned feature)
Properties
Section titled “Properties”action
Section titled “action”action:
"move"
Defined in: packages/types/dist/presence.d.ts:46
path:
AnchoredPath
Defined in: packages/types/dist/presence.d.ts:47
to:
AnchoredPath
Defined in: packages/types/dist/presence.d.ts:48
PresenceState
Section titled “PresenceState”Defined in: packages/types/dist/presence.d.ts:54
Presence state broadcast between peers
Properties
Section titled “Properties”client?
Section titled “client?”
optionalclient:string
Defined in: packages/types/dist/presence.d.ts:56
color?
Section titled “color?”
optionalcolor:string
Defined in: packages/types/dist/presence.d.ts:55
cursors?
Section titled “cursors?”
optionalcursors:Record<string, {position?:Vector3Tuple;rotation?:Vector3Tuple; }>
Defined in: packages/types/dist/presence.d.ts:59
Defined in: packages/types/dist/presence.d.ts:57
Defined in: packages/types/dist/presence.d.ts:35
Anchored version of automerge’s PutPatch
Properties
Section titled “Properties”action
Section titled “action”action:
"put"
Defined in: packages/types/dist/presence.d.ts:36
conflict?
Section titled “conflict?”
optionalconflict:boolean
Defined in: packages/types/dist/presence.d.ts:39
path:
AnchoredPath
Defined in: packages/types/dist/presence.d.ts:37
value:
JsonValue
Defined in: packages/types/dist/presence.d.ts:38
Client
Section titled “Client”Client =
string
Defined in: packages/types/dist/presence.d.ts:16
Client identifier in npm format: name@version or name#commit
(e.g. "my-plugin@1.0.0", "@garbo-succus/probability-nz#c0mM1t").
Color =
string
Defined in: packages/types/dist/presence.d.ts:10
Any valid CSS color string (e.g. "red", "#abc", "rgb(0,0,0)").
getPeerName()
Section titled “getPeerName()”getPeerName(
peerId):string
Defined in: packages/lib/src/peerName.ts:43
Deterministic, friendly peer name from a peer id (e.g. “Brave Penguin”). Seeded with FNV-1a to compensate for the upstream generator’s weak string seeding.
Parameters
Section titled “Parameters”peerId
Section titled “peerId”string
Returns
Section titled “Returns”string
toColor()
Section titled “toColor()”toColor(
seed):string
Defined in: packages/lib/src/toColor.ts:33
Deterministic, visually distinct color from a string.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
Example
Section titled “Example”toColor('player-1'); // '#a4c032'Advanced
Section titled “Advanced”GameManifest
Section titled “GameManifest”Defined in: packages/types/dist/doc.d.ts:141
Static game definition — imported to create a new GameState. Similar to a
GameState but with a scenarios array on the root instead of children.
Example
Section titled “Example”// 2-4 and 4-8 player scenarios{ "$schema": "https://registry.probability.nz/npm/@probability-nz/types/-/types-0.0.0.tgz/dist/analog.json", "templates": { "token": { "src": "token.glb" } }, "scenarios": [ { "name": "2-4 player setup", "children": [ { "name": "Game board", "src": "gameboard.glb", "children": [ { "template": "token" }, { "template": "token" }, { "template": "token" }, { "template": "token" } ] } ] }, { "name": "4-8 player setup", "children": [ { "name": "Game board", "src": "gameboard.glb", "children": [ { "template": "token" }, { "template": "token" }, { "template": "token" }, { "template": "token" }, { "template": "token" }, { "template": "token" }, { "template": "token" }, { "template": "token" } ] } ] } ]}Properties
Section titled “Properties”$schema
Section titled “$schema”$schema:
"https://registry.probability.nz/npm/@probability-nz/types/-/types-0.0.0.tgz/dist/analog.json"
Defined in: packages/types/dist/doc.d.ts:142
scenarios
Section titled “scenarios”scenarios:
Scenario[]
Defined in: packages/types/dist/doc.d.ts:144
templates
Section titled “templates”templates:
Templates
Defined in: packages/types/dist/doc.d.ts:143
Scenario
Section titled “Scenario”Defined in: packages/types/dist/doc.d.ts:88
A named starting arrangement of pieces
Properties
Section titled “Properties”children
Section titled “children”children:
Piece[]
Defined in: packages/types/dist/doc.d.ts:90
optionalname:string
Defined in: packages/types/dist/doc.d.ts:89
Vector3Tuple
Section titled “Vector3Tuple”Vector3Tuple = [
number,number,number]
Defined in: packages/types/dist/doc.d.ts:6
[x, y, z] — right-handed Y-up coordinate system (from Three.js).
loadManifest()
Section titled “loadManifest()”loadManifest(
url):Promise<GameManifest>
Defined in: packages/lib/src/manifest.ts:37
Fetch a game manifest, resolving asset URLs.
Parameters
Section titled “Parameters”string
Must end with /.
Returns
Section titled “Returns”Promise<GameManifest>
Throws
Section titled “Throws”On network errors, missing main field, or schema validation failure.
Example
Section titled “Example”const manifest = await loadManifest('https://registry.probability.nz/games/chess/');buildGameState for the next step after loading.
objectIdToPath()
Section titled “objectIdToPath()”objectIdToPath(
doc,objId):Prop[] |undefined
Defined in: packages/lib/src/objectIdToPath.ts:12
Find the path to an object in an Automerge document by its ID. Will be removed when Automerge adds native support.
Parameters
Section titled “Parameters”Doc<unknown>
string
Returns
Section titled “Returns”Prop[] | undefined
Functions
Section titled “Functions”assertGameState()
Section titled “assertGameState()”assertGameState(
schema,value):asserts value is GameState
Defined in: packages/lib/src/validate.ts:36
Assert that value is a valid GameState for the given schema.
Parameters
Section titled “Parameters”schema
Section titled “schema”JsonSchema
unknown
Returns
Section titled “Returns”asserts value is GameState
Throws
Section titled “Throws”On validation failure.
assertPresenceState()
Section titled “assertPresenceState()”assertPresenceState(
schema,value):asserts value is PresenceState
Defined in: packages/lib/src/validate.ts:48
Assert that value is a valid PresenceState for the given schema.
Parameters
Section titled “Parameters”schema
Section titled “schema”JsonSchema
unknown
Returns
Section titled “Returns”asserts value is PresenceState
Throws
Section titled “Throws”On validation failure.
buildGameState()
Section titled “buildGameState()”buildGameState(
__namedParameters,scenarioIndex):GameState
Defined in: packages/lib/src/buildGameState.ts:8
Build a GameState from a loaded manifest and scenario index.
Parameters
Section titled “Parameters”__namedParameters
Section titled “__namedParameters”scenarioIndex
Section titled “scenarioIndex”number
Returns
Section titled “Returns”Throws
Section titled “Throws”If scenarioIndex is out of bounds.
loadManifest for fetching the manifest.
Type Aliases
Section titled “Type Aliases”AnchoredPath
Section titled “AnchoredPath”AnchoredPath = [
string,...Prop[]]
Defined in: packages/types/dist/presence.d.ts:22
A path anchored to a specific Automerge object. First element is always an ObjID string.
Example
Section titled “Example”`["2@abc123", "children", 0, "position"]`AutomergeUrl
Section titled “AutomergeUrl”AutomergeUrl =
RepoAutomergeUrl&`automerge:${string}`
Defined in: packages/types/dist/hashroute.d.ts:3
Automerge document URL (e.g. automerge:111111111111111111).
JsonValue
Section titled “JsonValue”JsonValue =
string|number|boolean|null|JsonArray|JsonObject
Defined in: packages/types/dist/hashroute.d.ts:10
JSON-serializable value
Prop =
string|number
Defined in: node_modules/.pnpm/@automerge+automerge@3.2.4/node_modules/@automerge/automerge/dist/wasm_types.d.ts:8
Variables
Section titled “Variables”SCHEMA_URL
Section titled “SCHEMA_URL”
constSCHEMA_URL:"https://registry.probability.nz/npm/@probability-nz/types/-/types-0.0.0.tgz/dist/analog.json"="https://registry.probability.nz/npm/@probability-nz/types/-/types-0.0.0.tgz/dist/analog.json"
Defined in: packages/types/dist/doc.d.ts:1