// Copyright 2024 Matthew Rich . All rights reserved. package data import ( "context" "errors" "decl/internal/mapper" "decl/internal/transport" "gitea.rosskeen.house/rosskeen.house/machine" "io" "io/fs" ) var ( ErrInvalidResource error = errors.New("Invalid resource") ) type ResourceMapper mapper.Map[string, Declaration] type StateTransformer interface { Apply() error } // Used by the resource factory to initialize new resources. type ResourceInitializer interface { Init(uri URIParser) error } type Resource interface { Identifier Type() string StateMachine() machine.Stater UseConfig(config ConfigurationValueGetter) ResolveId(context.Context) string Loader StateTransformer Crudder Validator Clone() Resource SetResourceMapper(ResourceMapper) } type Declaration interface { Identifier ResourceType() TypeName ResolveId(context.Context) string Loader Validator DocumentStateTransformer Resource() Resource Clone() Declaration } func NewResourceMapper() ResourceMapper { return mapper.New[string, Declaration]() } type ContentHasher interface { Hash() []byte HashHexString() string } type ContentIdentifier interface { ContentType() string } type ContentReader interface { ContentReaderStream() (*transport.Reader, error) } type ContentWriter interface { ContentWriterStream() (*transport.Writer, error) } type ContentReadWriter interface { ContentReader ContentWriter } type ContentGetter interface { GetContent(w io.Writer) (contentReader io.ReadCloser, err error) } type ContentSetter interface { SetContent(r io.Reader) error } type ContentGetSetter interface { ContentGetter ContentSetter } type FileResource interface { SetBasePath(int) FilePath() string SetFileInfo(fs.FileInfo) error FileInfo() fs.FileInfo ContentGetSetter GetContentSourceRef() string SetContentSourceRef(uri string) SetFS(fs.FS) PathNormalization(bool) NormalizePath() error GetTarget() string SetGzipContent(bool) } type Signed interface { Signature() Signature } type FileInfoGetter interface { Stat() (fs.FileInfo, error) }