Skip to content

Lib

Non-React utilities and types for Probability plugins. Usable in Node, server-side validators, or non-React clients.

Terminal window
pnpm build

Shared 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)

name: string

Defined in: packages/types/dist/doc.d.ts:12

rotation: Vector3Tuple

Defined in: packages/types/dist/doc.d.ts:13


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.

// 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": [] }
]
}
]
}
]
}

optional __automergeMoves: __AutomergeMoves

Defined in: packages/types/dist/doc.d.ts:185

Tracks Automerge objectId changes when pieces are reparented.

$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: Piece[]

Defined in: packages/types/dist/doc.d.ts:179

templates: Templates

Defined in: packages/types/dist/doc.d.ts:180


Defined in: packages/types/dist/hashroute.d.ts:19

Connection context passed to plugins via the URL hash.

https://example.com/plugin#{"doc":"automerge:...","sync":["wss://..."],"delegation":"..."}

optional delegation: 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

optional children: Piece[]

Defined in: packages/types/dist/doc.d.ts:60

optional color: string | null

Defined in: packages/types/dist/doc.d.ts:46

CSS color string, or null for no tint

"#808080"

PieceTemplate.color

optional faces: Face[]

Defined in: packages/types/dist/doc.d.ts:53

Named face orientations (e.g. for dice)

PieceTemplate.faces

optional locked: boolean

Defined in: packages/types/dist/doc.d.ts:51

Make piece non-interactive?

false

PieceTemplate.locked

optional name: string

Defined in: packages/types/dist/doc.d.ts:20

PieceTemplate.name

optional position: Vector3Tuple

Defined in: packages/types/dist/doc.d.ts:31

World position in meters.

[0, 0, 0]

PieceTemplate.position

optional rotation: Vector3Tuple

Defined in: packages/types/dist/doc.d.ts:41

Euler rotation (degrees)

[0, 0, 0]

PieceTemplate.rotation

optional scale: Vector3Tuple

Defined in: packages/types/dist/doc.d.ts:36

Unitless multiplier applied to the model.

[1, 1, 1]

PieceTemplate.scale

optional src: string

Defined in: packages/types/dist/doc.d.ts:22

Path to a glTF/GLB model

PieceTemplate.src

optional template: string

Defined in: packages/types/dist/doc.d.ts:26

Key into the sibling templates object to inherit defaults from

PieceTemplate.template


Defined in: packages/types/dist/doc.d.ts:19

Piece template — shared fields for pieces

optional color: string | null

Defined in: packages/types/dist/doc.d.ts:46

CSS color string, or null for no tint

"#808080"

optional faces: Face[]

Defined in: packages/types/dist/doc.d.ts:53

Named face orientations (e.g. for dice)

optional locked: boolean

Defined in: packages/types/dist/doc.d.ts:51

Make piece non-interactive?

false

optional name: string

Defined in: packages/types/dist/doc.d.ts:20

optional position: Vector3Tuple

Defined in: packages/types/dist/doc.d.ts:31

World position in meters.

[0, 0, 0]

optional rotation: Vector3Tuple

Defined in: packages/types/dist/doc.d.ts:41

Euler rotation (degrees)

[0, 0, 0]

optional scale: Vector3Tuple

Defined in: packages/types/dist/doc.d.ts:36

Unitless multiplier applied to the model.

[1, 1, 1]

optional src: string

Defined in: packages/types/dist/doc.d.ts:22

Path to a glTF/GLB model

optional template: string

Defined in: packages/types/dist/doc.d.ts:26

Key into the sibling templates object to inherit defaults from


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.

{
"$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(hash): HashProps | undefined

Defined in: packages/lib/src/parseHashProps.ts:17

Parse plugin context from the URL hash.

string

Expects location.hash format (with # prefix).

HashProps | undefined

undefined if the hash is missing or unparseable.

Defined in: packages/types/dist/presence.d.ts:27

Cursor focus (what the user is looking at) — no automerge equivalent

action: "focus"

Defined in: packages/types/dist/presence.d.ts:28

path: AnchoredPath

Defined in: packages/types/dist/presence.d.ts:29


Defined in: packages/types/dist/presence.d.ts:45

Move — no automerge equivalent yet (planned feature)

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


Defined in: packages/types/dist/presence.d.ts:54

Presence state broadcast between peers

optional client: string

Defined in: packages/types/dist/presence.d.ts:56

optional color: string

Defined in: packages/types/dist/presence.d.ts:55

optional cursors: Record<string, { position?: Vector3Tuple; rotation?: Vector3Tuple; }>

Defined in: packages/types/dist/presence.d.ts:59

optional op: FocusOp | MoveOp | PutOp

Defined in: packages/types/dist/presence.d.ts:57


Defined in: packages/types/dist/presence.d.ts:35

Anchored version of automerge’s PutPatch

action: "put"

Defined in: packages/types/dist/presence.d.ts:36

optional conflict: 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 = 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(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.

string

string


toColor(seed): string

Defined in: packages/lib/src/toColor.ts:33

Deterministic, visually distinct color from a string.

string

string

toColor('player-1'); // '#a4c032'

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.

// 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" }
]
}
]
}
]
}

$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: Scenario[]

Defined in: packages/types/dist/doc.d.ts:144

templates: Templates

Defined in: packages/types/dist/doc.d.ts:143


Defined in: packages/types/dist/doc.d.ts:88

A named starting arrangement of pieces

children: Piece[]

Defined in: packages/types/dist/doc.d.ts:90

optional name: string

Defined in: packages/types/dist/doc.d.ts:89


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(url): Promise<GameManifest>

Defined in: packages/lib/src/manifest.ts:37

Fetch a game manifest, resolving asset URLs.

string

Must end with /.

Promise<GameManifest>

On network errors, missing main field, or schema validation failure.

const manifest = await loadManifest('https://registry.probability.nz/games/chess/');

buildGameState for the next step after loading.


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.

Doc<unknown>

string

Prop[] | undefined

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.

JsonSchema

unknown

asserts value is GameState

On validation failure.


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.

JsonSchema

unknown

asserts value is PresenceState

On validation failure.


buildGameState(__namedParameters, scenarioIndex): GameState

Defined in: packages/lib/src/buildGameState.ts:8

Build a GameState from a loaded manifest and scenario index.

GameManifest

number

GameState

If scenarioIndex is out of bounds.

loadManifest for fetching the manifest.

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.

`["2@abc123", "children", 0, "position"]`

AutomergeUrl = RepoAutomergeUrl & `automerge:${string}`

Defined in: packages/types/dist/hashroute.d.ts:3

Automerge document URL (e.g. automerge:111111111111111111).


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

const SCHEMA_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