Documentation
¶
Index ¶
- Constants
- func AddDocumentVersion(ctx context.Context, docID, userID uu.ID, reason string, ...) (err error)
- func CheckConnDocumentVersionFiles(ctx context.Context, conn Conn, docID uu.ID, version VersionTime, ...) (err error)
- func CheckedOutDocumentDir(docID uu.ID) fs.File
- func Configure(db Conn)
- func ContentHash(data []byte) string
- func ContextWithVersionTime(parent context.Context, version VersionTime) context.Context
- func CopyAllCompanyDocumentFiles(ctx context.Context, conn Conn, companyID uu.ID, backupDir fs.File, ...) (docDirs []fs.File, err error)
- func CopyDocumentFiles(ctx context.Context, conn Conn, docID uu.ID, backupDir fs.File, overwrite bool) (destDocDir fs.File, err error)
- func DeleteDocument(ctx context.Context, docID uu.ID) (err error)
- func DocumentCompanyID(ctx context.Context, docID uu.ID) (companyID uu.ID, err error)
- func DocumentExists(ctx context.Context, docID uu.ID) (exists bool, err error)
- func DocumentFileExists(ctx context.Context, docID uu.ID, filename string) (exists bool, err error)
- func DocumentVersionFileReader(ctx context.Context, docID uu.ID, version VersionTime, filename string) (fileReader fs.FileReader, err error)
- func EnumCompanyDocumentIDs(ctx context.Context, companyID uu.ID, ...) (err error)
- func EnumDocumentIDs(ctx context.Context, callback func(context.Context, uu.ID) error) (err error)
- func FirstDocumentVersionCommitUserID(ctx context.Context, docID uu.ID) (userID uu.ID, err error)
- func IdenticalDocumentVersionsOfDrivers(ctx context.Context, docID uu.ID, driverA Conn, versionA VersionTime, ...) (identical bool, err error)
- func IsErrDocumentCheckedOutByUser(err error, userID uu.ID) bool
- func PostgresDeleteDocumentVersionByID(ctx context.Context, versionID uu.ID) (err error)
- func PostgresGetDocumentVersionIDOrNull(ctx context.Context, documentID uu.ID, version VersionTime) (id uu.NullableID, err error)
- func PostgresGetDocumentVersionIDs(ctx context.Context, documentID uu.ID) (ids uu.IDSlice, err error)
- func PostgresInsertDocumentVersionIfMissing(ctx context.Context, versionInfo *VersionInfo) (versionID uu.ID, didExist bool, err error)
- func PostgresInsertDocumentVersionWithFiles(ctx context.Context, versionID uu.ID, versionInfo *VersionInfo) (err error)
- func ReadDocumentVersionFile(ctx context.Context, docID uu.ID, version VersionTime, filename string) (data []byte, err error)
- func ReadMemFile(ctx context.Context, provider FileProvider, filename string) (fs.MemFile, error)
- func SetDocumentCompanyID(ctx context.Context, docID, companyID uu.ID) (err error)
- func TempFileCopy(ctx context.Context, provider FileProvider, filename string) (fs.File, error)
- func ToRefactorVersionExists(ctx context.Context, documentID uu.ID, version VersionTime) (exists bool, err error)
- type CheckOutStatus
- func CheckOutDocument(ctx context.Context, docID, userID uu.ID, reason string) (status *CheckOutStatus, err error)
- func CheckOutNewDocument(ctx context.Context, docID, companyID, userID uu.ID, reason string) (status *CheckOutStatus, err error)
- func CheckedOutDocuments(ctx context.Context) (stati []*CheckOutStatus, err error)
- func DocumentCheckOutStatus(ctx context.Context, docID uu.ID) (status *CheckOutStatus, err error)
- type Conn
- type CreateVersionFunc
- type DeprecatedConn
- type ErrDocumentAlreadyExists
- type ErrDocumentChanged
- type ErrDocumentCheckedOut
- type ErrDocumentFileNotFound
- type ErrDocumentHasNoCommitedVersion
- type ErrDocumentNotCheckedOut
- type ErrDocumentNotFound
- type ErrDocumentVersionNotFound
- type ErrVersionAlreadyExists
- type FileInfo
- type FileProvider
- func CheckedOutDocumentFileProvider(docID uu.ID) (p FileProvider, err error)
- func DirFileProvider(dir fs.File) FileProvider
- func DocumentVersionFileProvider(ctx context.Context, docID uu.ID, version VersionTime) (p FileProvider, err error)
- func ExtFileProvider(base FileProvider, extFiles ...fs.FileReader) FileProvider
- func LatestDocumentVersionFileProvider(ctx context.Context, docID uu.ID) (p FileProvider, err error)
- func RemoveFileProvider(base FileProvider, removeFilenames ...string) FileProvider
- type HashedDocument
- type HashedVersion
- type MockFileProvider
- type OnNewVersionFunc
- type VersionInfo
- func CheckInDocument(ctx context.Context, docID uu.ID) (v *VersionInfo, err error)
- func CreateDocument(ctx context.Context, companyID, docID, userID uu.ID, reason string, ...) (versionInfo *VersionInfo, err error)
- func DocumentFileReader(ctx context.Context, docID uu.ID, filename string) (fileReader fs.FileReader, versionInfo *VersionInfo, err error)
- func DocumentVersionInfo(ctx context.Context, docID uu.ID, version VersionTime) (info *VersionInfo, err error)
- func LatestDocumentVersionInfo(ctx context.Context, docID uu.ID) (info *VersionInfo, err error)
- func NewVersionInfo(companyID, docID uu.ID, version, prevVersion VersionTime, commitUserID uu.ID, ...) (versionInfo *VersionInfo, err error)
- func ReadDocumentFile(ctx context.Context, docID uu.ID, filename string) (data []byte, versionInfo *VersionInfo, err error)
- func ReadVersionInfoJSON(file fs.File, writeFixedVersion bool) (versionInfo *VersionInfo, err error)
- type VersionTime
- func CancelCheckOutDocument(ctx context.Context, docID uu.ID) (wasCheckedOut bool, lastVersion VersionTime, err error)
- func DeleteDocumentVersion(ctx context.Context, docID uu.ID, version VersionTime) (leftVersions []VersionTime, err error)
- func DocumentVersions(ctx context.Context, docID uu.ID) (versions []VersionTime, err error)
- func LatestDocumentVersion(ctx context.Context, docID uu.ID) (version VersionTime, err error)
- func MustVersionTimeFromString(str string) VersionTime
- func NewVersionTime(ctx context.Context) VersionTime
- func PostgresGetLatestDocumentVersionTimeAndID(ctx context.Context, documentID uu.ID) (version VersionTime, id uu.ID, err error)
- func PostgresGetLatestVersion(ctx context.Context, documentID uu.ID) (version VersionTime, err error)
- func ReadLatestDocumentVersionFile(ctx context.Context, docID uu.ID, filename string) (data []byte, version VersionTime, err error)
- func SubstituteDeletedDocumentVersion(ctx context.Context, docID uu.ID, version VersionTime) (validVersion VersionTime, err error)
- func VersionTimeFrom(t time.Time) VersionTime
- func VersionTimeFromString(str string) (VersionTime, error)
- func (v VersionTime) After(other VersionTime) bool
- func (v VersionTime) Before(other VersionTime) bool
- func (v VersionTime) Compare(r VersionTime) int
- func (v VersionTime) Equal(other VersionTime) bool
- func (v VersionTime) IsNotNull() bool
- func (v VersionTime) IsNull() bool
- func (v VersionTime) MarshalText() (text []byte, err error)
- func (v VersionTime) NullableTime() nullable.Time
- func (v VersionTime) PrettyPrint(w io.Writer)
- func (v *VersionTime) Scan(value any) error
- func (v *VersionTime) SetNull()
- func (v VersionTime) String() string
- func (v *VersionTime) UnmarshalText(text []byte) error
- func (v VersionTime) Value() (sqldriver.Value, error)
Constants ¶
const ErrNoChanges errs.Sentinel = "no changes"
ErrNoChanges is returned when a new document version has no changes compared to the previous version.
const ( // VersionTimeFormat is the string format of a version time // returned by VersionTime.String() and parsed by VersionTimeFromString. VersionTimeFormat = "2006-01-02_15-04-05.000" )
Variables ¶
This section is empty.
Functions ¶
func AddDocumentVersion ¶
func AddDocumentVersion(ctx context.Context, docID, userID uu.ID, reason string, createVersion CreateVersionFunc, onNewVersion OnNewVersionFunc) (err error)
AddDocumentVersion adds a new version to a document using the files returned by createVersion. Returns a wrapped ErrNoChanges if the files returned by createVersion are the same as the latest version.
func CheckedOutDocumentDir ¶
CheckedOutDocumentDir returns a fs.File for the directory where a document would be checked out.
func ContentHash ¶
ContentHash returns a Dropbox compatible 64 hex character content hash for the passed data.
See https://www.dropbox.com/developers/reference/content-hash
func ContextWithVersionTime ¶
func ContextWithVersionTime(parent context.Context, version VersionTime) context.Context
ContextWithVersionTime returns a new context with the passed version time added to it.
This is useful in combination with NewVersionTime(ctx) for deterministic versions in unit tests.
func CopyAllCompanyDocumentFiles ¶
func CopyAllCompanyDocumentFiles(ctx context.Context, conn Conn, companyID uu.ID, backupDir fs.File, overwrite bool) (docDirs []fs.File, err error)
CopyAllCompanyDocumentFiles copies the files of all versions of all documents of a company to a backup directory.
The backupDir must exist and a directory structures for the documents will be created inside the backupDir and returned as docDirs. In case of an error the already backed up documents will be returned as docDirs.
If true is passed for overwrite then existing files will be overwritten else an error is reeturned when docDir already exists.
func CopyDocumentFiles ¶
func CopyDocumentFiles(ctx context.Context, conn Conn, docID uu.ID, backupDir fs.File, overwrite bool) (destDocDir fs.File, err error)
CopyDocumentFiles copies the files of all versions of a document to a backup directory.
The backupDir must exist and a directory structure for the docID will be created inside the backupDir and returned as docDir.
If true is passed for overwrite then existing files will be overwritten else an error is reeturned when docDir already exists.
In case of an error the already created directories and files will be removed.
func DeleteDocument ¶
DeleteDocument deletes all versions of a document including its workspace directory if checked out.
func DocumentCompanyID ¶
DocumentCompanyID returns the companyID for a docID
func DocumentExists ¶
DocumentExists returns true if a document with the passed docID exists
func DocumentFileExists ¶
DocumentFileExists returns if a document file with filename exists in the latest document version.
func DocumentVersionFileReader ¶
func DocumentVersionFileReader(ctx context.Context, docID uu.ID, version VersionTime, filename string) (fileReader fs.FileReader, err error)
DocumentVersionFileReader returns a fs.FileReader for a file of a document version. Wrapped ErrDocumentNotFound, ErrDocumentVersionNotFound, ErrDocumentFileNotFound will be returned in case of such error conditions.
func EnumCompanyDocumentIDs ¶
func EnumCompanyDocumentIDs(ctx context.Context, companyID uu.ID, callback func(context.Context, uu.ID) error) (err error)
EnumCompanyDocumentIDs calls the passed callback with the ID of every document of a company in the database
func EnumDocumentIDs ¶
EnumDocumentIDs calls the passed callback with the ID of every document in the database
func IdenticalDocumentVersionsOfDrivers ¶
func IdenticalDocumentVersionsOfDrivers(ctx context.Context, docID uu.ID, driverA Conn, versionA VersionTime, driverB Conn, versionB VersionTime) (identical bool, err error)
func PostgresGetDocumentVersionIDOrNull ¶
func PostgresGetDocumentVersionIDOrNull(ctx context.Context, documentID uu.ID, version VersionTime) (id uu.NullableID, err error)
func PostgresInsertDocumentVersionIfMissing ¶
func PostgresInsertDocumentVersionIfMissing(ctx context.Context, versionInfo *VersionInfo) (versionID uu.ID, didExist bool, err error)
PostgresInsertDocumentVersionIfMissing inserts the document information if there is no existing one
func ReadDocumentVersionFile ¶
func ReadDocumentVersionFile(ctx context.Context, docID uu.ID, version VersionTime, filename string) (data []byte, err error)
ReadDocumentVersionFile returns the contents of a file of a document version. Wrapped ErrDocumentNotFound, ErrDocumentVersionNotFound, ErrDocumentFileNotFound will be returned in case of such error conditions.
func ReadMemFile ¶
func ReadMemFile(ctx context.Context, provider FileProvider, filename string) (fs.MemFile, error)
ReadMemFile reads a file from a FileProvider and returns it as an fs.MemFile.
func SetDocumentCompanyID ¶
SetDocumentCompanyID changes the companyID for a document
func TempFileCopy ¶
func TempFileCopy(ctx context.Context, provider FileProvider, filename string) (fs.File, error)
TempFileCopy reads a file from a FileProvider and writes it to a temporary file with a random basename and the same extension as the original filename.
func ToRefactorVersionExists ¶
Types ¶
type CheckOutStatus ¶
type CheckOutStatus struct { CompanyID uu.ID DocID uu.ID Version VersionTime UserID uu.ID Reason string Time time.Time CheckOutDir fs.File }
func CheckOutDocument ¶
func CheckOutDocument(ctx context.Context, docID, userID uu.ID, reason string) (status *CheckOutStatus, err error)
CheckOutDocument checks out a document for a user with a stated reason. Returns ErrDocumentCheckedOut if the document is already checked out.
func CheckOutNewDocument ¶
func CheckOutNewDocument(ctx context.Context, docID, companyID, userID uu.ID, reason string) (status *CheckOutStatus, err error)
CheckOutNewDocument creates a new document for a company in checked out state.
func CheckedOutDocuments ¶
func CheckedOutDocuments(ctx context.Context) (stati []*CheckOutStatus, err error)
CheckedOutDocuments returns the CheckOutStatus of all checked out documents.
func DocumentCheckOutStatus ¶
DocumentCheckOutStatus returns the CheckOutStatus of a document. If the document is not checked out, then a nil CheckOutStatus will be returned. The methods Valid() and String() can be called on a nil CheckOutStatus. ErrDocumentNotFound is returned if the document does not exist.
func (*CheckOutStatus) String ¶
func (s *CheckOutStatus) String() string
String implements the fmt.Stringer interface.
func (*CheckOutStatus) Valid ¶
func (s *CheckOutStatus) Valid() bool
type Conn ¶
type Conn interface { // DocumentExists returns true if a document with the passed docID exists in DocumentExists(ctx context.Context, docID uu.ID) (exists bool, err error) // EnumDocumentIDs calls the passed callback with the ID of every document in the database EnumDocumentIDs(ctx context.Context, callback func(context.Context, uu.ID) error) error // EnumCompanyDocumentIDs calls the passed callback with the ID of every document of a company in the database EnumCompanyDocumentIDs(ctx context.Context, companyID uu.ID, callback func(context.Context, uu.ID) error) error // DocumentCompanyID returns the companyID for a docID DocumentCompanyID(ctx context.Context, docID uu.ID) (companyID uu.ID, err error) // SetDocumentCompanyID changes the companyID for a document SetDocumentCompanyID(ctx context.Context, docID, companyID uu.ID) error // DocumentVersions returns all version timestamps of a document in ascending order. // Returns nil and no error if the document does not exist or has no versions. DocumentVersions(ctx context.Context, docID uu.ID) ([]VersionTime, error) // LatestDocumentVersion returns the lates VersionTime of a document LatestDocumentVersion(ctx context.Context, docID uu.ID) (VersionTime, error) // DocumentVersionInfo returns the VersionInfo for a VersionTime DocumentVersionInfo(ctx context.Context, docID uu.ID, version VersionTime) (*VersionInfo, error) // LatestDocumentVersionInfo returns the VersionInfo for the latest document version LatestDocumentVersionInfo(ctx context.Context, docID uu.ID) (*VersionInfo, error) // DocumentVersionFileProvider returns a FileProvider for the files of a document version DocumentVersionFileProvider(ctx context.Context, docID uu.ID, version VersionTime) (FileProvider, error) // ReadDocumentVersionFile returns the contents of a file of a document version. // Wrapped ErrDocumentNotFound, ErrDocumentVersionNotFound, ErrDocumentFileNotFound // will be returned in case of such error conditions. ReadDocumentVersionFile(ctx context.Context, docID uu.ID, version VersionTime, filename string) (data []byte, err error) // DeleteDocument deletes all versions of a document // including its workspace directory if checked out. DeleteDocument(ctx context.Context, docID uu.ID) error // DeleteDocumentVersion deletes a version of a document that must not be checked out // and returns the left over versions. // If the version is the only version of the document, // then the document will be deleted and no leftVersions are returned. // Returns wrapped ErrDocumentNotFound, ErrDocumentVersionNotFound, ErrDocumentCheckedOut // in case of such error conditions. // DeleteDocumentVersion should not be used for normal docdb operations, // just to clean up mistakes or sync database states. DeleteDocumentVersion(ctx context.Context, docID uu.ID, version VersionTime) (leftVersions []VersionTime, err error) CreateDocument(ctx context.Context, companyID, docID, userID uu.ID, reason string, files []fs.FileReader) (*VersionInfo, error) AddDocumentVersion(ctx context.Context, docID, userID uu.ID, reason string, createVersion CreateVersionFunc, onNewVersion OnNewVersionFunc) error // RestoreDocument RestoreDocument(ctx context.Context, doc *HashedDocument, merge bool) error }
Conn is an interface for a docdb connection.
func NewConnWithError ¶
NewConnWithError returns a Conn where all methods return the passed error.
type CreateVersionFunc ¶
type CreateVersionFunc func(ctx context.Context, prevVersion VersionTime, prevFiles FileProvider) (writeFiles []fs.FileReader, removeFiles []string, newCompanyID *uu.ID, err error)
type DeprecatedConn ¶
type DeprecatedConn interface { Conn // DocumentCheckOutStatus returns the CheckOutStatus of a document. // If the document is not checked out, then a nil CheckOutStatus will be returned. // The methods Valid() and String() can be called on a nil CheckOutStatus. // ErrDocumentNotFound is returned if the document does not exist. DocumentCheckOutStatus(ctx context.Context, docID uu.ID) (*CheckOutStatus, error) // CheckedOutDocuments returns the CheckOutStatus of all checked out documents. CheckedOutDocuments(ctx context.Context) ([]*CheckOutStatus, error) // CheckOutNewDocument creates a new document for a company in checked out state. CheckOutNewDocument(ctx context.Context, docID, companyID, userID uu.ID, reason string) (status *CheckOutStatus, err error) // CheckOutDocument checks out a document for a user with a stated reason. // Returns ErrDocumentCheckedOut if the document is already checked out. CheckOutDocument(ctx context.Context, docID, userID uu.ID, reason string) (*CheckOutStatus, error) // CancelCheckOutDocument cancels a potential checkout. // No error is returned if the document was not checked out. // If the checkout was created by CheckOutNewDocument, // then the new document is deleted without leaving any history // and the returned lastVersion.IsNull() is true. CancelCheckOutDocument(ctx context.Context, docID uu.ID) (wasCheckedOut bool, lastVersion VersionTime, err error) // CheckInDocument checks in a checked out document // and returns the VersionInfo for the newly created version. CheckInDocument(ctx context.Context, docID uu.ID) (*VersionInfo, error) // CheckedOutDocumentDir returns a fs.File for the directory // where a document would be checked out. CheckedOutDocumentDir(docID uu.ID) fs.File }
DeprecatedConn has check-out, check-in and checkout directory methods. It is deprecated and will be removed in the future. Use the Conn interface instead.
type ErrDocumentAlreadyExists ¶
type ErrDocumentAlreadyExists struct {
// contains filtered or unexported fields
}
func NewErrDocumentAlreadyExists ¶
func NewErrDocumentAlreadyExists(docID uu.ID) ErrDocumentAlreadyExists
func (ErrDocumentAlreadyExists) Error ¶
func (e ErrDocumentAlreadyExists) Error() string
type ErrDocumentChanged ¶
type ErrDocumentChanged struct {
// contains filtered or unexported fields
}
func NewErrDocumentChanged ¶
func NewErrDocumentChanged(docID uu.ID, version VersionTime) ErrDocumentChanged
func (ErrDocumentChanged) Error ¶
func (e ErrDocumentChanged) Error() string
type ErrDocumentCheckedOut ¶
type ErrDocumentCheckedOut struct {
// contains filtered or unexported fields
}
func NewErrDocumentCheckedOut ¶
func NewErrDocumentCheckedOut(status *CheckOutStatus) ErrDocumentCheckedOut
func (ErrDocumentCheckedOut) CheckOutReason ¶
func (e ErrDocumentCheckedOut) CheckOutReason() string
func (ErrDocumentCheckedOut) CheckOutUserID ¶
func (e ErrDocumentCheckedOut) CheckOutUserID() uu.ID
func (ErrDocumentCheckedOut) Error ¶
func (e ErrDocumentCheckedOut) Error() string
type ErrDocumentFileNotFound ¶
type ErrDocumentFileNotFound struct {
// contains filtered or unexported fields
}
func NewErrDocumentFileNotFound ¶
func NewErrDocumentFileNotFound(docID uu.ID, filename string) ErrDocumentFileNotFound
func (ErrDocumentFileNotFound) DocID ¶
func (e ErrDocumentFileNotFound) DocID() uu.ID
func (ErrDocumentFileNotFound) Error ¶
func (e ErrDocumentFileNotFound) Error() string
func (ErrDocumentFileNotFound) Filename ¶
func (e ErrDocumentFileNotFound) Filename() string
func (ErrDocumentFileNotFound) Is ¶
func (ErrDocumentFileNotFound) Is(target error) bool
type ErrDocumentHasNoCommitedVersion ¶
type ErrDocumentHasNoCommitedVersion struct {
// contains filtered or unexported fields
}
func NewErrDocumentHasNoCommitedVersion ¶
func NewErrDocumentHasNoCommitedVersion(docID uu.ID) ErrDocumentHasNoCommitedVersion
func (ErrDocumentHasNoCommitedVersion) Error ¶
func (e ErrDocumentHasNoCommitedVersion) Error() string
type ErrDocumentNotCheckedOut ¶
type ErrDocumentNotCheckedOut struct {
// contains filtered or unexported fields
}
func NewErrDocumentNotCheckedOut ¶
func NewErrDocumentNotCheckedOut(docID uu.ID) ErrDocumentNotCheckedOut
func (ErrDocumentNotCheckedOut) Error ¶
func (e ErrDocumentNotCheckedOut) Error() string
type ErrDocumentNotFound ¶
type ErrDocumentNotFound struct {
// contains filtered or unexported fields
}
func NewErrDocumentNotFound ¶
func NewErrDocumentNotFound(docID uu.ID) ErrDocumentNotFound
func (ErrDocumentNotFound) DocID ¶
func (e ErrDocumentNotFound) DocID() uu.ID
func (ErrDocumentNotFound) Error ¶
func (e ErrDocumentNotFound) Error() string
func (ErrDocumentNotFound) Is ¶
func (ErrDocumentNotFound) Is(target error) bool
type ErrDocumentVersionNotFound ¶
type ErrDocumentVersionNotFound struct {
// contains filtered or unexported fields
}
func NewErrDocumentVersionNotFound ¶
func NewErrDocumentVersionNotFound(docID uu.ID, version VersionTime) ErrDocumentVersionNotFound
func (ErrDocumentVersionNotFound) DocID ¶
func (e ErrDocumentVersionNotFound) DocID() uu.ID
func (ErrDocumentVersionNotFound) Error ¶
func (e ErrDocumentVersionNotFound) Error() string
func (ErrDocumentVersionNotFound) Is ¶
func (ErrDocumentVersionNotFound) Is(target error) bool
func (ErrDocumentVersionNotFound) Version ¶
func (e ErrDocumentVersionNotFound) Version() VersionTime
type ErrVersionAlreadyExists ¶
type ErrVersionAlreadyExists struct {
// contains filtered or unexported fields
}
func NewErrVersionAlreadyExists ¶
func NewErrVersionAlreadyExists(docID uu.ID, version VersionTime) ErrVersionAlreadyExists
func (ErrVersionAlreadyExists) Error ¶
func (e ErrVersionAlreadyExists) Error() string
type FileProvider ¶
type FileProvider interface { HasFile(filename string) (bool, error) ListFiles(ctx context.Context) (filenames []string, err error) ReadFile(ctx context.Context, filename string) ([]byte, error) }
FileProvider is an interface for read access to named files
func CheckedOutDocumentFileProvider ¶
func CheckedOutDocumentFileProvider(docID uu.ID) (p FileProvider, err error)
CheckedOutDocumentFileProvider returns a FileProvider for the directory where a document would be checked out.
func DirFileProvider ¶
func DirFileProvider(dir fs.File) FileProvider
DirFileProvider returns a FileProvider for a fs.File directory
func DocumentVersionFileProvider ¶
func DocumentVersionFileProvider(ctx context.Context, docID uu.ID, version VersionTime) (p FileProvider, err error)
DocumentVersionFileProvider returns a FileProvider for the files of a document version
func ExtFileProvider ¶
func ExtFileProvider(base FileProvider, extFiles ...fs.FileReader) FileProvider
ExtFileProvider returns a FileProvider that extends a base FileProvider with additional files that will be returned before the files of the base FileProvider.
func RemoveFileProvider ¶
func RemoveFileProvider(base FileProvider, removeFilenames ...string) FileProvider
RemoveFileProvider returns a FileProvider that wraps a base FileProvider and does not return files with the passed removeFilenames.
type HashedDocument ¶
type HashedDocument struct { ID uu.ID CompanyID uu.ID HashedFiles map[string][]byte Versions map[VersionTime]*HashedVersion }
func ReadHashedDocument ¶
func (*HashedDocument) VersionInfo ¶
func (doc *HashedDocument) VersionInfo(versionTime VersionTime) *VersionInfo
func (*HashedDocument) VersionTimes ¶
func (doc *HashedDocument) VersionTimes() []VersionTime
type HashedVersion ¶
type MockFileProvider ¶
type MockFileProvider struct { HasFileMock func(filename string) (bool, error) ListFilesMock func(ctx context.Context) (filenames []string, err error) ReadFileMock func(ctx context.Context, filename string) ([]byte, error) }
func (*MockFileProvider) HasFile ¶
func (fp *MockFileProvider) HasFile(filename string) (bool, error)
type OnNewVersionFunc ¶
type OnNewVersionFunc func(ctx context.Context, versionInfo *VersionInfo) error
type VersionInfo ¶
type VersionInfo struct { CompanyID uu.ID DocID uu.ID Version VersionTime PrevVersion VersionTime CommitUserID uu.ID CommitReason string Files map[string]FileInfo AddedFiles []string RemovedFiles []string ModifiedFiles []string }
func CheckInDocument ¶
CheckInDocument checks in a checked out document and returns the VersionInfo for the newly created version.
func CreateDocument ¶
func DocumentFileReader ¶
func DocumentFileReader(ctx context.Context, docID uu.ID, filename string) (fileReader fs.FileReader, versionInfo *VersionInfo, err error)
DocumentFileReader returns a fs.FileReader for a file of the latest document version. Wrapped ErrDocumentNotFound, ErrDocumentHasNoCommitedVersion, ErrDocumentFileNotFound will be returned in case of such error conditions.
func DocumentVersionInfo ¶
func DocumentVersionInfo(ctx context.Context, docID uu.ID, version VersionTime) (info *VersionInfo, err error)
DocumentVersionInfo returns the VersionInfo for a VersionTime
func LatestDocumentVersionInfo ¶
LatestDocumentVersionInfo returns the VersionInfo for the latest document version
func NewVersionInfo ¶
func NewVersionInfo(companyID, docID uu.ID, version, prevVersion VersionTime, commitUserID uu.ID, commitReason string, versionDir, prevVersionDir fs.File, ignoreFiles ...string) (versionInfo *VersionInfo, err error)
NewVersionInfo uses the files from versionDir. When prevVersionDir is "" then all files are added to the AddedFiles slice, else the according diff slices RemovedFiles and ModidfiedFiles will also be filled. Files in versionDir and prevVersionDir with names from ignoreFiles will be ignored. The versionInfo file slices will be sorted.
func ReadDocumentFile ¶
func ReadDocumentFile(ctx context.Context, docID uu.ID, filename string) (data []byte, versionInfo *VersionInfo, err error)
ReadDocumentFile reads a file of the latest document version
func ReadVersionInfoJSON ¶
func ReadVersionInfoJSON(file fs.File, writeFixedVersion bool) (versionInfo *VersionInfo, err error)
func (*VersionInfo) EqualFiles ¶
func (vi *VersionInfo) EqualFiles(other *VersionInfo) bool
func (*VersionInfo) String ¶
func (vi *VersionInfo) String() string
type VersionTime ¶
VersionTime of a document. VersionTime implements the database/sql.Scanner and database/sql/driver.Valuer interfaces and will treat a zero VersionTime value as SQL NULL value.
func CancelCheckOutDocument ¶
func CancelCheckOutDocument(ctx context.Context, docID uu.ID) (wasCheckedOut bool, lastVersion VersionTime, err error)
CancelCheckOutDocument cancels a potential checkout. No error is returned if the document was not checked out. If the checkout was created by CheckOutNewDocument, then the new document is deleted without leaving any history and the returned lastVersion.IsNull() is true.
func DeleteDocumentVersion ¶
func DeleteDocumentVersion(ctx context.Context, docID uu.ID, version VersionTime) (leftVersions []VersionTime, err error)
DeleteDocumentVersion deletes a version of a document that must not be checked out and returns the left over versions. If the version is the only version of the document, then the document will be deleted and no leftVersions are returned. Returns wrapped ErrDocumentNotFound, ErrDocumentVersionNotFound, ErrDocumentCheckedOut in case of such error conditions. DeleteDocumentVersion should not be used for normal docdb operations, just to clean up mistakes or sync database states.
func DocumentVersions ¶
DocumentVersions returns all version timestamps of a document in ascending order. Returns nil and no error if the document does not exist or has no versions.
func LatestDocumentVersion ¶
LatestDocumentVersion returns the lates VersionTime of a document
func MustVersionTimeFromString ¶
func MustVersionTimeFromString(str string) VersionTime
MustVersionTimeFromString parses a string as VersionTime. The strings "", "null", "NULL" will be parsed as null VersionTime. Any error causes a panic.
func NewVersionTime ¶
func NewVersionTime(ctx context.Context) VersionTime
NewVersionTime returns the timestamp for a new version. If the passed context was created with ContextWithVersionTime then the version from the context is returned else the current time.
func SubstituteDeletedDocumentVersion ¶
func SubstituteDeletedDocumentVersion(ctx context.Context, docID uu.ID, version VersionTime) (validVersion VersionTime, err error)
SubstituteDeletedDocumentVersion will substitue the passed version with the next existing version it does not exist anymore. Will return ErrDocumentHasNoCommitedVersion if there is no other commited version for the document.
func VersionTimeFrom ¶
func VersionTimeFrom(t time.Time) VersionTime
VersionTimeFrom returns a VersionTime for the given time translated to UTC and truncated to milliseconds
func VersionTimeFromString ¶
func VersionTimeFromString(str string) (VersionTime, error)
VersionTimeFromString parses a string as VersionTime. The strings "", "null", "NULL" will be parsed as null VersionTime.
func (VersionTime) After ¶
func (v VersionTime) After(other VersionTime) bool
func (VersionTime) Before ¶
func (v VersionTime) Before(other VersionTime) bool
func (VersionTime) Compare ¶
func (v VersionTime) Compare(r VersionTime) int
Compare compares the time instant v.Time with r.Time. If v is before r, it returns -1; if v is after r, it returns +1; if they're the same, it returns 0.
func (VersionTime) Equal ¶
func (v VersionTime) Equal(other VersionTime) bool
func (VersionTime) IsNotNull ¶
func (v VersionTime) IsNotNull() bool
func (VersionTime) IsNull ¶
func (v VersionTime) IsNull() bool
func (VersionTime) MarshalText ¶
func (v VersionTime) MarshalText() (text []byte, err error)
MarshalText implements the encoding.TextMarshaler interface
func (VersionTime) NullableTime ¶
func (v VersionTime) NullableTime() nullable.Time
NullableTime returns the version time as nullable.Time
func (VersionTime) PrettyPrint ¶
func (v VersionTime) PrettyPrint(w io.Writer)
PrettyPrint implements the pretty.Printable interface
func (*VersionTime) Scan ¶
func (v *VersionTime) Scan(value any) error
Scan implements the database/sql.Scanner interface.
func (*VersionTime) SetNull ¶
func (v *VersionTime) SetNull()
func (VersionTime) String ¶
func (v VersionTime) String() string
String implements the fmt.Stringer interface.
func (*VersionTime) UnmarshalText ¶
func (v *VersionTime) UnmarshalText(text []byte) error
UnmarshalText implements the encoding.TextUnmarshaler interface