-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
157 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
[package] | ||
name = "fishy" | ||
version = "0.1.0" | ||
authors = [ | ||
"adz <[email protected]>", | ||
"sandreae <[email protected]>", | ||
] | ||
authors = ["adz <[email protected]>", "sandreae <[email protected]>"] | ||
edition = "2021" | ||
description = "Create, manage and deploy p2panda schemas" | ||
repository = "https://github.com/p2panda/fishy" | ||
license = "AGPL-3.0-or-later" | ||
readme = "README.md" | ||
|
||
[[bin]] | ||
name = "fishy" | ||
path = "src/main.rs" | ||
|
||
[lib] | ||
name = "fishy" | ||
path = "src/lib/lib.rs" | ||
|
||
[profile.release] | ||
strip = true | ||
opt-level = "z" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
mod current; | ||
mod diff; | ||
mod executor; | ||
mod previous; | ||
mod write; | ||
|
||
pub use current::get_current_schemas; | ||
pub use diff::{get_diff, FieldTypeDiff}; | ||
pub use executor::{execute_plan, Plan}; | ||
pub use previous::get_previous_schemas; | ||
pub use previous::PreviousSchemas; | ||
pub use write::write_to_lock_file; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
use anyhow::{anyhow, bail, Result}; | ||
use gql_client::Client as GQLClient; | ||
use p2panda_rs::entry::decode::decode_entry; | ||
use p2panda_rs::entry::traits::AsEntry; | ||
use p2panda_rs::entry::{LogId, SeqNum}; | ||
use p2panda_rs::hash::Hash; | ||
use serde::Deserialize; | ||
|
||
use crate::lock_file::Commit; | ||
|
||
#[derive(Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
#[allow(dead_code)] | ||
struct NextArguments { | ||
log_id: LogId, | ||
seq_num: SeqNum, | ||
skiplink: Option<Hash>, | ||
backlink: Option<Hash>, | ||
} | ||
|
||
/// GraphQL response for `nextArgs` query. | ||
#[derive(Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
struct NextArgsResponse { | ||
next_args: NextArguments, | ||
} | ||
|
||
#[derive(Deserialize, Debug)] | ||
#[serde(rename_all = "camelCase")] | ||
#[allow(dead_code)] | ||
struct PublishResponse { | ||
publish: NextArguments, | ||
} | ||
|
||
pub struct Client(GQLClient); | ||
|
||
impl Client { | ||
pub fn new(endpoint: &str) -> Self { | ||
Self(GQLClient::new(endpoint)) | ||
} | ||
|
||
pub async fn publish(&self, commit: Commit) -> Result<bool> { | ||
let entry = decode_entry(&commit.entry).unwrap(); | ||
|
||
let query = format!( | ||
r#" | ||
{{ | ||
nextArgs(publicKey: "{}", viewId: "{}") {{ | ||
logId | ||
seqNum | ||
skiplink | ||
backlink | ||
}} | ||
}} | ||
"#, | ||
entry.public_key(), | ||
commit.entry_hash, | ||
); | ||
|
||
let response = self.0.query_unwrap::<NextArgsResponse>(&query).await; | ||
|
||
if let Ok(result) = response { | ||
let args = result.next_args; | ||
|
||
if entry.log_id() != &args.log_id { | ||
bail!("Inconsistency between local commits and node detected"); | ||
} | ||
|
||
// Check if node already knows about this commit | ||
if entry.seq_num() < &args.seq_num { | ||
// Skip this one | ||
return Ok(false); | ||
} | ||
} | ||
|
||
let query = format!( | ||
r#" | ||
mutation Publish {{ | ||
publish(entry: "{}", operation: "{}") {{ | ||
logId | ||
seqNum | ||
skiplink | ||
backlink | ||
}} | ||
}} | ||
"#, | ||
commit.entry, commit.operation | ||
); | ||
|
||
self.0 | ||
.query_unwrap::<PublishResponse>(&query) | ||
.await | ||
.map_err(|err| anyhow!("GraphQL request to node failed: {err}"))?; | ||
|
||
return Ok(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
pub mod build; | ||
mod client; | ||
pub mod lock_file; | ||
pub mod schema_file; | ||
pub mod utils; | ||
|
||
pub use client::Client; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
pub mod files; | ||
pub mod key_pair; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ | |
|
||
mod commands; | ||
mod constants; | ||
mod lock_file; | ||
mod schema_file; | ||
mod utils; | ||
|
||
use std::path::PathBuf; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
pub mod files; | ||
pub mod key_pair; | ||
pub mod terminal; | ||
pub mod print; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters