The delivery repository's contracts and SDK live under modules/ as mesh-delivery-contracts and mesh-delivery-sdk, their Go module paths renamed to match the folders (the TypeScript names already did), and every importer in mesh-delivery, mesh-catalog, mesh-host, mesh-tools and mesh-sdk follows in the same group: a design as it should be, one path per module, checked by the group's check building every importer. Builds: design 47 G §427, §88 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package takein
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/kept"
|
|
"git.novox.be/novox/mesh-sdk/go/keys"
|
|
)
|
|
|
|
// TakenState is the indexer's state `taken`: one key per repository (trunk.RepositoryKey), the last merge it took in.
|
|
const TakenState = "taken"
|
|
|
|
// Taken is the value of a taken key: the repository, the merge commit the indexer last took in (applied its message
|
|
// whole), and when.
|
|
type Taken struct {
|
|
V int `json:"v"`
|
|
Repository string `json:"repository"`
|
|
Merge string `json:"merge"`
|
|
At time.Time `json:"at"`
|
|
}
|
|
|
|
// EncodeTaken is t as JSON at Version; a value with no repository or merge is refused.
|
|
func EncodeTaken(t Taken) ([]byte, error) {
|
|
if t.Repository == "" || t.Merge == "" {
|
|
return nil, fmt.Errorf("takein: a taken value names its repository and merge")
|
|
}
|
|
t.V = keys.Version
|
|
return json.Marshal(t)
|
|
}
|
|
|
|
// DecodeTaken reads a taken value; it refuses an unknown version (ErrUnknownVersion) and one with no merge.
|
|
func DecodeTaken(data []byte) (Taken, error) {
|
|
var t Taken
|
|
if err := kept.Decode(data, &t); err != nil {
|
|
return t, err
|
|
}
|
|
if t.Repository == "" || t.Merge == "" {
|
|
return t, fmt.Errorf("takein: a taken value names no repository or merge")
|
|
}
|
|
return t, nil
|
|
}
|