diff options
Diffstat (limited to 'src/api/store.rs')
| -rw-r--r-- | src/api/store.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/api/store.rs b/src/api/store.rs index 48bdafc..2b21c83 100644 --- a/src/api/store.rs +++ b/src/api/store.rs @@ -580,9 +580,10 @@ const TYPE_HEADER: &str = "x-continuum-type"; /// JSON, text as a string, or a scalar of a type of its own (`typed::from_native`). struct WriteBody { value: Val, - /// Plain JSON or text, whose values keep the types of what they are written over - /// where they can (`store::Writing::sticky`). - sticky: bool, + /// Which of its values keep the types of what they are written over + /// (`store::Sticky`): plain JSON's and text's where they can, typed JSON's numbers + /// over floats. + sticky: store::Sticky, /// How timestamps are written in it (`timestamp-format`). timestamps: TimestampFormat, } @@ -600,19 +601,19 @@ fn body_value(headers: &HeaderMap, body: &Bytes) -> Result<WriteBody, ApiError> }; let timestamps = json_form_of(params)?.timestamps; let (value, sticky) = match media.as_str() { - "application/json" => (Val::from_json(&json()?).map_err(bad)?, true), + "application/json" => (Val::from_json(&json()?).map_err(bad)?, store::Sticky::All), typed::TYPED_JSON => ( Val::from_typed_json(&json()?, timestamps).map_err(bad)?, - false, + store::Sticky::Floats, ), typed::TEXT => ( String::from_utf8(body.to_vec()) .map(|text| Val::Scalar(automerge::ScalarValue::Str(text.into()))) .map_err(|_| bad("not UTF-8".to_owned()))?, - true, + store::Sticky::All, ), media => match typed::from_native(media, params, body) { - Some(Ok(scalar)) => (Val::Scalar(scalar), false), + Some(Ok(scalar)) => (Val::Scalar(scalar), store::Sticky::No), Some(Err(error)) => return Err(bad(error)), None => return Err(StatusCode::UNSUPPORTED_MEDIA_TYPE.into()), }, |
