mirror of
https://github.com/hanzoai/cloud.git
synced 2026-11-23 21:15:04 +00:00
The code is the private build's sdk/ with the module path swapped and the hostnames, private issue refs and incident prose taken out. Its self-contained tests come with it; the framework's own tests need the private test kits and stay behind. Builds and vets in this module; needs luxfi/kms v1.12.26. Claude-Session: https://claude.ai/code/session_015XYKLn69gF4x75RWePpDBV
38 lines
864 B
Go
38 lines
864 B
Go
package dialect
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
"io"
|
|
)
|
|
|
|
// Document refuses a JSON document a JSON column would: bytes that are not UTF-8, a
|
|
// string that holds a NUL (which a document spells \u0000), or text that is not JSON.
|
|
// PostgreSQL's JSONB refuses all three at the statement and SQLite's TEXT keeps them,
|
|
// so a store calls it where a document comes in, and the error is the same on both
|
|
// engines. The error never carries the document.
|
|
func Document(raw []byte) error {
|
|
if err := Text(string(raw)); err != nil {
|
|
return err
|
|
}
|
|
if !json.Valid(raw) {
|
|
return ErrText
|
|
}
|
|
dec := json.NewDecoder(bytes.NewReader(raw))
|
|
for {
|
|
tok, err := dec.Token()
|
|
if errors.Is(err, io.EOF) {
|
|
return nil
|
|
}
|
|
if err != nil {
|
|
return ErrText
|
|
}
|
|
if s, ok := tok.(string); ok {
|
|
if err := Text(s); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|