Automatically inferred from the schema, or explicitly specified
The root schema type (must be a named type: object, union, or enum)
A DeltaPackApi for encoding/decoding objects of the schema type
// Define a schema using type constructors
const Player = ObjectType("Player", {
name: StringType(),
score: IntType({ min: 0 }),
position: ObjectType("Position", {
x: FloatType({ precision: 0.01 }),
y: FloatType({ precision: 0.01 }),
}),
});
// Load the schema to get the API (type is inferred)
const api = load(Player);
// Use the API
const player = { name: "Alice", score: 100, position: { x: 1.5, y: 2.5 } };
const encoded = api.encode(player);
const decoded = api.decode(encoded);
// Delta compression for state sync
const updated = { ...player, score: 150 };
const diff = api.encodeDiff(player, updated);
const applied = api.decodeDiff(player, diff);
Create a DeltaPackApi with an explicit type parameter. Useful when loading schemas parsed from YAML where types can't be inferred.
Create a DeltaPackApi from a schema definition.
This is the main entry point for using Delta-Pack in interpreter mode. Pass a schema type (created with ObjectType, UnionType, or EnumType) to get back an API for serializing objects of that type.