types.gno
1.92 Kb ยท 42 lines
1package version_manager
2
3import "gno.land/p/nt/avl/rotree"
4
5// VersionManager defines the interface for managing multiple versioned implementations of a domain.
6// It enables the Strategy Pattern at the package level, allowing runtime switching between
7// different versions (v1, v2, v3, etc.) without requiring data migration.
8//
9// Design Goals:
10// - Enable zero-downtime upgrades through hot-swapping implementations
11// - Maintain a single source of truth for storage across all versions
12// - Enforce security through domain-scoped registration
13// - Support backward compatibility by keeping old versions available in read-only mode
14//
15// Implementation Note:
16// The actual implementations of each version must satisfy a common domain interface
17// defined by the specific domain (e.g., ProtocolFee interface for protocol_fee domain).
18type VersionManager interface {
19 // RegisterInitializer registers a version's implementation.
20 // Must be called by each version package during initialization.
21 // First registration becomes the active implementation with write access.
22 // Subsequent registrations are granted read-only access.
23 RegisterInitializer(initializer func(store any) any) error
24
25 // ChangeImplementation switches the active version at runtime.
26 // The new active version gets write access, while others remain read-only.
27 // This enables hot-swapping without downtime or data migration.
28 ChangeImplementation(packagePath string) error
29
30 // GetDomainPath returns the base domain path (e.g., "gno.land/r/gnoswap/protocol_fee")
31 GetDomainPath() string
32
33 // GetInitializers returns all registered version initializers
34 GetInitializers() *rotree.ReadOnlyTree
35
36 // GetCurrentPackagePath returns the package path of the active implementation
37 GetCurrentPackagePath() string
38
39 // GetCurrentImplementation returns the active version instance
40 // The caller should type-assert this to the domain-specific interface
41 GetCurrentImplementation() any
42}