infrastructure

package
v0.0.0-...-7e80ac8 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2025 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

GenericMembershipIndexerSet provides the generic membership indexer for Wire dependency injection

InfrastructureSet provides all infrastructure dependencies

MembershipIndexerSet provides the membership indexer for Wire dependency injection

OptimizedInfrastructureSet provides optimized infrastructure dependencies with caching and indexing

PostgreSQLMembershipIndexerSet provides PostgreSQL-specific membership indexer

SQLiteMembershipIndexerSet provides SQLite-specific membership indexer

View Source
var SupportedFormats = map[string]bool{
	"application/ld+json": true,
	"text/turtle":         true,
	"application/rdf+xml": true,
	"application/json":    true,
	"text/plain":          true,
}

SupportedFormats defines the RDF formats supported by the converter

Functions

func DatabaseProvider

func DatabaseProvider() (*gorm.DB, error)

DatabaseProvider creates a GORM database instance using pericarp's database setup

func EventStoreProvider

func EventStoreProvider(db *gorm.DB) (*infrastructure.GormEventStore, error)

EventStoreProvider creates a GormEventStore using pericarp's implementation

func MigrateDatabaseWithProvider

func MigrateDatabaseWithProvider(db *sql.DB, provider SchemaProvider) error

MigrateDatabase applies all pending migrations using the appropriate schema provider

func NewDatabaseConnection

func NewDatabaseConnection(config DatabaseConfig) (*sql.DB, error)

NewDatabaseConnection creates a database connection based on configuration

func NewEventDispatcher

func NewEventDispatcher() (domain.EventDispatcher, error)

NewEventDispatcher creates a new WatermillEventDispatcher instance using pericarp

func NewFileSystemContainerRepositoryProvider

func NewFileSystemContainerRepositoryProvider(config *conf.Container) (domain.ContainerRepository, error)

NewFileSystemContainerRepositoryProvider provides a FileSystemContainerRepository for Wire dependency injection

func NewFileSystemRepositoryProvider

func NewFileSystemRepositoryProvider() (domain.StreamingResourceRepository, error)

NewFileSystemRepositoryProvider provides a FileSystemRepository for Wire dependency injection This function uses a default base path for the repository

func NewFileSystemRepositoryWithPath

func NewFileSystemRepositoryWithPath(basePath string) (domain.StreamingResourceRepository, error)

NewFileSystemRepositoryWithPath provides a FileSystemRepository with a specific base path

func NewGORMContainerRepositoryProvider

func NewGORMContainerRepositoryProvider(db *gorm.DB) (domain.ContainerRepository, error)

NewGORMContainerRepositoryProvider provides a GORMContainerRepository for Wire dependency injection

func NewOptimizedFileSystemRepositoryProvider

func NewOptimizedFileSystemRepositoryProvider() (domain.StreamingResourceRepository, error)

NewOptimizedFileSystemRepositoryProvider provides an OptimizedFileSystemRepository for Wire

func NewUnitOfWorkFactory

func NewUnitOfWorkFactory(
	eventStore pericarpdomain.EventStore,
	eventDispatcher pericarpdomain.EventDispatcher,
) func() pericarpdomain.UnitOfWork

NewUnitOfWorkFactory creates a factory function for creating UnitOfWork instances

Types

type CacheConfig

type CacheConfig struct {
	MaxSize    int64         // Maximum cache size in bytes (default: 100MB)
	MaxEntries int           // Maximum number of entries (default: 1000)
	TTL        time.Duration // Time to live (default: 1 hour)
}

CacheConfig holds configuration for the resource cache

type CacheEntry

type CacheEntry struct {
	Resource *domain.Resource
	AccessAt time.Time
	HitCount int64
	Size     int
}

CacheEntry represents a cached resource with metadata

type CachedContainerRepository

type CachedContainerRepository struct {
	// contains filtered or unexported fields
}

CachedContainerRepository wraps a container repository with caching

func NewCachedContainerRepository

func NewCachedContainerRepository(repo domain.ContainerRepository, cache *ContainerCache) *CachedContainerRepository

NewCachedContainerRepository creates a new cached container repository

func (*CachedContainerRepository) AddMember

func (r *CachedContainerRepository) AddMember(ctx context.Context, containerID, memberID string) error

AddMember adds a member and invalidates container cache

func (*CachedContainerRepository) ContainerExists

func (r *CachedContainerRepository) ContainerExists(ctx context.Context, id string) (bool, error)

ContainerExists checks existence (no caching for dynamic results)

func (*CachedContainerRepository) CreateContainer

func (r *CachedContainerRepository) CreateContainer(ctx context.Context, container domain.ContainerResource) error

CreateContainer creates a container and invalidates cache

func (*CachedContainerRepository) DeleteContainer

func (r *CachedContainerRepository) DeleteContainer(ctx context.Context, id string) error

DeleteContainer deletes a container and invalidates cache

func (*CachedContainerRepository) FindByPath

FindByPath finds by path (no caching for dynamic results)

func (*CachedContainerRepository) GetChildren

func (r *CachedContainerRepository) GetChildren(ctx context.Context, containerID string) ([]domain.ContainerResource, error)

GetChildren gets children (no caching for dynamic results)

func (*CachedContainerRepository) GetContainer

GetContainer retrieves a container with caching

func (*CachedContainerRepository) GetParent

func (r *CachedContainerRepository) GetParent(ctx context.Context, containerID string) (domain.ContainerResource, error)

GetParent gets parent with caching

func (*CachedContainerRepository) GetPath

func (r *CachedContainerRepository) GetPath(ctx context.Context, containerID string) ([]string, error)

GetPath gets path (no caching for dynamic results)

func (*CachedContainerRepository) ListMembers

func (r *CachedContainerRepository) ListMembers(ctx context.Context, containerID string, pagination domain.PaginationOptions) ([]string, error)

ListMembers lists members (no caching for dynamic results)

func (*CachedContainerRepository) RemoveMember

func (r *CachedContainerRepository) RemoveMember(ctx context.Context, containerID, memberID string) error

RemoveMember removes a member and invalidates container cache

func (*CachedContainerRepository) UpdateContainer

func (r *CachedContainerRepository) UpdateContainer(ctx context.Context, container *domain.Container) error

UpdateContainer updates a container and invalidates cache

type ContainerCache

type ContainerCache struct {
	// contains filtered or unexported fields
}

ContainerCache provides caching for container data and statistics

func NewContainerCache

func NewContainerCache(ttl time.Duration, maxEntries int) *ContainerCache

NewContainerCache creates a new container cache

func (*ContainerCache) Clear

func (c *ContainerCache) Clear()

Clear removes all entries from cache

func (*ContainerCache) Get

func (c *ContainerCache) Get(containerID string) (*domain.Container, bool)

Get retrieves a container from cache

func (*ContainerCache) GetCacheStats

func (c *ContainerCache) GetCacheStats() map[string]interface{}

GetCacheStats returns cache statistics

func (*ContainerCache) GetStats

func (c *ContainerCache) GetStats(containerID string) (memberCount int, totalSize int64, found bool)

GetStats retrieves cached statistics for a container

func (*ContainerCache) Invalidate

func (c *ContainerCache) Invalidate(containerID string)

Invalidate removes a container from cache

func (*ContainerCache) InvalidatePattern

func (c *ContainerCache) InvalidatePattern(pattern string)

InvalidatePattern removes containers matching a pattern from cache

func (*ContainerCache) Put

func (c *ContainerCache) Put(containerID string, container *domain.Container, memberCount int, totalSize int64)

Put stores a container in cache

func (*ContainerCache) Size

func (c *ContainerCache) Size() int

Size returns the number of entries in cache

func (*ContainerCache) UpdateStats

func (c *ContainerCache) UpdateStats(containerID string, memberCount int, totalSize int64)

UpdateStats updates cached statistics for a container

type ContainerCacheEntry

type ContainerCacheEntry struct {
	Container    *domain.Container
	MemberCount  int
	TotalSize    int64
	LastAccessed time.Time
	ExpiresAt    time.Time
}

ContainerCacheEntry represents a cached container entry

func (*ContainerCacheEntry) IsExpired

func (e *ContainerCacheEntry) IsExpired() bool

IsExpired checks if the cache entry has expired

type ContainerMetadata

type ContainerMetadata struct {
	ID            string    `json:"id"`
	ParentID      string    `json:"parentId"`
	ContainerType string    `json:"containerType"`
	Title         string    `json:"title"`
	Description   string    `json:"description"`
	Members       []string  `json:"members"`
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`
}

ContainerMetadata represents the metadata stored for a container

type ContainerModel

type ContainerModel struct {
	ID          string          `gorm:"primaryKey;type:varchar(255)"`
	ParentID    *string         `gorm:"type:varchar(255);index"`
	Parent      *ContainerModel `gorm:"foreignKey:ParentID;references:ID;constraint:OnDelete:CASCADE"`
	Type        string          `gorm:"not null;type:varchar(50);default:'BasicContainer'"`
	Title       string          `gorm:"type:varchar(255)"`
	Description string          `gorm:"type:text"`
	CreatedAt   time.Time       `gorm:"not null"`
	UpdatedAt   time.Time       `gorm:"not null"`

	// Relationships
	Children  []ContainerModel `gorm:"foreignKey:ParentID;references:ID"`
	Resources []ResourceModel  `gorm:"foreignKey:ContainerID;references:ID"`
}

ContainerModel represents the GORM model for containers

func (*ContainerModel) BeforeCreate

func (c *ContainerModel) BeforeCreate(tx *gorm.DB) error

BeforeCreate GORM hook for validation before creation

func (*ContainerModel) BeforeUpdate

func (c *ContainerModel) BeforeUpdate(tx *gorm.DB) error

BeforeUpdate GORM hook for updating timestamps

func (ContainerModel) TableName

func (ContainerModel) TableName() string

TableName specifies the table name for ContainerModel

type ContainerRDFConverter

type ContainerRDFConverter struct {
	// contains filtered or unexported fields
}

ContainerRDFConverter handles conversion of container entities to various RDF formats

func NewContainerRDFConverter

func NewContainerRDFConverter() *ContainerRDFConverter

NewContainerRDFConverter creates a new container RDF converter

func (*ContainerRDFConverter) ConvertToJSONLD

func (c *ContainerRDFConverter) ConvertToJSONLD(container *domain.Container, baseURI string) ([]byte, error)

ConvertToJSONLD converts a container to JSON-LD format

func (*ContainerRDFConverter) ConvertToRDFXML

func (c *ContainerRDFConverter) ConvertToRDFXML(container *domain.Container, baseURI string) ([]byte, error)

ConvertToRDFXML converts a container to RDF/XML format

func (*ContainerRDFConverter) ConvertToTurtle

func (c *ContainerRDFConverter) ConvertToTurtle(container *domain.Container, baseURI string) ([]byte, error)

ConvertToTurtle converts a container to Turtle format

func (*ContainerRDFConverter) GenerateMembershipTriples

func (c *ContainerRDFConverter) GenerateMembershipTriples(container *domain.Container, baseURI string) []ContainerTriple

GenerateMembershipTriples generates LDP membership triples for a container

type ContainerTriple

type ContainerTriple struct {
	Subject    string `json:"subject"`
	Predicate  string `json:"predicate"`
	Object     string `json:"object"`
	ObjectType string `json:"objectType"` // "uri", "literal", "blank"
	DataType   string `json:"dataType,omitempty"`
}

ContainerTriple represents an RDF triple for container serialization

type DatabaseConfig

type DatabaseConfig struct {
	Driver   string // "sqlite3" or "postgres"
	Host     string // PostgreSQL host (ignored for SQLite)
	Port     int    // PostgreSQL port (ignored for SQLite)
	Database string // Database name or SQLite file path
	Username string // PostgreSQL username (ignored for SQLite)
	Password string // PostgreSQL password (ignored for SQLite)
	SSLMode  string // PostgreSQL SSL mode (ignored for SQLite)
}

DatabaseConfig holds database connection configuration

func DatabaseConfigFromEnv

func DatabaseConfigFromEnv() DatabaseConfig

DatabaseConfigFromEnv creates a database configuration from environment variables

func DefaultPostgresConfig

func DefaultPostgresConfig(host, database, username, password string) DatabaseConfig

DefaultPostgresConfig returns a default PostgreSQL configuration

func DefaultSQLiteConfig

func DefaultSQLiteConfig(dbPath string) DatabaseConfig

DefaultSQLiteConfig returns a default SQLite configuration

func DevelopmentSQLiteConfig

func DevelopmentSQLiteConfig() DatabaseConfig

DevelopmentSQLiteConfig returns a SQLite configuration for development

func ProductionPostgreSQLConfig

func ProductionPostgreSQLConfig() DatabaseConfig

ProductionPostgreSQLConfig returns a PostgreSQL configuration for production

func StagingPostgreSQLConfig

func StagingPostgreSQLConfig() DatabaseConfig

StagingPostgreSQLConfig returns a PostgreSQL configuration for staging

func TestSQLiteConfig

func TestSQLiteConfig() DatabaseConfig

TestSQLiteConfig returns a SQLite configuration for testing

type FileSystemContainerRepository

type FileSystemContainerRepository struct {
	*FileSystemRepository // Inherits base filesystem operations
	// contains filtered or unexported fields
}

FileSystemContainerRepository implements ContainerRepository using filesystem storage

func NewFileSystemContainerRepository

func NewFileSystemContainerRepository(basePath string, indexer MembershipIndexer) (*FileSystemContainerRepository, error)

NewFileSystemContainerRepository creates a new FileSystemContainerRepository

func (*FileSystemContainerRepository) AddMember

func (r *FileSystemContainerRepository) AddMember(ctx context.Context, containerID, memberID string) error

AddMember adds a member to a container

func (*FileSystemContainerRepository) ContainerExists

func (r *FileSystemContainerRepository) ContainerExists(ctx context.Context, id string) (bool, error)

ContainerExists checks if a container exists

func (*FileSystemContainerRepository) CreateContainer

func (r *FileSystemContainerRepository) CreateContainer(ctx context.Context, container domain.ContainerResource) error

CreateContainer creates a new container in the filesystem

func (*FileSystemContainerRepository) Delete

Delete deletes a resource (delegates to base repository)

func (*FileSystemContainerRepository) DeleteContainer

func (r *FileSystemContainerRepository) DeleteContainer(ctx context.Context, id string) error

DeleteContainer deletes a container from the filesystem

func (*FileSystemContainerRepository) Exists

Exists checks if a resource exists (delegates to base repository)

func (*FileSystemContainerRepository) FindByPath

FindByPath finds a container by its path

func (*FileSystemContainerRepository) GetChildren

func (r *FileSystemContainerRepository) GetChildren(ctx context.Context, containerID string) ([]domain.ContainerResource, error)

GetChildren returns all child containers of a container

func (*FileSystemContainerRepository) GetContainer

GetContainer retrieves a container from the filesystem

func (*FileSystemContainerRepository) GetParent

GetParent returns the parent container of a container

func (*FileSystemContainerRepository) GetPath

func (r *FileSystemContainerRepository) GetPath(ctx context.Context, containerID string) ([]string, error)

GetPath returns the path to a container as a slice of container IDs

func (*FileSystemContainerRepository) ListMembers

func (r *FileSystemContainerRepository) ListMembers(ctx context.Context, containerID string, pagination domain.PaginationOptions) ([]string, error)

ListMembers lists all members of a container

func (*FileSystemContainerRepository) RemoveMember

func (r *FileSystemContainerRepository) RemoveMember(ctx context.Context, containerID, memberID string) error

RemoveMember removes a member from a container

func (*FileSystemContainerRepository) Retrieve

Retrieve retrieves a resource (delegates to base repository)

func (*FileSystemContainerRepository) RetrieveStream

RetrieveStream retrieves a resource as a stream (delegates to base repository)

func (*FileSystemContainerRepository) Store

Store stores a resource (delegates to base repository)

func (*FileSystemContainerRepository) StoreStream

func (r *FileSystemContainerRepository) StoreStream(ctx context.Context, id string, reader io.Reader, contentType string, size int64) error

StoreStream stores a resource from a stream (delegates to base repository)

func (*FileSystemContainerRepository) UpdateContainer

func (r *FileSystemContainerRepository) UpdateContainer(ctx context.Context, container domain.ContainerResource) error

UpdateContainer updates an existing container

type FileSystemRepository

type FileSystemRepository struct {
	// contains filtered or unexported fields
}

FileSystemRepository implements StreamingResourceRepository using file system storage

func NewFileSystemRepository

func NewFileSystemRepository(basePath string) (*FileSystemRepository, error)

NewFileSystemRepository creates a new FileSystemRepository

func (*FileSystemRepository) Delete

func (r *FileSystemRepository) Delete(ctx context.Context, id string) error

Delete removes a resource from the file system

func (*FileSystemRepository) Exists

func (r *FileSystemRepository) Exists(ctx context.Context, id string) (bool, error)

Exists checks if a resource exists in the file system

func (*FileSystemRepository) Retrieve

Retrieve loads a resource from the file system with checksum validation

func (*FileSystemRepository) RetrieveStream

RetrieveStream retrieves a resource as a stream for efficient memory usage

func (*FileSystemRepository) Store

func (r *FileSystemRepository) Store(ctx context.Context, resource domain.Resource) error

Store saves a resource to the file system with metadata and checksum validation

func (*FileSystemRepository) StoreStream

func (r *FileSystemRepository) StoreStream(ctx context.Context, id string, reader io.Reader, contentType string, size int64) error

StoreStream stores a resource from a stream with efficient memory usage

type FilterOptions

type FilterOptions struct {
	MemberType    string     `json:"memberType,omitempty"`    // "Container" or "Resource"
	ContentType   string     `json:"contentType,omitempty"`   // MIME type filter
	NamePattern   string     `json:"namePattern,omitempty"`   // Name pattern matching
	CreatedAfter  *time.Time `json:"createdAfter,omitempty"`  // Created after timestamp
	CreatedBefore *time.Time `json:"createdBefore,omitempty"` // Created before timestamp
	SizeMin       *int64     `json:"sizeMin,omitempty"`       // Minimum size in bytes
	SizeMax       *int64     `json:"sizeMax,omitempty"`       // Maximum size in bytes
}

FilterOptions represents filtering options for container members

type GORMContainerRepository

type GORMContainerRepository struct {
	// contains filtered or unexported fields
}

GORMContainerRepository implements ContainerRepository using GORM

func NewGORMContainerRepository

func NewGORMContainerRepository(db *gorm.DB) (*GORMContainerRepository, error)

NewGORMContainerRepository creates a new GORM-based container repository

func (*GORMContainerRepository) AddMember

func (r *GORMContainerRepository) AddMember(ctx context.Context, containerID, memberID string) error

AddMember implements ContainerRepository.AddMember

func (*GORMContainerRepository) ContainerExists

func (r *GORMContainerRepository) ContainerExists(ctx context.Context, id string) (bool, error)

ContainerExists implements ContainerRepository.ContainerExists

func (*GORMContainerRepository) CreateContainer

func (r *GORMContainerRepository) CreateContainer(ctx context.Context, container domain.ContainerResource) error

CreateContainer implements ContainerRepository.CreateContainer

func (*GORMContainerRepository) Delete

func (r *GORMContainerRepository) Delete(ctx context.Context, id string) error

Delete implements ResourceRepository.Delete

func (*GORMContainerRepository) DeleteContainer

func (r *GORMContainerRepository) DeleteContainer(ctx context.Context, id string) error

DeleteContainer implements ContainerRepository.DeleteContainer

func (*GORMContainerRepository) Exists

func (r *GORMContainerRepository) Exists(ctx context.Context, id string) (bool, error)

Exists implements ResourceRepository.Exists

func (*GORMContainerRepository) FindByPath

FindByPath implements ContainerRepository.FindByPath

func (*GORMContainerRepository) GetChildren

func (r *GORMContainerRepository) GetChildren(ctx context.Context, containerID string) ([]domain.ContainerResource, error)

GetChildren implements ContainerRepository.GetChildren

func (*GORMContainerRepository) GetContainer

GetContainer implements ContainerRepository.GetContainer

func (*GORMContainerRepository) GetParent

func (r *GORMContainerRepository) GetParent(ctx context.Context, containerID string) (domain.ContainerResource, error)

GetParent implements ContainerRepository.GetParent

func (*GORMContainerRepository) GetPath

func (r *GORMContainerRepository) GetPath(ctx context.Context, containerID string) ([]string, error)

GetPath implements ContainerRepository.GetPath

func (*GORMContainerRepository) ListMembers

func (r *GORMContainerRepository) ListMembers(ctx context.Context, containerID string, pagination domain.PaginationOptions) ([]string, error)

ListMembers implements ContainerRepository.ListMembers

func (*GORMContainerRepository) RemoveMember

func (r *GORMContainerRepository) RemoveMember(ctx context.Context, containerID, memberID string) error

RemoveMember implements ContainerRepository.RemoveMember

func (*GORMContainerRepository) Retrieve

Retrieve implements ResourceRepository.Retrieve

func (*GORMContainerRepository) Store

func (r *GORMContainerRepository) Store(ctx context.Context, resource domain.Resource) error

Store implements ResourceRepository.Store

func (*GORMContainerRepository) UpdateContainer

func (r *GORMContainerRepository) UpdateContainer(ctx context.Context, container domain.ContainerResource) error

UpdateContainer implements ContainerRepository.UpdateContainer

type GenericMembershipIndexer

type GenericMembershipIndexer struct {
	// contains filtered or unexported fields
}

GenericMembershipIndexer implements MembershipIndexer for multiple database types

func GenericMembershipIndexerProvider

func GenericMembershipIndexerProvider(config DatabaseConfig) (*GenericMembershipIndexer, error)

GenericMembershipIndexerProvider creates a GenericMembershipIndexer instance

func NewGenericMembershipIndexer

func NewGenericMembershipIndexer(config DatabaseConfig) (*GenericMembershipIndexer, error)

NewGenericMembershipIndexer creates a new database-agnostic membership indexer

func PostgreSQLMembershipIndexerProvider

func PostgreSQLMembershipIndexerProvider(host, database, username, password string) (*GenericMembershipIndexer, error)

PostgreSQLMembershipIndexerProvider creates a PostgreSQL-specific membership indexer

func SQLiteMembershipIndexerProvider

func SQLiteMembershipIndexerProvider(basePath string) (*GenericMembershipIndexer, error)

SQLiteMembershipIndexerProvider creates a SQLite-specific membership indexer

func (*GenericMembershipIndexer) Close

func (g *GenericMembershipIndexer) Close() error

Close closes the database connection

func (*GenericMembershipIndexer) GetContainerStats

func (g *GenericMembershipIndexer) GetContainerStats(ctx context.Context, containerID string) (map[string]interface{}, error)

GetContainerStats returns statistics about a container

func (*GenericMembershipIndexer) GetContainers

func (g *GenericMembershipIndexer) GetContainers(ctx context.Context, memberID string) ([]string, error)

GetContainers retrieves all containers that contain a specific member

func (*GenericMembershipIndexer) GetMemberCount

func (g *GenericMembershipIndexer) GetMemberCount(ctx context.Context, containerID string) (int, error)

GetMemberCount returns the total number of members in a container

func (*GenericMembershipIndexer) GetMembers

func (g *GenericMembershipIndexer) GetMembers(ctx context.Context, containerID string, pagination PaginationOptions) ([]MemberInfo, error)

GetMembers retrieves all members of a container with pagination

func (*GenericMembershipIndexer) IndexMembership

func (g *GenericMembershipIndexer) IndexMembership(ctx context.Context, containerID, memberID string) error

IndexMembership adds a membership relationship to the index

func (*GenericMembershipIndexer) RebuildIndex

func (g *GenericMembershipIndexer) RebuildIndex(ctx context.Context) error

RebuildIndex rebuilds the membership index from scratch

func (*GenericMembershipIndexer) RemoveMembership

func (g *GenericMembershipIndexer) RemoveMembership(ctx context.Context, containerID, memberID string) error

RemoveMembership removes a membership relationship from the index

type MemberInfo

type MemberInfo struct {
	ID          string
	Type        ResourceType
	ContentType string
	Size        int64
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

MemberInfo contains information about a container member

type MembershipIndexer

type MembershipIndexer interface {
	IndexMembership(ctx context.Context, containerID, memberID string) error
	RemoveMembership(ctx context.Context, containerID, memberID string) error
	GetMembers(ctx context.Context, containerID string, pagination PaginationOptions) ([]MemberInfo, error)
	GetContainers(ctx context.Context, memberID string) ([]string, error)
	RebuildIndex(ctx context.Context) error
	Close() error
}

MembershipIndexer defines the interface for container membership indexing

type MembershipModel

type MembershipModel struct {
	ContainerID string    `gorm:"primaryKey;type:varchar(255)"`
	MemberID    string    `gorm:"primaryKey;type:varchar(255)"`
	MemberType  string    `gorm:"not null;type:varchar(50)"` // "Container" or "Resource"
	CreatedAt   time.Time `gorm:"not null"`

	// Relationships
	Container ContainerModel `gorm:"foreignKey:ContainerID;references:ID;constraint:OnDelete:CASCADE"`
}

MembershipModel represents the GORM model for container membership relationships

func (*MembershipModel) BeforeCreate

func (m *MembershipModel) BeforeCreate(tx *gorm.DB) error

BeforeCreate GORM hook for validation before creation

func (MembershipModel) TableName

func (MembershipModel) TableName() string

TableName specifies the table name for MembershipModel

type OptimizedFileSystemRepository

type OptimizedFileSystemRepository struct {
	*FileSystemRepository
	// contains filtered or unexported fields
}

OptimizedFileSystemRepository extends FileSystemRepository with indexing and caching

func NewOptimizedFileSystemRepository

func NewOptimizedFileSystemRepository(basePath string, cacheConfig CacheConfig) (*OptimizedFileSystemRepository, error)

NewOptimizedFileSystemRepository creates a new optimized repository with indexing and caching

func (*OptimizedFileSystemRepository) ClearCache

func (r *OptimizedFileSystemRepository) ClearCache(ctx context.Context)

ClearCache clears the resource cache

func (*OptimizedFileSystemRepository) Delete

Delete removes a resource with index and cache cleanup

func (*OptimizedFileSystemRepository) Exists

Exists checks if a resource exists using index for fast lookup

func (*OptimizedFileSystemRepository) FindByContentType

func (r *OptimizedFileSystemRepository) FindByContentType(ctx context.Context, contentType string) ([]*domain.Resource, error)

FindByContentType finds resources by content type using index

func (*OptimizedFileSystemRepository) FindByTag

func (r *OptimizedFileSystemRepository) FindByTag(ctx context.Context, key, value string) ([]*domain.Resource, error)

FindByTag finds resources by tag using index

func (*OptimizedFileSystemRepository) GetStats

func (r *OptimizedFileSystemRepository) GetStats(ctx context.Context) map[string]interface{}

GetStats returns combined statistics from repository, index, and cache

func (*OptimizedFileSystemRepository) ListResources

func (r *OptimizedFileSystemRepository) ListResources(ctx context.Context, offset, limit int) ([]*domain.Resource, error)

ListResources returns a paginated list of resources using index

func (*OptimizedFileSystemRepository) RebuildIndex

func (r *OptimizedFileSystemRepository) RebuildIndex(ctx context.Context) error

RebuildIndex rebuilds the resource index

func (*OptimizedFileSystemRepository) Retrieve

Retrieve loads a resource with cache-first lookup and index optimization

func (*OptimizedFileSystemRepository) RetrieveStream

RetrieveStream retrieves a resource as a stream (delegates to base repository)

func (*OptimizedFileSystemRepository) Store

Store saves a resource with optimized indexing and cache invalidation

func (*OptimizedFileSystemRepository) StoreStream

func (r *OptimizedFileSystemRepository) StoreStream(ctx context.Context, id string, reader io.Reader, contentType string, size int64) error

StoreStream stores a resource from a stream (delegates to base repository)

func (*OptimizedFileSystemRepository) WarmupCache

func (r *OptimizedFileSystemRepository) WarmupCache(ctx context.Context) error

WarmupCache preloads frequently accessed resources into cache

type PaginationOptions

type PaginationOptions struct {
	Limit  int
	Offset int
}

PaginationOptions contains pagination parameters

type PostgreSQLSchemaProvider

type PostgreSQLSchemaProvider struct{}

PostgreSQLSchemaProvider implements schema operations for PostgreSQL

func (*PostgreSQLSchemaProvider) CreateContainerSchema

func (p *PostgreSQLSchemaProvider) CreateContainerSchema(db *sql.DB) error

func (*PostgreSQLSchemaProvider) CreateSchemaMigrationsTable

func (p *PostgreSQLSchemaProvider) CreateSchemaMigrationsTable(db *sql.DB) error

func (*PostgreSQLSchemaProvider) GetCurrentSchemaVersion

func (p *PostgreSQLSchemaProvider) GetCurrentSchemaVersion(db *sql.DB) (int, error)

func (*PostgreSQLSchemaProvider) RecordMigration

func (p *PostgreSQLSchemaProvider) RecordMigration(db *sql.DB, version int, description string) error

func (*PostgreSQLSchemaProvider) ValidateSchema

func (p *PostgreSQLSchemaProvider) ValidateSchema(db *sql.DB) error

type RDFConverter

type RDFConverter struct{}

RDFConverter handles conversion between different RDF serialization formats

func NewRDFConverter

func NewRDFConverter() *RDFConverter

NewRDFConverter creates a new RDF format converter

func (*RDFConverter) Convert

func (c *RDFConverter) Convert(data []byte, fromFormat, toFormat string) ([]byte, error)

Convert transforms RDF data from one format to another Supported formats: JSON-LD, Turtle, RDF/XML

func (*RDFConverter) ValidateFormat

func (c *RDFConverter) ValidateFormat(format string) bool

ValidateFormat checks if the given format is supported

type ResourceCache

type ResourceCache struct {
	// contains filtered or unexported fields
}

ResourceCache provides in-memory caching for frequently accessed resources

func NewResourceCache

func NewResourceCache(config CacheConfig) *ResourceCache

NewResourceCache creates a new resource cache with the given configuration

func (*ResourceCache) Clear

func (rc *ResourceCache) Clear(ctx context.Context)

Clear clears all entries from the cache

func (*ResourceCache) Get

func (rc *ResourceCache) Get(ctx context.Context, id string) (*domain.Resource, bool)

Get retrieves a resource from the cache

func (*ResourceCache) GetMostAccessed

func (rc *ResourceCache) GetMostAccessed(limit int) []*CacheEntry

GetMostAccessed returns the most frequently accessed resources

func (*ResourceCache) GetStats

func (rc *ResourceCache) GetStats() map[string]interface{}

GetStats returns cache statistics

func (*ResourceCache) Put

func (rc *ResourceCache) Put(ctx context.Context, resource *domain.Resource)

Put stores a resource in the cache

func (*ResourceCache) Remove

func (rc *ResourceCache) Remove(ctx context.Context, id string)

Remove removes a resource from the cache

func (*ResourceCache) Warmup

func (rc *ResourceCache) Warmup(ctx context.Context, resources []*domain.Resource)

Warmup preloads frequently accessed resources into the cache

type ResourceIndex

type ResourceIndex struct {
	ID          string            `json:"id"`
	ContentType string            `json:"contentType"`
	Size        int               `json:"size"`
	CreatedAt   time.Time         `json:"createdAt"`
	UpdatedAt   time.Time         `json:"updatedAt"`
	Tags        map[string]string `json:"tags"`
	Path        string            `json:"path"`
}

ResourceIndex represents an index entry for a resource

type ResourceIndexer

type ResourceIndexer struct {
	// contains filtered or unexported fields
}

ResourceIndexer provides fast lookup capabilities for resources

func NewResourceIndexer

func NewResourceIndexer(basePath string) (*ResourceIndexer, error)

NewResourceIndexer creates a new resource indexer

func (*ResourceIndexer) AddResource

func (ri *ResourceIndexer) AddResource(resource *domain.Resource) error

AddResource adds a resource to the index

func (*ResourceIndexer) FindByContentType

func (ri *ResourceIndexer) FindByContentType(contentType string) []*ResourceIndex

FindByContentType finds resources by content type

func (*ResourceIndexer) FindByID

func (ri *ResourceIndexer) FindByID(id string) (*ResourceIndex, bool)

FindByID finds a resource by ID

func (*ResourceIndexer) FindBySizeRange

func (ri *ResourceIndexer) FindBySizeRange(minSize, maxSize int) []*ResourceIndex

FindBySizeRange finds resources within a size range

func (*ResourceIndexer) FindByTag

func (ri *ResourceIndexer) FindByTag(key, value string) []*ResourceIndex

FindByTag finds resources by tag

func (*ResourceIndexer) GetStats

func (ri *ResourceIndexer) GetStats() map[string]interface{}

GetStats returns indexing statistics

func (*ResourceIndexer) ListAll

func (ri *ResourceIndexer) ListAll() []*ResourceIndex

ListAll returns all indexed resources

func (*ResourceIndexer) Rebuild

func (ri *ResourceIndexer) Rebuild(ctx context.Context) error

Rebuild rebuilds the index by scanning the file system

func (*ResourceIndexer) RemoveResource

func (ri *ResourceIndexer) RemoveResource(id string) error

RemoveResource removes a resource from the index

type ResourceMetadata

type ResourceMetadata struct {
	ID             string                 `json:"id"`
	ContentType    string                 `json:"contentType"`
	OriginalFormat string                 `json:"originalFormat"`
	Size           int                    `json:"size"`
	Checksum       string                 `json:"checksum"`
	CreatedAt      time.Time              `json:"createdAt"`
	UpdatedAt      time.Time              `json:"updatedAt"`
	Tags           map[string]interface{} `json:"tags"`
}

ResourceMetadata represents the metadata stored alongside resource content

type ResourceModel

type ResourceModel struct {
	ID          string         `gorm:"primaryKey;type:varchar(255)"`
	ContainerID string         `gorm:"not null;type:varchar(255);index"`
	Container   ContainerModel `gorm:"foreignKey:ContainerID;references:ID;constraint:OnDelete:CASCADE"`
	ContentType string         `gorm:"not null;type:varchar(255)"`
	Size        int64          `gorm:"not null;default:0"`
	FilePath    string         `gorm:"type:varchar(500)"` // Path to file on filesystem
	Metadata    string         `gorm:"type:text"`         // JSON serialized metadata
	CreatedAt   time.Time      `gorm:"not null"`
	UpdatedAt   time.Time      `gorm:"not null"`
}

ResourceModel represents the GORM model for resources

func (*ResourceModel) BeforeCreate

func (r *ResourceModel) BeforeCreate(tx *gorm.DB) error

BeforeCreate GORM hook for validation before creation

func (*ResourceModel) BeforeUpdate

func (r *ResourceModel) BeforeUpdate(tx *gorm.DB) error

BeforeUpdate GORM hook for updating timestamps

func (ResourceModel) TableName

func (ResourceModel) TableName() string

TableName specifies the table name for ResourceModel

type ResourceType

type ResourceType string

ResourceType represents the type of a resource

const (
	ResourceTypeContainer ResourceType = "Container"
	ResourceTypeResource  ResourceType = "Resource"
)

type SQLiteMembershipIndexer

type SQLiteMembershipIndexer struct {
	// contains filtered or unexported fields
}

SQLiteMembershipIndexer implements MembershipIndexer using SQLite

func MembershipIndexerProvider

func MembershipIndexerProvider(basePath string) (*SQLiteMembershipIndexer, error)

MembershipIndexerProvider creates a SQLiteMembershipIndexer instance (legacy)

func NewSQLiteMembershipIndexer

func NewSQLiteMembershipIndexer(dbPath string) (*SQLiteMembershipIndexer, error)

NewSQLiteMembershipIndexer creates a new SQLite membership indexer

func (*SQLiteMembershipIndexer) Close

func (s *SQLiteMembershipIndexer) Close() error

Close closes the database connection

func (*SQLiteMembershipIndexer) GetContainerStats

func (s *SQLiteMembershipIndexer) GetContainerStats(ctx context.Context, containerID string) (map[string]interface{}, error)

GetContainerStats returns statistics about a container

func (*SQLiteMembershipIndexer) GetContainers

func (s *SQLiteMembershipIndexer) GetContainers(ctx context.Context, memberID string) ([]string, error)

GetContainers retrieves all containers that contain a specific member

func (*SQLiteMembershipIndexer) GetDB

func (s *SQLiteMembershipIndexer) GetDB() *sql.DB

GetDB returns the database connection (for internal use by repository)

func (*SQLiteMembershipIndexer) GetFilteredMemberCount

func (s *SQLiteMembershipIndexer) GetFilteredMemberCount(ctx context.Context, containerID string, filter FilterOptions) (int, error)

GetFilteredMemberCount returns the count of members matching the filter

func (*SQLiteMembershipIndexer) GetMemberCount

func (s *SQLiteMembershipIndexer) GetMemberCount(ctx context.Context, containerID string) (int, error)

GetMemberCount returns the total number of members in a container

func (*SQLiteMembershipIndexer) GetMembers

func (s *SQLiteMembershipIndexer) GetMembers(ctx context.Context, containerID string, pagination PaginationOptions) ([]MemberInfo, error)

GetMembers retrieves all members of a container with pagination

func (*SQLiteMembershipIndexer) GetMembersWithFiltering

func (s *SQLiteMembershipIndexer) GetMembersWithFiltering(ctx context.Context, containerID string, pagination PaginationOptions, filter FilterOptions, sort SortOptions) ([]MemberInfo, error)

GetMembersWithFiltering retrieves container members with filtering and sorting

func (*SQLiteMembershipIndexer) IndexMembership

func (s *SQLiteMembershipIndexer) IndexMembership(ctx context.Context, containerID, memberID string) error

IndexMembership adds a membership relationship to the index

func (*SQLiteMembershipIndexer) RebuildIndex

func (s *SQLiteMembershipIndexer) RebuildIndex(ctx context.Context) error

RebuildIndex rebuilds the membership index from scratch

func (*SQLiteMembershipIndexer) RemoveMembership

func (s *SQLiteMembershipIndexer) RemoveMembership(ctx context.Context, containerID, memberID string) error

RemoveMembership removes a membership relationship from the index

type SQLiteSchemaProvider

type SQLiteSchemaProvider struct{}

SQLiteSchemaProvider implements schema operations for SQLite

func (*SQLiteSchemaProvider) CreateContainerSchema

func (p *SQLiteSchemaProvider) CreateContainerSchema(db *sql.DB) error

func (*SQLiteSchemaProvider) CreateSchemaMigrationsTable

func (p *SQLiteSchemaProvider) CreateSchemaMigrationsTable(db *sql.DB) error

func (*SQLiteSchemaProvider) GetCurrentSchemaVersion

func (p *SQLiteSchemaProvider) GetCurrentSchemaVersion(db *sql.DB) (int, error)

func (*SQLiteSchemaProvider) RecordMigration

func (p *SQLiteSchemaProvider) RecordMigration(db *sql.DB, version int, description string) error

func (*SQLiteSchemaProvider) ValidateSchema

func (p *SQLiteSchemaProvider) ValidateSchema(db *sql.DB) error

type SchemaProvider

type SchemaProvider interface {
	CreateContainerSchema(db *sql.DB) error
	CreateSchemaMigrationsTable(db *sql.DB) error
	GetCurrentSchemaVersion(db *sql.DB) (int, error)
	RecordMigration(db *sql.DB, version int, description string) error
	ValidateSchema(db *sql.DB) error
}

SchemaProvider handles database schema operations for different database types

func NewSchemaProvider

func NewSchemaProvider(driver string) (SchemaProvider, error)

NewSchemaProvider creates a schema provider for the given database driver

type SortOptions

type SortOptions struct {
	Field     string `json:"field"`     // "name", "createdAt", "updatedAt", "size", "type"
	Direction string `json:"direction"` // "asc" or "desc"
}

SortOptions represents sorting options for container members

Jump to

Keyboard shortcuts

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