Delta-Pack - v0.2.9
    Preparing search index...

    Function load

    • 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.

      Type Parameters

      • T extends NamedType

        Automatically inferred from the schema, or explicitly specified

      Parameters

      • rootType: T

        The root schema type (must be a named type: object, union, or enum)

      Returns DeltaPackApi<Infer<T>>

      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);
      // Load from parsed YAML schema with explicit type
      const schema = parseSchemaYml(yamlString);
      const api = load<MyType>(schema);
    • Create a DeltaPackApi with an explicit type parameter. Useful when loading schemas parsed from YAML where types can't be inferred.

      Type Parameters

      • T

      Parameters

      Returns DeltaPackApi<T>