StorageObject

Reference for the StorageObject module: a content-addressed, immutable node store. It saves a whole object as a set of hash-addressed, deduplicated, structurally shared blocks, plus a header row that records a saved object's id, module, type and root hash. The store guarantees the integrity of the hash tree; schema and type checking live in the layer above.

This page is a pure reference. For how the framework fits together, see the Guide.

Classes

StorageObjectBlockDatabase

The content-addressed node store (the storage_object_block table). Integrity only: it knows nothing about schemas or application types; it stores and returns a tree of hash-addressed nodes and guarantees the tree's hash integrity. The object header that names a root is the separate StorageObjectDatabase.

Functions

GetRaw

StorageObjectBlockDatabase::GetRaw(string $hash): object

The raw stored row (id, hash, type, data) for a hash, for admin or debug.

NameTypeDescription
$hashstringThe content hash of the block.

Returns object The raw stored row.

Load

StorageObjectBlockDatabase::Load(string $rootHash): array

The whole object rooted at the given hash, as blocks, by following the hashes from the root through the store. Throws when a referenced block is missing (store corruption).

NameTypeDescription
$rootHashstringThe root block hash to load from.

Returns array A list of StorageObjectBlockData.

Save

StorageObjectBlockDatabase::Save(array $blocks, string $rootHash): void

Save a whole object; the blocks must contain every block reachable from the root hash. Walks the tree in memory to find the blocks actually needed and checks that every reference is present and every block's hash matches its content, then bulk inserts them. Throws StorageObjectCorruptException on any missing block or bad hash.

NameTypeDescription
$blocksarrayThe object's blocks, as StorageObjectBlockData.
$rootHashstringThe root block hash of the object.

Returns void

StorageObjectChunk

Content-defined chunking for long strings and long sequences. A value too big for one node is split into leaves so that a small edit re-mints only the leaf it lands in, and identical runs dedup by hash. It decides only where the cuts fall; StorageObjectWrite turns the cuts into the actual node tree.

ChunkText

StorageObjectChunk::ChunkText(string $text): array

The byte ranges of the text as an ordered list of chunk strings; concatenating them reproduces the text exactly. A string that produces no cut comes back as a single chunk. Cuts are snapped forward to the next UTF-8 code-point boundary so every chunk is valid text.

NameTypeDescription
$textstringThe string to chunk.

Returns array The ordered chunk strings.

GroupHashes

StorageObjectChunk::GroupHashes(array $hashes): array

Group an ordered list of child hashes into runs by the same content-defined rule. A short list comes back as a single group; a longer one splits into runs that become the next spine level. Always returns at least one group.

NameTypeDescription
$hashesarrayThe ordered child hashes to group.

Returns array A list of hash groups.

StorageObjectDatabase

The object header store (the storage_object table). A header is one saved object instance: its owning module and type name, the root hash of its content, and when it was added. Objects are an append log, so Create always inserts a new row and many rows may share a root hash (identical content dedupes at the block level, not here).

Create

StorageObjectDatabase::Create(string $module, string $typeName, string $rootHash): int

Insert a new object header pointing at the root hash and return its new id. The blocks under the root hash must already be saved. The module and type name are short identifiers for navigation and future per-type configuration.

NameTypeDescription
$modulestringThe owning module identifier.
$typeNamestringThe type name identifier.
$rootHashstringThe root block hash of the saved content.

Returns int The new object id.

Get

StorageObjectDatabase::Get(int $id): StorageObjectData

The object header for an id; throws if none exists.

NameTypeDescription
$idintThe object id to read.

Returns StorageObjectData The object header.

GetByIdOptional

StorageObjectDatabase::GetByIdOptional(int $id): ?StorageObjectData

The object header for an id, or null if none exists.

NameTypeDescription
$idintThe object id to read.

Returns ?StorageObjectData The object header, or null.

StorageObjectIngest

The safety gate for untrusted uploaded blocks (the editor save path). It runs before the decode walk so a malformed or hostile upload is rejected up front. It does the set-level checks that need no root and no walk: resource caps on total node count, per-node data size and per-node fanout, and a rehash where every block's claimed hash must equal the hash of its content.

Constants

ConstantValueDescription
StorageObjectIngest::MAX_NODES50000The maximum number of nodes in an uploaded set.
StorageObjectIngest::MAX_NODE_BYTES2048The maximum serialised data size of one node.
StorageObjectIngest::MAX_FANOUT32The maximum number of references from one node.
Functions

Verify

StorageObjectIngest::Verify(array $blocks): array

Verify an untrusted uploaded block set, returning it unchanged if it passes. Throws StorageObjectCorruptException on the first violation.

NameTypeDescription
$blocksarrayThe uploaded blocks, as StorageObjectBlockData.

Returns array The blocks, unchanged.

StorageObjectNode

The storage-representation operations for a node: how a node is written to a row, read back, addressed, and how its references are enumerated. It knows nothing about application types; it works only with the generic node kinds. The hash is the 28-char base64 of a 160-bit truncated SHA-256 over a canonical preimage.

Deserialize

StorageObjectNode::Deserialize(int $type, string $data): StorageObjectNodeUnion

Rebuild a node from its stored type and data. Throws StorageObjectCorruptException on an unknown node type.

NameTypeDescription
$typeintThe stored node kind (a StorageObjectNodeType constant).
$datastringThe stored data column.

Returns StorageObjectNodeUnion The rebuilt node.

Hash

StorageObjectNode::Hash(StorageObjectNodeUnion $node): string

The 28-char content hash of a node, the base64 of a 160-bit truncated SHA-256 over the node's canonical preimage.

NameTypeDescription
$nodeStorageObjectNodeUnionThe node to hash.

Returns string The content hash.

Refs

StorageObjectNode::Refs(StorageObjectNodeUnion $node): array

The child hashes a node references: struct field hashes, array item hashes, or inner child hashes. Value and packed-floats leaves reference nothing.

NameTypeDescription
$nodeStorageObjectNodeUnionThe node to read references from.

Returns array The referenced child hashes.

Serialize

StorageObjectNode::Serialize(StorageObjectNodeUnion $node): array

A node as a type and data pair for storage.

NameTypeDescription
$nodeStorageObjectNodeUnionThe node to serialise.

Returns array A two-element array of node type and data.

StorageObjectNodeType

The stored node kind, one tiny integer per row. A node is a struct, an array (a sequence root), an inner spine node, a packed-floats leaf, or a basic value (integer, float, boolean, string). The value subtypes are distinct kinds so a row is fully self-describing and the hash preimage is unambiguous.

Constants

ConstantValueDescription
StorageObjectNodeType::STRUCT1A struct node (named fields to hashes).
StorageObjectNodeType::ARRAY2An array node (a sequence root).
StorageObjectNodeType::INTEGER3An integer value.
StorageObjectNodeType::FLOAT4A float value.
StorageObjectNodeType::BOOLEAN5A boolean value.
StorageObjectNodeType::STRING6A string value.
StorageObjectNodeType::INNER7An inner spine node.
StorageObjectNodeType::FLOAT28A packed-floats leaf of 2 floats.
StorageObjectNodeType::FLOAT39A packed-floats leaf of 3 floats.
StorageObjectNodeType::FLOAT410A packed-floats leaf of 4 floats.

StorageObjectRead

The decode half of the block codec: read typed values out of a materialised block set (hash to node) by hash. Build the map once with Index. Every getter asserts the node's kind and throws StorageObjectCorruptException on a missing block or a kind mismatch. Sequences are content-defined chunked; Text and Items flatten the spine transparently.

Bool

StorageObjectRead::Bool(array $map, string $hash): bool

The boolean value at the hash.

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the value node.

Returns bool The boolean value.

ColourOpaque

StorageObjectRead::ColourOpaque(array $map, string $hash): ColourOpaqueData

A ColourOpaqueData from a FLOAT3 leaf (red, green, blue).

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the FLOAT3 leaf.

Returns ColourOpaqueData The opaque colour.

ColourTransparent

StorageObjectRead::ColourTransparent(array $map, string $hash): ColourTransparentData

A ColourTransparentData from a FLOAT4 leaf (red, green, blue, alpha).

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the FLOAT4 leaf.

Returns ColourTransparentData The transparent colour.

Field

StorageObjectRead::Field(array $fields, string $name): string

A required field hash from a struct field map (as returned by Struct), or a corrupt exception if absent.

NameTypeDescription
$fieldsarrayThe struct field map of name to hash.
$namestringThe field name to read.

Returns string The field's value hash.

Float

StorageObjectRead::Float(array $map, string $hash): float

The float value at the hash.

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the value node.

Returns float The float value.

Index

StorageObjectRead::Index(array $blocks): array

Index a block list by hash for random access.

NameTypeDescription
$blocksarrayThe blocks, as StorageObjectBlockData.

Returns array The map of hash to node.

Int

StorageObjectRead::Int(array $map, string $hash): int

The integer value at the hash.

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the value node.

Returns int The integer value.

Items

StorageObjectRead::Items(array $map, string $hash): array

The element hashes of a sequence, in order, flattening the spine. The node at the hash must be an ARRAY root; its INNER spine is descended and the leaf element hashes returned. A nested array element is returned as its own hash for the caller to decode.

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the ARRAY root.

Returns array The ordered element hashes.

Quaternion

StorageObjectRead::Quaternion(array $map, string $hash): MathsQuaternionData

A MathsQuaternionData from a FLOAT4 leaf (x, y, z, w).

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the FLOAT4 leaf.

Returns MathsQuaternionData The quaternion.

Struct

StorageObjectRead::Struct(array $map, string $hash): array

The fields of a struct node as name to child hash.

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the struct node.

Returns array The map of field name to child hash.

Text

StorageObjectRead::Text(array $map, string $hash): string

The string at the hash, reassembling a chunked string. A single bare string value is returned directly; an ARRAY root is flattened and its string-chunk leaves are concatenated byte-exact.

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the string value or ARRAY root.

Returns string The reassembled string.

Vector2

StorageObjectRead::Vector2(array $map, string $hash): MathsVector2Data

A MathsVector2Data from a FLOAT2 leaf.

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the FLOAT2 leaf.

Returns MathsVector2Data The vector.

Vector3

StorageObjectRead::Vector3(array $map, string $hash): MathsVector3Data

A MathsVector3Data from a FLOAT3 leaf.

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the FLOAT3 leaf.

Returns MathsVector3Data The vector.

Vector4

StorageObjectRead::Vector4(array $map, string $hash): MathsVector4Data

A MathsVector4Data from a FLOAT4 leaf.

NameTypeDescription
$maparrayThe block set indexed as hash to node.
$hashstringThe hash of the FLOAT4 leaf.

Returns MathsVector4Data The vector.

StorageObjectWire

Convert between the on-the-wire block form and the in-memory StorageObjectBlockData. A wire block is a plain object of hash, type and data, the same three columns the store persists, so JSON on the wire and rows at rest share one representation. An uploaded hash is carried but not trusted; the store rehashes every block on Save.

BlocksToWire

StorageObjectWire::BlocksToWire(array $blocks): array

Serialise blocks to the wire form of hash, type and data for download.

NameTypeDescription
$blocksarrayThe blocks, as StorageObjectBlockData.

Returns array A list of wire objects.

ParseBlocks

StorageObjectWire::ParseBlocks(array $rawBlocks): array

Rebuild uploaded wire blocks into StorageObjectBlockData. Each raw item has hash, type and data; the node is reconstructed from type and data, and the hash is preserved as given (the Save walk verifies it).

NameTypeDescription
$rawBlocksarrayThe uploaded wire objects.

Returns array A list of StorageObjectBlockData.

StorageObjectWrite

The encode half of the block codec: build a StorageObjectTreeData (a root hash plus the blocks reachable from it) for a typed value. Every hash is minted here from the node's canonical form, so the server is always the authority on hashes. Long strings and sequences are content-defined chunked; vectors, quaternions and colours are packed into a single FLOAT2/3/4 leaf.

ArrayNode

StorageObjectWrite::ArrayNode(array $children): StorageObjectTreeData

A sequence from ordered children (each a child StorageObjectTreeData). Content-defined chunked into an ARRAY root over an INNER spine when large; a short list stays one flat ARRAY node.

NameTypeDescription
$childrenarrayThe ordered child trees, as StorageObjectTreeData.

Returns StorageObjectTreeData The sequence tree.

Bool

StorageObjectWrite::Bool(bool $flag): StorageObjectTreeData

A boolean value node.

NameTypeDescription
$flagboolThe boolean value.

Returns StorageObjectTreeData The value tree.

ColourOpaque

StorageObjectWrite::ColourOpaque(ColourOpaqueData $colour): StorageObjectTreeData

An opaque colour as a FLOAT3 leaf (red, green, blue).

NameTypeDescription
$colourColourOpaqueDataThe opaque colour.

Returns StorageObjectTreeData The leaf tree.

ColourTransparent

StorageObjectWrite::ColourTransparent(ColourTransparentData $colour): StorageObjectTreeData

A transparent colour as a FLOAT4 leaf (red, green, blue, alpha).

NameTypeDescription
$colourColourTransparentDataThe transparent colour.

Returns StorageObjectTreeData The leaf tree.

Float

StorageObjectWrite::Float(float $number): StorageObjectTreeData

A float value node.

NameTypeDescription
$numberfloatThe float value.

Returns StorageObjectTreeData The value tree.

Int

StorageObjectWrite::Int(int $number): StorageObjectTreeData

An integer value node.

NameTypeDescription
$numberintThe integer value.

Returns StorageObjectTreeData The value tree.

Quaternion

StorageObjectWrite::Quaternion(MathsQuaternionData $quaternion): StorageObjectTreeData

A quaternion as a FLOAT4 leaf (x, y, z, w).

NameTypeDescription
$quaternionMathsQuaternionDataThe quaternion.

Returns StorageObjectTreeData The leaf tree.

Struct

StorageObjectWrite::Struct(array $childrenByName): StorageObjectTreeData

A struct node from named children (name to child StorageObjectTreeData). A null child is skipped entirely, which is how an unset optional field is encoded. The hash is order-independent (the canonical form sorts keys).

NameTypeDescription
$childrenByNamearrayThe map of field name to child tree or null.

Returns StorageObjectTreeData The struct tree.

Text

StorageObjectWrite::Text(string $text): StorageObjectTreeData

A string value. Content-defined chunked: a string that fits in one chunk becomes a single bare string value node; a long string becomes an ARRAY root over an INNER spine of string-chunk leaves.

NameTypeDescription
$textstringThe string to encode.

Returns StorageObjectTreeData The string tree.

Vector2

StorageObjectWrite::Vector2(MathsVector2Data $vector): StorageObjectTreeData

A vec2 as a FLOAT2 leaf (two packed floats).

NameTypeDescription
$vectorMathsVector2DataThe vector.

Returns StorageObjectTreeData The leaf tree.

Vector3

StorageObjectWrite::Vector3(MathsVector3Data $vector): StorageObjectTreeData

A vec3 as a FLOAT3 leaf (three packed floats).

NameTypeDescription
$vectorMathsVector3DataThe vector.

Returns StorageObjectTreeData The leaf tree.

Vector4

StorageObjectWrite::Vector4(MathsVector4Data $vector): StorageObjectTreeData

A vec4 as a FLOAT4 leaf (four packed floats).

NameTypeDescription
$vectorMathsVector4DataThe vector.

Returns StorageObjectTreeData The leaf tree.

StorageObjectArrayData

An array node: an ordered list of the content hashes of its element nodes. Also used to spine a long string or a large array into a tree. Fields and constructor only.

Properties

PropertyTypeDescription
$array->hashesstring[]The ordered element hashes (readonly).

__construct

new StorageObjectArrayData(array $hashes = [])

Create an array node from an ordered list of content hashes.

NameTypeDescription
$hashesstring[]The ordered element hashes.

Returns StorageObjectArrayData

StorageObjectBlockData

One block of a stored object: its content hash and the node it holds. An object is transferred as a set of these blocks plus a root hash. Fields and constructor only.

Properties

PropertyTypeDescription
$block->hashstringThe content hash of the node (readonly).
$block->nodeStorageObjectNodeUnionThe node the block holds (readonly).

__construct

new StorageObjectBlockData(string $hash, StorageObjectNodeUnion $node)

Create a block from a content hash and the node it holds.

NameTypeDescription
$hashstringThe content hash of the node.
$nodeStorageObjectNodeUnionThe node the block holds.

Returns StorageObjectBlockData

StorageObjectData

A persisted storage object: one row of the storage_object table. It is the header record for a saved object. The content itself lives as deduplicated blocks, reached from the root hash. Fields and constructor only.

Properties

PropertyTypeDescription
$object->idintThe numeric object id (readonly).
$object->modulestringThe owning module name (readonly).
$object->typeNamestringThe type name (readonly).
$object->rootHashstringThe root block hash of the content (readonly).
$object->addedTimestampintThe Unix timestamp when the row was added (readonly).
$object->addedDatestringThe added datetime as a string (readonly).

__construct

new StorageObjectData(int $id, string $module, string $typeName, string $rootHash, int $addedTimestamp, string $addedDate)

Create a persisted object header from its stored fields.

NameTypeDescription
$idintThe numeric object id.
$modulestringThe owning module name.
$typeNamestringThe type name.
$rootHashstringThe root block hash of the content.
$addedTimestampintThe Unix timestamp when the row was added.
$addedDatestringThe added datetime as a string.

Returns StorageObjectData

StorageObjectFieldData

One field of a struct node: a field name and the content hash of the field's value node. A struct node is an ordered list of these. Fields and constructor only.

Properties

PropertyTypeDescription
$field->namestringThe field name (readonly).
$field->hashstringThe content hash of the field's value node (readonly).

__construct

new StorageObjectFieldData(string $name, string $hash)

Create a struct field from a name and a value hash.

NameTypeDescription
$namestringThe field name.
$hashstringThe content hash of the field's value node.

Returns StorageObjectFieldData

StorageObjectFloatsData

A packed-floats leaf: 2, 3 or 4 floats stored inline in one ref-free node. This is the store form of a fixed small float composite (a vector, a quaternion, or a colour). Fields and constructor only.

Properties

PropertyTypeDescription
$floats->componentsfloat[]The 2, 3 or 4 floats (readonly).

__construct

new StorageObjectFloatsData(array $components = [])

Create a packed-floats leaf from 2, 3 or 4 floats.

NameTypeDescription
$componentsfloat[]The 2, 3 or 4 floats.

Returns StorageObjectFloatsData

StorageObjectInnerData

An inner (spine) node: an ordered list of the content hashes of its children, where each child is either another inner node or a leaf element of the sequence. Inner nodes exist only inside a sequence's chunk tree. Fields and constructor only.

Properties

PropertyTypeDescription
$inner->hashesstring[]The ordered child hashes (readonly).

__construct

new StorageObjectInnerData(array $hashes = [])

Create an inner spine node from an ordered list of child hashes.

NameTypeDescription
$hashesstring[]The ordered child hashes.

Returns StorageObjectInnerData

StorageObjectNodeUnion

A stored node: exactly one of a struct, an array (a sequence root), an inner spine node, a packed-floats leaf, or a basic value. Construct with the static factories; read the variant by testing the fields directly (exactly one is non-null).

Properties

PropertyTypeDescription
$node->struct?StorageObjectStructDataThe struct variant, or null (readonly).
$node->array?StorageObjectArrayDataThe array variant, or null (readonly).
$node->inner?StorageObjectInnerDataThe inner spine variant, or null (readonly).
$node->floats?StorageObjectFloatsDataThe packed-floats variant, or null (readonly).
$node->value?StorageObjectValueUnionThe basic value variant, or null (readonly).

ArrayNode

StorageObjectNodeUnion::ArrayNode(StorageObjectArrayData $array): self

A node union holding an array node.

NameTypeDescription
$arrayStorageObjectArrayDataThe array node.

Returns StorageObjectNodeUnion The node union.

Floats

StorageObjectNodeUnion::Floats(StorageObjectFloatsData $floats): self

A node union holding a packed-floats leaf.

NameTypeDescription
$floatsStorageObjectFloatsDataThe packed-floats leaf.

Returns StorageObjectNodeUnion The node union.

Inner

StorageObjectNodeUnion::Inner(StorageObjectInnerData $inner): self

A node union holding an inner spine node.

NameTypeDescription
$innerStorageObjectInnerDataThe inner spine node.

Returns StorageObjectNodeUnion The node union.

Struct

StorageObjectNodeUnion::Struct(StorageObjectStructData $struct): self

A node union holding a struct node.

NameTypeDescription
$structStorageObjectStructDataThe struct node.

Returns StorageObjectNodeUnion The node union.

Value

StorageObjectNodeUnion::Value(StorageObjectValueUnion $value): self

A node union holding a basic value.

NameTypeDescription
$valueStorageObjectValueUnionThe basic value.

Returns StorageObjectNodeUnion The node union.

StorageObjectStructData

A struct node: an ordered list of named fields, each a name and the hash of the field's value node. This is the object spine; every field points at another node by hash. Fields and constructor only.

Properties

PropertyTypeDescription
$struct->fieldsStorageObjectFieldData[]The ordered named fields (readonly).

__construct

new StorageObjectStructData(array $fields = [])

Create a struct node from an ordered list of named fields.

NameTypeDescription
$fieldsStorageObjectFieldData[]The ordered named fields.

Returns StorageObjectStructData

StorageObjectTreeData

A whole object encoded as content-addressed blocks: the root node's hash plus the blocks reachable from it. This is the ToBlocks codec output and the shape the backend sends to reconstruct an object. Fields and constructor only.

Properties

PropertyTypeDescription
$tree->rootHashstringThe root node's content hash (readonly).
$tree->blocksStorageObjectBlockData[]The blocks reachable from the root (readonly).

__construct

new StorageObjectTreeData(string $rootHash, array $blocks = [])

Create a tree from a root hash and its reachable blocks.

NameTypeDescription
$rootHashstringThe root node's content hash.
$blocksStorageObjectBlockData[]The blocks reachable from the root.

Returns StorageObjectTreeData

StorageObjectValueUnion

A basic scalar value held by a value node: exactly one of integer, float, boolean, or string. Construct with the static factories; read the variant by testing the fields directly (exactly one is non-null).

Properties

PropertyTypeDescription
$value->integer?intThe integer variant, or null (readonly).
$value->float?floatThe float variant, or null (readonly).
$value->boolean?boolThe boolean variant, or null (readonly).
$value->string?stringThe string variant, or null (readonly).

Boolean

StorageObjectValueUnion::Boolean(bool $value): self

A value union holding a boolean.

NameTypeDescription
$valueboolThe boolean value.

Returns StorageObjectValueUnion The value union.

Float

StorageObjectValueUnion::Float(float $value): self

A value union holding a float.

NameTypeDescription
$valuefloatThe float value.

Returns StorageObjectValueUnion The value union.

Integer

StorageObjectValueUnion::Integer(int $value): self

A value union holding an integer.

NameTypeDescription
$valueintThe integer value.

Returns StorageObjectValueUnion The value union.

StringValue

StorageObjectValueUnion::StringValue(string $value): self

A value union holding a string.

NameTypeDescription
$valuestringThe string value.

Returns StorageObjectValueUnion The value union.

StorageObjectCorruptException

Thrown when the tree of hashes fails an integrity check: a referenced block is missing (an incomplete object), a block's stored hash does not match the canonical hash of its content, or a node cannot be decoded. This is corruption of the hash tree, not a type error; schema and type validation happen in the layer above. Extends Exception and adds no members.