Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source pure

Package lplist provides a layered proxy implementation for lists that allows transparent migration of data between di...

Readme View source

gno.land/p/moul/ulist/lplist/v0

LayeredProxyList — a layered proxy over ulist enabling lazy, append-only schema migration: it wraps a source list with a target list and transforms source entries only when accessed (source stays immutable), and layers can be chained for multi-step migrations. Nested under ulist in the monorepo; it was missed on the original ulist import.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

Dependency graph:

gno.land/p/moul/ulist/lplist/v0 dependency graph

⚠️ Disclaimer: provided as-is, without warranty; not security-audited. Full disclaimer: DISCLAIMER.

Overview

Package lplist provides a layered proxy implementation for lists that allows transparent migration of data between different schema versions.

LayeredProxyList wraps an existing list (source) with a new list (target) and optionally applies migrations to source data when it's accessed. This enables schema evolution without requiring upfront migration of all data, making it ideal for large datasets or when preserving original data is important.

Key features: - Lazy migration: Data is only transformed when accessed, not stored in migrated form - Append-only source: Source data is treated as immutable to preserve original data - Chaining: Multiple LayeredProxyLists can be stacked for multi-step migrations

Example usage:

Example
 1// Define data types for different schema versions
 2type UserV1 struct {
 3    Name string
 4    Age int
 5}
 6
 7type UserV2 struct {
 8    FullName string
 9    Age int
10    Active bool
11}
12
13// Create source list with old schema
14sourceList := ulist.New()
15sourceList.Append(
16    UserV1{Name: "Alice", Age: 30},
17    UserV1{Name: "Bob", Age: 25},
18)
19
20// Define migration function from V1 to V2
21migrateUserV1ToV2 := func(v any) any {
22    user := v.(UserV1)
23    return UserV2{
24        FullName: user.Name,  // Name field renamed to FullName
25        Age: user.Age,
26        Active: true,         // New field with default value
27    }
28}
29
30// Create layered proxy with migration
31proxy := NewLayeredProxyList(sourceList, migrateUserV1ToV2)
32
33// Add new data directly in V2 format
34proxy.Append(UserV2{FullName: "Charlie", Age: 40, Active: false})
35
36// All access through proxy returns data in V2 format
37for i := 0; i < proxy.Size(); i++ {
38    user := proxy.Get(i).(UserV2)
39    fmt.Printf("User: %s, Age: %d, Active: %t\n", user.FullName, user.Age, user.Active)
40}

Functions 1

func NewLayeredProxyList

1func NewLayeredProxyList(source ulist.IList, migrator MigratorFn) *LayeredProxyList
source

NewLayeredProxyList creates a new LayeredProxyList instance that wraps an existing List

Types 2

type LayeredProxyList

struct
1type LayeredProxyList struct {
2	source       ulist.IList
3	target       *ulist.List
4	migrator     MigratorFn
5	sourceHeight int // Store initial source size to optimize lookups
6}
source

LayeredProxyList represents a wrapper around an existing List that handles migration

Methods on LayeredProxyList

func Append

method on LayeredProxyList
1func (l *LayeredProxyList) Append(values ...any)
source

Append adds one or more values to the target list

func Delete

method on LayeredProxyList
1func (l *LayeredProxyList) Delete(indices ...int) error
source

Delete marks elements as deleted in the appropriate list

func Get

method on LayeredProxyList
1func (l *LayeredProxyList) Get(index int) any
source

Get retrieves the value at the specified index Uses sourceHeight to efficiently route requests

func GetByOffset

method on LayeredProxyList
1func (l *LayeredProxyList) GetByOffset(offset int, count int) []ulist.Entry
source

GetByOffset returns elements starting from offset with count determining direction

func GetRange

method on LayeredProxyList
1func (l *LayeredProxyList) GetRange(start, end int) []ulist.Entry
source

GetRange returns elements between start and end indices

func GetRangeByOffset

method on LayeredProxyList
1func (l *LayeredProxyList) GetRangeByOffset(offset int, count int) []ulist.Entry
source

GetRangeByOffset returns elements starting from offset

func Iterator

method on LayeredProxyList
1func (l *LayeredProxyList) Iterator(start, end int, cb ulist.IterCbFn) bool
source

Iterator performs iteration between start and end indices

func IteratorByOffset

method on LayeredProxyList
1func (l *LayeredProxyList) IteratorByOffset(offset int, count int, cb ulist.IterCbFn) bool
source

IteratorByOffset performs iteration starting from offset

func MustDelete

method on LayeredProxyList
1func (l *LayeredProxyList) MustDelete(indices ...int)
source

MustDelete deletes elements, panicking on error

func MustGet

method on LayeredProxyList
1func (l *LayeredProxyList) MustGet(index int) any
source

MustGet retrieves a value, panicking if not found

func MustSet

method on LayeredProxyList
1func (l *LayeredProxyList) MustSet(index int, value any)
source

MustSet updates the value at the specified index, panicking on error

func Set

method on LayeredProxyList
1func (l *LayeredProxyList) Set(index int, value any) error
source

Set updates the value at the specified index

func Size

method on LayeredProxyList
1func (l *LayeredProxyList) Size() int
source

Size returns the total number of active elements

func TotalSize

method on LayeredProxyList
1func (l *LayeredProxyList) TotalSize() int
source

TotalSize returns the total number of elements in the list

type MigratorFn

func
1type MigratorFn func(any) any
source

MigratorFn is a function type that lazily converts values from source to target

Imports 2

Source Files 3