Documentation
¶
Overview ¶
Package dsutil holds helpers shared by the docstore backends: argument validation, canonicalisation of document bodies and JSON encoding.
Index ¶
- Constants
- func Canonical(data map[string]any) (map[string]any, error)
- func CheckKey(site, collection, id string) error
- func CheckNamespace(site, collection string) error
- func CheckWrite(site, collection, id, actor string) (string, error)
- func CleanActor(actor string) (string, error)
- func DecodeData(b []byte) (map[string]any, error)
- func Marshal(data map[string]any) ([]byte, error)
- func MergePatch(data, patch map[string]any) (map[string]any, []byte, error)
- func PreparePatch(patch map[string]any) (map[string]any, error)
- func PrepareWrite(data map[string]any) (map[string]any, []byte, error)
- func Unmarshal(b []byte, v any) error
Constants ¶
const MaxSystemIDBytes = 1024
MaxSystemIDBytes bounds document ids in system collections.
Variables ¶
This section is empty.
Functions ¶
func Canonical ¶
Canonical returns a deep copy of a document body with reserved keys removed and every value converted to canonical JSON types (map[string]any, []any, float64, string, bool, nil). Values of other Go types are converted through encoding/json. Strings and keys are cleaned with docstore.CleanString and numbers with docstore.CleanNumber, and bodies nested deeper than docstore.MaxNestingDepth are rejected, so that every backend stores (and returns) exactly the same values; violations yield ErrInvalid. Nil values are kept (null data, or deletion markers in a patch).
func CheckKey ¶
CheckKey validates site, collection and document id. Ids in user collections must satisfy docstore.ValidateID. System collections (names starting with "_") are written by Backyard itself with ids such as e-mail addresses (the "_system/_users" cache), so there any valid UTF-8 id of 1 to MaxSystemIDBytes bytes without control characters is accepted.
func CheckNamespace ¶
CheckNamespace validates a site and collection (user or system collection).
func CheckWrite ¶
CheckWrite validates the key of a write like CheckKey and returns the actor in canonical form (see CleanActor).
func CleanActor ¶
CleanActor canonicalises the actor recorded in created_by/updated_by like any other stored string (see docstore.CleanString).
func DecodeData ¶
DecodeData decodes a stored document body. Empty input yields an empty map.
func Marshal ¶
Marshal encodes a canonical document body as compact JSON (HTML characters are not escaped).
func MergePatch ¶
MergePatch applies a canonical patch to stored data (shallow merge; nil deletes) and returns the merged body and its encoding.
func PreparePatch ¶
PreparePatch canonicalises an Update patch (reserved keys dropped, nil values kept as deletion markers).
func PrepareWrite ¶
PrepareWrite turns a Create/Put body into the stored form: reserved keys ("id", "_meta") are dropped, the body is deep-copied into canonical JSON types (map[string]any, []any, float64, string, bool, nil) and encoded.
Types ¶
This section is empty.