92 lines
1.6 KiB
Go
92 lines
1.6 KiB
Go
|
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. 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
|
||
|
}
|
||
|
|
||
|
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
|
||
|
StateTransformer
|
||
|
Resource() Resource
|
||
|
Clone() Declaration
|
||
|
}
|
||
|
|
||
|
func NewResourceMapper() ResourceMapper {
|
||
|
return mapper.New[string, Declaration]()
|
||
|
}
|
||
|
|
||
|
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 {
|
||
|
FilePath() string
|
||
|
SetFileInfo(fs.FileInfo) error
|
||
|
FileInfo() fs.FileInfo
|
||
|
ContentGetSetter
|
||
|
SetContentSourceRef(uri string)
|
||
|
}
|
||
|
|