types

package
v0.0.0-...-861cdb6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllCruds = []struct {
	Value  crud.Operation `json:"value"`
	TSName string         `json:"tsname"`
}{
	{crud.Create, "CREATE"},
	{crud.Update, "UPDATE"},
	{crud.Delete, "DELETE"},
	{crud.Undelete, "UNDELETE"},
	{crud.Remove, "REMOVE"},
	{crud.Autoname, "AUTONAME"},
}
View Source
var (
	AllDataFacets = []struct {
		Value  DataFacet `json:"value"`
		TSName string    `json:"tsname"`
	}{}
)
View Source
var AllPeriods = []struct {
	Value  Period `json:"value"`
	TSName string `json:"tsname"`
}{
	{PeriodBlockly, "BLOCKLY"},
	{PeriodHourly, "HOURLY"},
	{PeriodDaily, "DAILY"},
	{PeriodWeekly, "WEEKLY"},
	{PeriodMonthly, "MONTHLY"},
	{PeriodQuarterly, "QUARTERLY"},
	{PeriodAnnual, "ANNUAL"},
}
View Source
var AllStates = []struct {
	Value  StoreState `json:"value"`
	TSName string     `json:"tsname"`
}{
	{StateStale, "STALE"},
	{StateFetching, "FETCHING"},
	{StateLoaded, "LOADED"},
}

Functions

func DeriveFacets

func DeriveFacets(vc *ViewConfig)

DeriveFacets populates Columns and DetailPanels from Fields when present. It preserves existing Columns/DetailPanels if Fields is empty.

func ExportData

func ExportData[T any](data []T, payload *Payload, typeName string) (string, error)

ExportData is the unified export function that handles file creation with proper extension and format

func IsCacheError

func IsCacheError(err error) bool

IsCacheError checks if an error is a cache-related error

func IsSDKError

func IsSDKError(err error) bool

IsSDKError checks if an error is an SDK operation error

func IsValidationError

func IsValidationError(err error) bool

IsValidationError checks if an error is a validation error

func NormalizeFields

func NormalizeFields(fields *[]FieldConfig)

NormalizeFields normalizes field configurations in place.

func RegisterDataFacet

func RegisterDataFacet(df DataFacet)

func SetMenuOrder

func SetMenuOrder(vc *ViewConfig)

SetMenuOrder applies menu ordering and facet configurations from embedded or file-based config to ViewConfig. When TB_ALLVIEWS environment variable is set, ordering and disabled state configurations are ignored.

func SortFields

func SortFields(vc *ViewConfig)

SortFields sorts columns and detail fields by their explicit order values. It does not assign defaults; ordering must be provided in config.

Types

type ActionConfig

type ActionConfig struct {
	Name         string `json:"name"`
	Label        string `json:"label"`
	Icon         string `json:"icon"`
	Confirmation bool   `json:"confirmation"`
}

ActionConfig represents an available action (delete, remove, etc.)

type Bucket

type Bucket struct {
	BucketKey  string  `json:"bucketIndex"`
	StartBlock uint64  `json:"startBlock"`
	EndBlock   uint64  `json:"endBlock"`
	Total      float64 `json:"total"`
	ColorValue float64 `json:"colorValue"`
}

func NewBucket

func NewBucket(bucketKey string, startBlock, endBlock uint64) Bucket

NewBucket creates a new Bucket with the specified parameters

type BucketInterface

type BucketInterface interface {
	GetBuckets() *Buckets
	ClearBuckets()
	SetBuckets(buckets *Buckets)
	UpdateBuckets(updateFunc func(*Buckets))
}

BucketInterface defines bucket operations that facets must implement

type BucketStats

type BucketStats struct {
	Total   float64 `json:"total"`
	Average float64 `json:"average"`
	Min     float64 `json:"min"`
	Max     float64 `json:"max"`
	Count   int     `json:"count"`
}

func NewBucketStats

func NewBucketStats() BucketStats

NewBucketStats creates a new BucketStats with zero values

type Buckets

type Buckets struct {
	// Flexible series structure using named metrics
	Series     map[string][]Bucket        `json:"series"`
	AssetNames map[string]*coreTypes.Name `json:"assetNames,omitempty"` // Maps series prefix to asset name
	GridInfo   GridInfo                   `json:"gridInfo"`
}

func NewBuckets

func NewBuckets() *Buckets

NewBuckets creates a new Buckets struct with proper initialization

func NewBucketsWithGridInfo

func NewBucketsWithGridInfo(gi *GridInfo) *Buckets

NewBuckets creates a new Buckets struct with proper initialization

func (*Buckets) EnsureSeriesExists

func (b *Buckets) EnsureSeriesExists(name string)

EnsureSeriesExists ensures a series exists, creating it if necessary

func (*Buckets) GetSeries

func (b *Buckets) GetSeries(name string) []Bucket

GetSeries returns a series by name, creating it if it doesn't exist

func (*Buckets) SetAssetName

func (b *Buckets) SetAssetName(assetIdentifier string, assetName *coreTypes.Name)

SetAssetName stores the asset name for a series prefix (e.g., "0x1234567890ab_ETH")

func (*Buckets) SetSeries

func (b *Buckets) SetSeries(name string, buckets []Bucket)

SetSeries sets a series by name

func (*Buckets) UpdateSeries

func (b *Buckets) UpdateSeries(name string, updateFunc func([]Bucket) []Bucket)

UpdateSeries safely updates a series by applying a function to it

type Collection

type Collection interface {
	GetPage(payload *Payload, first, pageSize int, sort sdk.SortSpec, filter string) (Page, error)
	FetchByFacet(payload *Payload)
	Reset(payload *Payload)
	NeedsUpdate(payload *Payload) bool
	GetSummary(payload *Payload) Summary
	ExportData(payload *Payload) (string, error)
	ChangeVisibility(payload *Payload) error
	GetConfig() (*ViewConfig, error)
	SummaryAccumulator
}

type CollectionError

type CollectionError struct {
	Type       ErrorType
	Operation  string
	Collection string
	DataFacet  DataFacet
	Underlying error
	Message    string
}

CollectionError provides structured error information with context

func NewCacheError

func NewCacheError(collection string, dataFacet DataFacet, operation string, err error) *CollectionError

NewCacheError creates an error for cache-related failures

func NewSDKError

func NewSDKError(collection string, dataFacet DataFacet, operation string, err error) *CollectionError

NewSDKError creates an error for SDK operation failures

func NewStoreError

func NewStoreError(collection string, dataFacet DataFacet, operation string, err error) *CollectionError

NewStoreError creates an error for store operation failures

func NewValidationError

func NewValidationError(collection string, dataFacet DataFacet, operation string, err error) *CollectionError

NewValidationError creates an error for invalid parameters or configuration

func (*CollectionError) Error

func (e *CollectionError) Error() string

func (*CollectionError) Unwrap

func (e *CollectionError) Unwrap() error

type ColumnConfig

type ColumnConfig struct {
	Key      string `json:"key"`
	Header   string `json:"header"`
	Width    int    `json:"width"`
	Sortable bool   `json:"sortable"`
	Type     string `json:"type"`
	Order    int    `json:"order"`
}

ColumnConfig represents a table column configuration

type Crud

type Crud string

type DataFacet

type DataFacet string

type DataLoadedPayload

type DataLoadedPayload struct {
	Payload
	CurrentCount  int        `json:"currentCount"`
	ExpectedTotal int        `json:"expectedTotal"`
	State         StoreState `json:"state"`
	Summary       Summary    `json:"summary"`
	Error         string     `json:"error,omitempty"`
	Timestamp     int64      `json:"timestamp"`
	EventPhase    string     `json:"eventPhase"`
	Operation     string     `json:"operation,omitempty"`
}

type DetailPanelConfig

type DetailPanelConfig struct {
	Title     string                 `json:"title"`
	Collapsed bool                   `json:"collapsed"`
	Fields    []DetailRendererConfig `json:"fields"`
}

DetailPanelConfig represents a detail panel section

type DetailRendererConfig

type DetailRendererConfig struct {
	Key         string `json:"key"`
	Label       string `json:"label"`
	Type        string `json:"type"`
	DetailOrder int    `json:"detailOrder"`
}

DetailRendererConfig represents a field in a detail panel

type ErrorType

type ErrorType string

ErrorType represents different categories of errors that can occur

const (
	ErrorTypeValidation ErrorType = "validation"
	ErrorTypeSDK        ErrorType = "sdk"
	ErrorTypeNetwork    ErrorType = "network"
	ErrorTypeCache      ErrorType = "cache"
	ErrorTypeStore      ErrorType = "store"
	ErrorTypeUnknown    ErrorType = "unknown"
)

func GetErrorContext

func GetErrorContext(err error) (ErrorType, string, string)

GetErrorContext extracts error context for better user messages

type FacetChartConfig

type FacetChartConfig struct {
	SeriesStrategy  string `json:"seriesStrategy,omitempty"`  // how to group data into series ("address", "symbol", "address+symbol")
	SeriesPrefixLen int    `json:"seriesPrefixLen,omitempty"` // prefix length for collision avoidance (8-15)
}

FacetChartConfig represents facet-level chart configuration

type FacetConfig

type FacetConfig struct {
	Name             string              `json:"name"`
	Store            string              `json:"store"`
	ViewType         string              `json:"viewType,omitempty"`
	DividerBefore    bool                `json:"dividerBefore"`
	Disabled         bool                `json:"disabled"`
	CanClose         bool                `json:"canClose"`
	Fields           []FieldConfig       `json:"fields"`
	Columns          []ColumnConfig      `json:"columns"`
	DetailPanels     []DetailPanelConfig `json:"detailPanels"`
	Actions          []string            `json:"actions"`
	HeaderActions    []string            `json:"headerActions"`
	Panel            string              `json:"panel"`
	PanelChartConfig *PanelChartConfig   `json:"panelChartConfig,omitempty"`
	FacetChartConfig *FacetChartConfig   `json:"facetChartConfig,omitempty"`
	RowAction        *RowActionConfig    `json:"rowAction,omitempty"`
}

FacetConfig represents configuration for a single facet within a view

type FieldConfig

type FieldConfig struct {
	Key         string `json:"key"`
	Label       string `json:"label"`
	Type        string `json:"type"`
	Section     string `json:"section"`
	Width       int    `json:"width"`
	Sortable    bool   `json:"sortable"`
	Order       int    `json:"order"`
	DetailOrder int    `json:"detailOrder"`
	NoTable     bool   `json:"-"`
	NoDetail    bool   `json:"-"`
	ColumnLabel string `json:"-"`
	DetailLabel string `json:"-"`
}

FieldConfig is the single source-of-truth for facet fields Header is derived from Label; do not duplicate.

type GridInfo

type GridInfo struct {
	Rows        int    `json:"rows"`
	Columns     int    `json:"columns"`
	MaxBlock    uint64 `json:"maxBlock"`
	Size        uint64 `json:"size"`
	BucketCount int    `json:"bucketCount"`
}

func NewGridInfo

func NewGridInfo() GridInfo

NewGridInfo creates a new GridInfo with proper default values

type MetricConfig

type MetricConfig struct {
	Key          string `json:"key"`          // unique identifier
	Label        string `json:"label"`        // display name
	BucketsField string `json:"bucketsField"` // field name in Buckets struct
	Bytes        bool   `json:"bytes"`        // whether to format as bytes
}

MetricConfig represents a single metric configuration

type NavigationPayload struct {
	Payload
	RecordId string `json:"recordId"` // Unique identifier for database lookup
	RowIndex int    `json:"rowIndex"` // Calculated position in current table
}
type NavigationTarget struct {
	View        string          `json:"view"`                  // Target view name (e.g., "exports")
	Facet       string          `json:"facet"`                 // Target facet (e.g., "assetcharts") or "<latest>" for last visited
	RowIndex    int             `json:"rowIndex"`              // Row index in target view (default: 0)
	Identifiers []RowIdentifier `json:"identifiers,omitempty"` // Context extraction rules
}

NavigationTarget defines the destination for row navigation actions

type Page

type Page interface {
	GetFacet() DataFacet
	GetTotalItems() int
	GetExpectedTotal() int
	GetState() StoreState
}

type PanelChartConfig

type PanelChartConfig struct {
	Type          string         `json:"type"`                  // "barchart" or "heatmap"
	DefaultMetric string         `json:"defaultMetric"`         // key of default metric
	SkipUntil     string         `json:"skipUntil,omitempty"`   // optional date filter
	TimeGroupBy   string         `json:"timeGroupBy,omitempty"` // "daily", "monthly", "quarterly", "annual"
	Metrics       []MetricConfig `json:"metrics"`               // available metrics
}

PanelChartConfig represents visualization panel configuration

type Payload

type Payload struct {
	Collection       string    `json:"collection"`
	DataFacet        DataFacet `json:"dataFacet"`
	ActiveChain      string    `json:"activeChain,omitempty"`
	ActiveAddress    string    `json:"activeAddress,omitempty"`
	ActiveContract   string    `json:"activeContract,omitempty"`
	ActivePeriod     Period    `json:"activePeriod,omitempty"`
	ConnectedAddress string    `json:"connectedAddress,omitempty"`
	TargetAddress    string    `json:"targetAddress,omitempty"`
	TargetSwitch     bool      `json:"targetSwitch,omitempty"`
	Format           string    `json:"format,omitempty"`
	ProjectPath      string    `json:"projectPath,omitempty"`
}

func (*Payload) ShouldSummarize

func (p *Payload) ShouldSummarize() bool

type Period

type Period string

Period represents different time aggregation levels

const (
	PeriodBlockly   Period = "blockly" // Default - no aggregation, raw data
	PeriodHourly    Period = "hourly"
	PeriodDaily     Period = "daily"
	PeriodWeekly    Period = "weekly"
	PeriodMonthly   Period = "monthly"
	PeriodQuarterly Period = "quarterly"
	PeriodAnnual    Period = "annual"
)

Period constants for different time aggregation levels

type ProjectPayload

type ProjectPayload struct {
	HasProject     bool                 `json:"hasProject"`
	ActiveChain    string               `json:"activeChain"`
	ActivePeriod   Period               `json:"activePeriod"`
	ActiveAddress  string               `json:"activeAddress"`
	ActiveContract string               `json:"activeContract"`
	LastView       string               `json:"lastView"`
	LastFacetMap   map[string]DataFacet `json:"lastFacetMap"`
}

type RowActionConfig

type RowActionConfig struct {
	Type          string                 `json:"type"`                    // "navigate", "modal", "custom", "none"
	Target        *NavigationTarget      `json:"target,omitempty"`        // For navigation actions
	CustomHandler string                 `json:"customHandler,omitempty"` // For custom actions
	Parameters    map[string]interface{} `json:"parameters,omitempty"`    // Additional parameters
}

RowActionConfig defines what happens when a user presses Enter on a table row

func NewRowActionNavigation

func NewRowActionNavigation(targetView, targetFacet, fieldType, fieldName string) *RowActionConfig

NewRowActionNavigation creates a navigation row action with sensible defaults

type RowActionPayload

type RowActionPayload struct {
	Payload
	RowData       map[string]interface{} `json:"rowData"`
	RowAction     *RowActionConfig       `json:"rowAction"`
	ContextValues map[string]interface{} `json:"contextValues,omitempty"` // Processed context values
}

type RowIdentifier

type RowIdentifier struct {
	Type       string `json:"type"`                 // "address", "hash", "blockRange"
	FieldName  string `json:"fieldName"`            // Field name to extract from row data
	ContextKey string `json:"contextKey,omitempty"` // Key to use in context (defaults to Type)
}

RowIdentifier represents different ways to identify/extract context from a row

type StoreState

type StoreState string
const (
	StateStale    StoreState = "stale"    // Needs refresh
	StateFetching StoreState = "fetching" // Currently loading
	StateLoaded   StoreState = "loaded"   // Complete data
)

type Summary

type Summary struct {
	TotalCount  int                    `json:"totalCount"`
	FacetCounts map[DataFacet]int      `json:"facetCounts"`
	CustomData  map[string]interface{} `json:"customData,omitempty"`
	LastUpdated int64                  `json:"lastUpdated"`
}

type SummaryAccumulator

type SummaryAccumulator interface {
	AccumulateItem(item interface{}, summary *Summary)
	GetSummary(payload *Payload) Summary
	ResetSummary()
}

type ViewConfig

type ViewConfig struct {
	ViewName     string                  `json:"viewName"`
	Disabled     bool                    `json:"disabled"`
	Facets       map[string]FacetConfig  `json:"facets"`
	Actions      map[string]ActionConfig `json:"actions"`
	FacetOrder   []string                `json:"facetOrder"`
	MenuOrder    int                     `json:"menuOrder,omitempty"`
	MenuPosition string                  `json:"menuPosition,omitempty"`
	MenuLabel    string                  `json:"menuLabel,omitempty"`
}

ViewConfig represents the complete configuration for a view

func (*ViewConfig) IsDisabled

func (vc *ViewConfig) IsDisabled() bool

IsDisabled returns true if the view is disabled or all its facets are disabled

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL