mirror of
https://github.com/aljazceru/react-native-pubky.git
synced 2025-12-17 14:44:26 +01:00
feat: add list method
Adds list method. Adds put, get & list examples to README.md. Bump package version to 0.6.0.
This commit is contained in:
48
README.md
48
README.md
@@ -16,12 +16,13 @@ npm install @synonymdev/react-native-pubky
|
||||
- [x] [resolve](#resolve): Functionality to resolve content.
|
||||
- [x] [publishHttps](#publishHttps): Publish HTTPS records.
|
||||
- [x] [resolveHttps](#resolveHttps): Resolve HTTPS records.
|
||||
- [x] [put](#put): Upload a small payload to a given path.
|
||||
- [x] [get](#get): Download a small payload from a given path relative to a pubky author.
|
||||
- [x] [list](#list): Returns a list of Pubky URLs of the files in the path of the `url` provided.
|
||||
### Methods to be Implemented
|
||||
- [ ] signIn: Sign-in to a homeserver.
|
||||
- [ ] signUp: Sign-up to a homeserver and update Pkarr accordingly.
|
||||
- [ ] signOut: Sign-out from a homeserver.
|
||||
- [ ] put: Upload a small payload to a given path.
|
||||
- [ ] get: Download a small payload from a given path relative to a pubky author.
|
||||
|
||||
|
||||
## Usage
|
||||
@@ -110,6 +111,49 @@ if (resolveHttpsRes.isErr()) {
|
||||
console.log(resolveHttpsRes.value);
|
||||
```
|
||||
|
||||
### <a name="put"></a>put
|
||||
```js
|
||||
import { put } from '@synonymdev/react-native-pubky';
|
||||
|
||||
const putRes = await put(
|
||||
'url', // URL
|
||||
'content', // Content
|
||||
);
|
||||
if (putRes.isErr()) {
|
||||
console.log(putRes.error.message);
|
||||
return;
|
||||
}
|
||||
console.log(putRes.value);
|
||||
```
|
||||
|
||||
### <a name="get"></a>get
|
||||
```js
|
||||
import { get } from '@synonymdev/react-native-pubky';
|
||||
|
||||
const getRes = await get(
|
||||
'url' // URL
|
||||
);
|
||||
if (getRes.isErr()) {
|
||||
console.log(getRes.error.message);
|
||||
return;
|
||||
}
|
||||
console.log(getRes.value);
|
||||
```
|
||||
|
||||
### <a name="list"></a>list
|
||||
```js
|
||||
import { list } from '@synonymdev/react-native-pubky';
|
||||
|
||||
const listRes = await list(
|
||||
'url' // URL
|
||||
);
|
||||
if (listRes.isErr()) {
|
||||
console.log(listRes.error.message);
|
||||
return;
|
||||
}
|
||||
console.log(listRes.value);
|
||||
```
|
||||
|
||||
## Local Installation
|
||||
|
||||
1. Clone & npm install:
|
||||
|
||||
@@ -231,6 +231,25 @@ class PubkyModule(reactContext: ReactApplicationContext) :
|
||||
}
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
fun list(url: String, promise: Promise) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
try {
|
||||
val result = list(url)
|
||||
val array = Arguments.createArray().apply {
|
||||
result.forEach { pushString(it) }
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
promise.resolve(array)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
withContext(Dispatchers.Main) {
|
||||
promise.reject("Error", e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val NAME = "Pubky"
|
||||
}
|
||||
|
||||
@@ -389,6 +389,8 @@ internal interface _UniFFILib : Library {
|
||||
): RustBuffer.ByValue
|
||||
fun uniffi_pubkymobile_fn_func_get(`url`: RustBuffer.ByValue,
|
||||
): Pointer
|
||||
fun uniffi_pubkymobile_fn_func_list(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||
): RustBuffer.ByValue
|
||||
fun uniffi_pubkymobile_fn_func_parse_auth_url(`url`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||
): RustBuffer.ByValue
|
||||
fun uniffi_pubkymobile_fn_func_publish(`recordName`: RustBuffer.ByValue,`recordContent`: RustBuffer.ByValue,`secretKey`: RustBuffer.ByValue,_uniffi_out_err: RustCallStatus,
|
||||
@@ -525,6 +527,8 @@ internal interface _UniFFILib : Library {
|
||||
): Short
|
||||
fun uniffi_pubkymobile_checksum_func_get(
|
||||
): Short
|
||||
fun uniffi_pubkymobile_checksum_func_list(
|
||||
): Short
|
||||
fun uniffi_pubkymobile_checksum_func_parse_auth_url(
|
||||
): Short
|
||||
fun uniffi_pubkymobile_checksum_func_publish(
|
||||
@@ -566,6 +570,9 @@ private fun uniffiCheckApiChecksums(lib: _UniFFILib) {
|
||||
if (lib.uniffi_pubkymobile_checksum_func_get() != 5395.toShort()) {
|
||||
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||
}
|
||||
if (lib.uniffi_pubkymobile_checksum_func_list() != 8522.toShort()) {
|
||||
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||
}
|
||||
if (lib.uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088.toShort()) {
|
||||
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
|
||||
}
|
||||
@@ -749,6 +756,14 @@ suspend fun `get`(`url`: String) : List<String> {
|
||||
)
|
||||
}
|
||||
|
||||
fun `list`(`url`: String): List<String> {
|
||||
return FfiConverterSequenceString.lift(
|
||||
rustCall() { _status ->
|
||||
_UniFFILib.INSTANCE.uniffi_pubkymobile_fn_func_list(FfiConverterString.lower(`url`),_status)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
fun `parseAuthUrl`(`url`: String): List<String> {
|
||||
return FfiConverterSequenceString.lift(
|
||||
rustCall() { _status ->
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1237,7 +1237,7 @@ PODS:
|
||||
- ReactCommon/turbomodule/bridging
|
||||
- ReactCommon/turbomodule/core
|
||||
- Yoga
|
||||
- react-native-pubky (0.5.0):
|
||||
- react-native-pubky (0.6.0):
|
||||
- DoubleConversion
|
||||
- glog
|
||||
- hermes-engine
|
||||
@@ -1757,7 +1757,7 @@ SPEC CHECKSUMS:
|
||||
React-logger: 4072f39df335ca443932e0ccece41fbeb5ca8404
|
||||
React-Mapbuffer: 714f2fae68edcabfc332b754e9fbaa8cfc68fdd4
|
||||
React-microtasksnativemodule: 4943ad8f99be8ccf5a63329fa7d269816609df9e
|
||||
react-native-pubky: 6eb6e656a9c7bfc4310556c142db5861a2fe5b7f
|
||||
react-native-pubky: 0240de4239550981499983fa50a1aa6fc200823d
|
||||
React-nativeconfig: 4a9543185905fe41014c06776bf126083795aed9
|
||||
React-NativeModulesApple: 0506da59fc40d2e1e6e12a233db5e81c46face27
|
||||
React-perflogger: 3bbb82f18e9ac29a1a6931568e99d6305ef4403b
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
get,
|
||||
resolveHttps,
|
||||
publishHttps,
|
||||
list,
|
||||
} from '@synonymdev/react-native-pubky';
|
||||
|
||||
export default function App() {
|
||||
@@ -207,6 +208,24 @@ export default function App() {
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
<Button
|
||||
title={'list'}
|
||||
onPress={async (): Promise<void> => {
|
||||
try {
|
||||
const res = await list(
|
||||
'url' // URL
|
||||
);
|
||||
if (res.isErr()) {
|
||||
console.log(res.error.message);
|
||||
return;
|
||||
}
|
||||
console.log(res.value);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,8 @@ RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key
|
||||
);
|
||||
void* _Nonnull uniffi_pubkymobile_fn_func_get(RustBuffer url
|
||||
);
|
||||
RustBuffer uniffi_pubkymobile_fn_func_list(RustBuffer url, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
RustBuffer uniffi_pubkymobile_fn_func_parse_auth_url(RustBuffer url, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
RustBuffer uniffi_pubkymobile_fn_func_publish(RustBuffer record_name, RustBuffer record_content, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
||||
@@ -204,6 +206,9 @@ uint16_t uniffi_pubkymobile_checksum_func_auth(void
|
||||
);
|
||||
uint16_t uniffi_pubkymobile_checksum_func_get(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_pubkymobile_checksum_func_list(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_pubkymobile_checksum_func_parse_auth_url(void
|
||||
|
||||
|
||||
Binary file not shown.
@@ -67,6 +67,8 @@ RustBuffer uniffi_pubkymobile_fn_func_auth(RustBuffer url, RustBuffer secret_key
|
||||
);
|
||||
void* _Nonnull uniffi_pubkymobile_fn_func_get(RustBuffer url
|
||||
);
|
||||
RustBuffer uniffi_pubkymobile_fn_func_list(RustBuffer url, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
RustBuffer uniffi_pubkymobile_fn_func_parse_auth_url(RustBuffer url, RustCallStatus *_Nonnull out_status
|
||||
);
|
||||
RustBuffer uniffi_pubkymobile_fn_func_publish(RustBuffer record_name, RustBuffer record_content, RustBuffer secret_key, RustCallStatus *_Nonnull out_status
|
||||
@@ -204,6 +206,9 @@ uint16_t uniffi_pubkymobile_checksum_func_auth(void
|
||||
);
|
||||
uint16_t uniffi_pubkymobile_checksum_func_get(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_pubkymobile_checksum_func_list(void
|
||||
|
||||
);
|
||||
uint16_t uniffi_pubkymobile_checksum_func_parse_auth_url(void
|
||||
|
||||
|
||||
Binary file not shown.
@@ -53,6 +53,10 @@ RCT_EXTERN_METHOD(resolveHttps:(NSString *)publicKey
|
||||
withResolver:(RCTPromiseResolveBlock)resolve
|
||||
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||
|
||||
RCT_EXTERN_METHOD(list:(NSString *)url
|
||||
withResolver:(RCTPromiseResolveBlock)resolve
|
||||
withRejecter:(RCTPromiseRejectBlock)reject)
|
||||
|
||||
+ (BOOL)requiresMainQueueSetup
|
||||
{
|
||||
return NO;
|
||||
|
||||
@@ -133,4 +133,16 @@ class Pubky: NSObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc(list:withResolver:withRejecter:)
|
||||
func list(_ url: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
||||
Task {
|
||||
do {
|
||||
let result = try await react_native_pubky.list(url: url)
|
||||
resolve(result)
|
||||
} catch {
|
||||
reject("list Error", "Failed to list", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,6 +447,15 @@ public func get(url: String) async -> [String] {
|
||||
|
||||
|
||||
|
||||
public func list(url: String) -> [String] {
|
||||
return try! FfiConverterSequenceString.lift(
|
||||
try! rustCall() {
|
||||
uniffi_pubkymobile_fn_func_list(
|
||||
FfiConverterString.lower(url),$0)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
public func parseAuthUrl(url: String) -> [String] {
|
||||
return try! FfiConverterSequenceString.lift(
|
||||
try! rustCall() {
|
||||
@@ -591,6 +600,9 @@ private var initializationResult: InitializationResult {
|
||||
if (uniffi_pubkymobile_checksum_func_get() != 5395) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_pubkymobile_checksum_func_list() != 8522) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_pubkymobile_checksum_func_parse_auth_url() != 29088) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@synonymdev/react-native-pubky",
|
||||
"version": "0.5.0",
|
||||
"version": "0.6.0",
|
||||
"description": "React Native Implementation of Pubky",
|
||||
"source": "./src/index.tsx",
|
||||
"main": "./lib/commonjs/index.js",
|
||||
|
||||
@@ -365,6 +365,33 @@ pub fn publish(record_name: String, record_content: String, secret_key: String)
|
||||
}
|
||||
}
|
||||
|
||||
#[uniffi::export]
|
||||
pub fn list(url: String) -> Vec<String> {
|
||||
let runtime = TOKIO_RUNTIME.clone();
|
||||
runtime.block_on(async {
|
||||
let client = PUBKY_CLIENT.clone();
|
||||
let parsed_url = match Url::parse(&url) {
|
||||
Ok(url) => url,
|
||||
Err(_) => return create_response_vector(true, "Failed to parse URL".to_string()),
|
||||
};
|
||||
let list_builder = match client.list(parsed_url) {
|
||||
Ok(list) => list,
|
||||
Err(error) => return create_response_vector(true, format!("Failed to list: {}", error)),
|
||||
};
|
||||
// Execute the non-Send part synchronously
|
||||
let send_future = list_builder.send();
|
||||
let send_res = match send_future.await {
|
||||
Ok(res) => res,
|
||||
Err(error) => return create_response_vector(true, format!("Failed to send list request: {}", error))
|
||||
};
|
||||
let json_string = match serde_json::to_string(&send_res) {
|
||||
Ok(json) => json,
|
||||
Err(error) => return create_response_vector(true, format!("Failed to serialize JSON: {}", error)),
|
||||
};
|
||||
create_response_vector(false, json_string)
|
||||
})
|
||||
}
|
||||
|
||||
#[uniffi::export]
|
||||
pub fn auth(url: String, secret_key: String) -> Vec<String> {
|
||||
let runtime = TOKIO_RUNTIME.clone();
|
||||
|
||||
@@ -212,3 +212,15 @@ export async function resolveHttps(
|
||||
return err(JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
export async function list(url: string): Promise<Result<string[]>> {
|
||||
try {
|
||||
const res = await Pubky.list(url);
|
||||
if (res[0] === 'error') {
|
||||
return err(res[1]);
|
||||
}
|
||||
return ok(JSON.parse(res[1]));
|
||||
} catch (e) {
|
||||
return err(JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user