mirror of
https://github.com/aljazceru/pubky-core.git
synced 2026-01-10 09:44:20 +01:00
feat(js): add list shallow option
This commit is contained in:
@@ -243,3 +243,71 @@ test("list", async (t) => {
|
||||
);
|
||||
}
|
||||
})
|
||||
|
||||
test('list shallow', async (t) => {
|
||||
const client = PubkyClient.testnet();
|
||||
|
||||
const keypair = Keypair.random()
|
||||
const publicKey = keypair.publicKey()
|
||||
const pubky = publicKey.z32()
|
||||
|
||||
const homeserver = PublicKey.from('8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo')
|
||||
await client.signup(keypair, homeserver)
|
||||
|
||||
|
||||
|
||||
let urls = [
|
||||
`pubky://${pubky}/pub/a.com/a.txt`,
|
||||
`pubky://${pubky}/pub/example.com/a.txt`,
|
||||
`pubky://${pubky}/pub/example.com/b.txt`,
|
||||
`pubky://${pubky}/pub/example.com/c.txt`,
|
||||
`pubky://${pubky}/pub/example.com/d.txt`,
|
||||
`pubky://${pubky}/pub/example.con/d.txt`,
|
||||
`pubky://${pubky}/pub/example.con`,
|
||||
`pubky://${pubky}/pub/file`,
|
||||
`pubky://${pubky}/pub/file2`,
|
||||
`pubky://${pubky}/pub/z.com/a.txt`,
|
||||
]
|
||||
|
||||
for (let url of urls) {
|
||||
await client.put(url, Buffer.from(""));
|
||||
}
|
||||
|
||||
let url = `pubky://${pubky}/pub/`;
|
||||
|
||||
{
|
||||
let list = await client.list(url, null, false, null, true);
|
||||
|
||||
t.deepEqual(
|
||||
list,
|
||||
[
|
||||
`pubky://${pubky}/pub/a.com/`,
|
||||
`pubky://${pubky}/pub/example.com/`,
|
||||
`pubky://${pubky}/pub/example.con`,
|
||||
`pubky://${pubky}/pub/example.con/`,
|
||||
`pubky://${pubky}/pub/file`,
|
||||
`pubky://${pubky}/pub/file2`,
|
||||
`pubky://${pubky}/pub/z.com/`,
|
||||
],
|
||||
"normal list shallow"
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
let list = await client.list(url, null, true, null, true);
|
||||
|
||||
t.deepEqual(
|
||||
list,
|
||||
[
|
||||
`pubky://${pubky}/pub/z.com/`,
|
||||
`pubky://${pubky}/pub/file2`,
|
||||
`pubky://${pubky}/pub/file`,
|
||||
`pubky://${pubky}/pub/example.con/`,
|
||||
`pubky://${pubky}/pub/example.con`,
|
||||
`pubky://${pubky}/pub/example.com/`,
|
||||
`pubky://${pubky}/pub/a.com/`,
|
||||
],
|
||||
"normal list shallow"
|
||||
);
|
||||
}
|
||||
})
|
||||
|
||||
@@ -27,8 +27,8 @@ impl<'a> ListBuilder<'a> {
|
||||
}
|
||||
|
||||
/// Set the `reverse` option.
|
||||
pub fn reverse(mut self) -> Self {
|
||||
self.reverse = true;
|
||||
pub fn reverse(mut self, reverse: bool) -> Self {
|
||||
self.reverse = reverse;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ impl<'a> ListBuilder<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn shallow(mut self) -> Self {
|
||||
self.shallow = true;
|
||||
pub fn shallow(mut self, shallow: bool) -> Self {
|
||||
self.shallow = shallow;
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -319,7 +319,7 @@ mod tests {
|
||||
let list = client
|
||||
.list(url.as_str())
|
||||
.unwrap()
|
||||
.reverse()
|
||||
.reverse(true)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -340,7 +340,7 @@ mod tests {
|
||||
let list = client
|
||||
.list(url.as_str())
|
||||
.unwrap()
|
||||
.reverse()
|
||||
.reverse(true)
|
||||
.limit(2)
|
||||
.send()
|
||||
.await
|
||||
@@ -360,7 +360,7 @@ mod tests {
|
||||
let list = client
|
||||
.list(url.as_str())
|
||||
.unwrap()
|
||||
.reverse()
|
||||
.reverse(true)
|
||||
.limit(2)
|
||||
.cursor("d.txt")
|
||||
.send()
|
||||
@@ -412,7 +412,7 @@ mod tests {
|
||||
let list = client
|
||||
.list(url.as_str())
|
||||
.unwrap()
|
||||
.shallow()
|
||||
.shallow(true)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -436,8 +436,8 @@ mod tests {
|
||||
let list = client
|
||||
.list(url.as_str())
|
||||
.unwrap()
|
||||
.shallow()
|
||||
.reverse()
|
||||
.shallow(true)
|
||||
.reverse(true)
|
||||
.send()
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
@@ -165,6 +165,7 @@ impl PubkyClient {
|
||||
cursor: Option<String>,
|
||||
reverse: Option<bool>,
|
||||
limit: Option<u16>,
|
||||
shallow: Option<bool>,
|
||||
) -> Result<Array, JsValue> {
|
||||
// TODO: try later to return Vec<String> from async function.
|
||||
|
||||
@@ -174,6 +175,7 @@ impl PubkyClient {
|
||||
.reverse(reverse.unwrap_or(false))
|
||||
.limit(limit.unwrap_or(u16::MAX))
|
||||
.cursor(&cursor)
|
||||
.shallow(shallow.unwrap_or(false))
|
||||
.send()
|
||||
.await
|
||||
.map(|urls| {
|
||||
@@ -191,6 +193,7 @@ impl PubkyClient {
|
||||
self.inner_list(url)?
|
||||
.reverse(reverse.unwrap_or(false))
|
||||
.limit(limit.unwrap_or(u16::MAX))
|
||||
.shallow(shallow.unwrap_or(false))
|
||||
.send()
|
||||
.await
|
||||
.map(|urls| {
|
||||
|
||||
Reference in New Issue
Block a user