Skip to content

Commit f34863a

Browse files
committed
ref(clients): Rename "put" to "insert"
1 parent 96c9f32 commit f34863a

File tree

14 files changed

+53
-53
lines changed

14 files changed

+53
-53
lines changed

clients/python/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ session = client.session(
5353
# The following operations will raise an exception on failure
5454

5555
# Write an object and metadata
56-
object_key = session.put(
56+
object_key = session.insert(
5757
b"Hello, world!",
5858
# You can pass in your own identifier for the object to decide where to store the file.
5959
# Otherwise, Objectstore will pick an identifier and return it.
60-
# A put request to an existing identifier overwrites the contents and metadata.
60+
# An insert request to an existing identifier overwrites the contents and metadata.
6161
# id="hello",
6262
metadata={"key": "value"},
6363
# Overrides the default defined at the Usecase level

clients/python/src/objectstore_client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def _make_url(self, key: str | None, full: bool = False) -> str:
212212
else:
213213
return f"{base_path}"
214214

215-
def put(
215+
def insert(
216216
self,
217217
contents: bytes | IO[bytes],
218218
key: str | None = None,

clients/python/src/objectstore_client/metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Metadata:
3535
time_created: datetime | None
3636
"""
3737
Timestamp indicating when the object was created or the last time it was replaced.
38-
This means that a PUT request to an existing object causes this value to be bumped.
38+
This means that an insert request to an existing object causes this value to be bumped.
3939
This field is computed by the server, it cannot be set by clients.
4040
"""
4141

clients/python/tests/test_e2e.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ def test_full_cycle(server_url: str) -> None:
103103

104104
session = client.session(test_usecase, org=42, project=1337)
105105

106-
object_key = session.put(b"test data")
106+
object_key = session.insert(b"test data")
107107
assert object_key is not None
108108

109109
retrieved = session.get(object_key)
110110
assert retrieved.payload.read() == b"test data"
111111
assert retrieved.metadata.time_created is not None
112112

113-
new_key = session.put(b"new data", key=object_key)
113+
new_key = session.insert(b"new data", key=object_key)
114114
assert new_key == object_key
115115
retrieved = session.get(object_key)
116116
assert retrieved.payload.read() == b"new data"
@@ -135,7 +135,7 @@ def test_full_cycle_uncompressed(server_url: str) -> None:
135135
compressor = zstandard.ZstdCompressor()
136136
compressed_data = compressor.compress(data)
137137

138-
object_key = session.put(compressed_data, compression="none")
138+
object_key = session.insert(compressed_data, compression="none")
139139
assert object_key is not None
140140

141141
retrieved = session.get(object_key)

clients/rust/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ async fn example_basic() -> Result<()> {
1717
.for_project(42, 1337)
1818
.session(&client)?;
1919

20-
let response = session.put("Hello, world!")
20+
let response = session.insert("Hello, world!")
2121
.send()
2222
.await
23-
.expect("put to succeed");
23+
.expect("insert to succeed");
2424

2525
let object = session
2626
.get(&response.key)
@@ -68,7 +68,7 @@ async fn example() -> Result<()> {
6868
let session = OBJECTSTORE_CLIENT
6969
.session(ATTACHMENTS.for_project(42, 1337))?;
7070

71-
let response = session.put("Hello, world!").send().await?;
71+
let response = session.insert("Hello, world!").send().await?;
7272

7373
let object = session
7474
.get(&response.key)

clients/rust/src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub(crate) struct ClientInner {
356356
///
357357
/// let session = client.session(usecase.for_project(12345, 1337))?;
358358
///
359-
/// let response = session.put("hello world").send().await?;
359+
/// let response = session.insert("hello world").send().await?;
360360
///
361361
/// # Ok(())
362362
/// # }
@@ -406,7 +406,7 @@ pub struct Session {
406406
pub(crate) client: Arc<ClientInner>,
407407
}
408408

409-
/// The type of [`Stream`](futures_util::Stream) to be used for a PUT request.
409+
/// The type of [`Stream`](futures_util::Stream) to be used for an insert request.
410410
pub type ClientStream = BoxStream<'static, io::Result<Bytes>>;
411411

412412
impl Session {

clients/rust/src/get.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl fmt::Debug for GetResponse {
4545
}
4646

4747
impl Session {
48-
/// Requests the object with the given `key`.
48+
/// Retrieves the object with the given `key`.
4949
pub fn get(&self, key: &str) -> GetBuilder {
5050
GetBuilder {
5151
session: self.clone(),
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,70 +15,70 @@ pub use objectstore_types::{Compression, ExpirationPolicy};
1515

1616
use crate::{ClientStream, Session};
1717

18-
/// The response returned from the service after uploading an object.
18+
/// The response returned from the service after inserting an object.
1919
#[derive(Debug, Deserialize)]
20-
pub struct PutResponse {
20+
pub struct InsertResponse {
2121
/// The key of the object, as stored.
2222
pub key: String,
2323
}
2424

25-
pub(crate) enum PutBody {
25+
pub(crate) enum InsertBody {
2626
Buffer(Bytes),
2727
Stream(ClientStream),
2828
}
2929

30-
impl fmt::Debug for PutBody {
30+
impl fmt::Debug for InsertBody {
3131
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32-
f.debug_tuple("PutBody").finish_non_exhaustive()
32+
f.debug_tuple("InsertBody").finish_non_exhaustive()
3333
}
3434
}
3535

3636
impl Session {
37-
fn put_body(&self, body: PutBody) -> PutBuilder {
37+
fn insert_body(&self, body: InsertBody) -> InsertBuilder {
3838
let metadata = Metadata {
3939
expiration_policy: self.scope.usecase().expiration_policy(),
4040
compression: Some(self.scope.usecase().compression()),
4141
..Default::default()
4242
};
4343

44-
PutBuilder {
44+
InsertBuilder {
4545
session: self.clone(),
4646
metadata,
4747
key: None,
4848
body,
4949
}
5050
}
5151

52-
/// Creates a PUT request for a [`Bytes`]-like type.
53-
pub fn put(&self, body: impl Into<Bytes>) -> PutBuilder {
54-
self.put_body(PutBody::Buffer(body.into()))
52+
/// Creates or replaces an object using a [`Bytes`]-like payload.
53+
pub fn insert(&self, body: impl Into<Bytes>) -> InsertBuilder {
54+
self.insert_body(InsertBody::Buffer(body.into()))
5555
}
5656

57-
/// Creates a PUT request with a stream.
58-
pub fn put_stream(&self, body: ClientStream) -> PutBuilder {
59-
self.put_body(PutBody::Stream(body))
57+
/// Creates or replaces an object using a streaming payload.
58+
pub fn insert_stream(&self, body: ClientStream) -> InsertBuilder {
59+
self.insert_body(InsertBody::Stream(body))
6060
}
6161

62-
/// Creates a PUT request with an [`AsyncRead`] type.
63-
pub fn put_read<R>(&self, body: R) -> PutBuilder
62+
/// Creates or replaces an object using an [`AsyncRead`] payload.
63+
pub fn insert_read<R>(&self, body: R) -> InsertBuilder
6464
where
6565
R: AsyncRead + Send + Sync + 'static,
6666
{
6767
let stream = ReaderStream::new(body).boxed();
68-
self.put_body(PutBody::Stream(stream))
68+
self.insert_body(InsertBody::Stream(stream))
6969
}
7070
}
7171

72-
/// A PUT request builder.
72+
/// An insert request builder.
7373
#[derive(Debug)]
74-
pub struct PutBuilder {
74+
pub struct InsertBuilder {
7575
session: Session,
7676
metadata: Metadata,
7777
key: Option<String>,
78-
body: PutBody,
78+
body: InsertBody,
7979
}
8080

81-
impl PutBuilder {
81+
impl InsertBuilder {
8282
/// Sets an explicit object key.
8383
///
8484
/// If a key is specified, the object will be stored under that key. Otherwise, the Objectstore
@@ -135,9 +135,9 @@ impl PutBuilder {
135135
// TODO: instead of a separate `send` method, it would be nice to just implement `IntoFuture`.
136136
// However, `IntoFuture` needs to define the resulting future as an associated type,
137137
// and "impl trait in associated type position" is not yet stable :-(
138-
impl PutBuilder {
139-
/// Sends the built PUT request to the upstream service.
140-
pub async fn send(self) -> crate::Result<PutResponse> {
138+
impl InsertBuilder {
139+
/// Sends the built insert request to the upstream service.
140+
pub async fn send(self) -> crate::Result<InsertResponse> {
141141
let method = match self.key {
142142
Some(_) => reqwest::Method::PUT,
143143
None => reqwest::Method::POST,
@@ -148,20 +148,20 @@ impl PutBuilder {
148148
.request(method, self.key.as_deref().unwrap_or_default());
149149

150150
let body = match (self.metadata.compression, self.body) {
151-
(Some(Compression::Zstd), PutBody::Buffer(bytes)) => {
151+
(Some(Compression::Zstd), InsertBody::Buffer(bytes)) => {
152152
let cursor = Cursor::new(bytes);
153153
let encoder = ZstdEncoder::new(cursor);
154154
let stream = ReaderStream::new(encoder);
155155
Body::wrap_stream(stream)
156156
}
157-
(Some(Compression::Zstd), PutBody::Stream(stream)) => {
157+
(Some(Compression::Zstd), InsertBody::Stream(stream)) => {
158158
let stream = StreamReader::new(stream);
159159
let encoder = ZstdEncoder::new(stream);
160160
let stream = ReaderStream::new(encoder);
161161
Body::wrap_stream(stream)
162162
}
163-
(None, PutBody::Buffer(bytes)) => bytes.into(),
164-
(None, PutBody::Stream(stream)) => Body::wrap_stream(stream),
163+
(None, InsertBody::Buffer(bytes)) => bytes.into(),
164+
(None, InsertBody::Stream(stream)) => Body::wrap_stream(stream),
165165
// _ => todo!("compression algorithms other than `zstd` are currently not supported"),
166166
};
167167

clients/rust/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod client;
66
mod delete;
77
mod error;
88
mod get;
9-
mod put;
9+
mod insert;
1010
pub mod utils;
1111

1212
pub use objectstore_types::{Compression, ExpirationPolicy};
@@ -15,7 +15,7 @@ pub use client::*;
1515
pub use delete::*;
1616
pub use error::*;
1717
pub use get::*;
18-
pub use put::*;
18+
pub use insert::*;
1919

2020
#[cfg(test)]
2121
mod tests;

clients/rust/src/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async fn stores_uncompressed() {
2222
let body = "oh hai!";
2323

2424
let stored_id = session
25-
.put(body)
25+
.insert(body)
2626
.compression(None)
2727
.send()
2828
.await
@@ -46,7 +46,7 @@ async fn uses_zstd_by_default() {
4646
let session = client.session(usecase.for_organization(12345)).unwrap();
4747

4848
let body = "oh hai!";
49-
let stored_id = session.put(body).send().await.unwrap().key;
49+
let stored_id = session.insert(body).send().await.unwrap().key;
5050

5151
// when the user indicates that it can deal with zstd, it gets zstd
5252
let GetResponse { metadata, stream } = session
@@ -79,7 +79,7 @@ async fn deletes_stores_stuff() {
7979
let session = client.session(usecase.for_project(12345, 1337)).unwrap();
8080

8181
let body = "oh hai!";
82-
let stored_id = session.put(body).send().await.unwrap().key;
82+
let stored_id = session.insert(body).send().await.unwrap().key;
8383

8484
session.delete(&stored_id).send().await.unwrap();
8585

@@ -97,7 +97,7 @@ async fn stores_under_given_key() {
9797

9898
let body = "oh hai!";
9999
let stored_id = session
100-
.put(body)
100+
.insert(body)
101101
.key("test-key123!!")
102102
.send()
103103
.await
@@ -115,9 +115,9 @@ async fn overwrites_existing_key() {
115115
let usecase = Usecase::new("usecase");
116116
let session = client.session(usecase.for_project(12345, 1337)).unwrap();
117117

118-
let stored_id = session.put("initial body").send().await.unwrap().key;
118+
let stored_id = session.insert("initial body").send().await.unwrap().key;
119119
let overwritten_id = session
120-
.put("new body")
120+
.insert("new body")
121121
.key(&stored_id)
122122
.send()
123123
.await

0 commit comments

Comments
 (0)