#![allow(
missing_docs,
clippy::doc_markdown,
clippy::struct_excessive_bools,
clippy::derive_partial_eq_without_eq,
clippy::large_enum_variant
)]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Bounty {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub basis: Option<crate::generated::dev::idiolect::defs::Basis>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub constraints: Option<Vec<BountyConstraints>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub eligibility: Option<Vec<BountyEligibility>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub fulfillment: Option<idiolect_records::AtUri>,
pub occurred_at: idiolect_records::Datetime,
pub requester: idiolect_records::Did,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub reward: Option<BountyReward>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub status: Option<BountyStatus>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub status_vocab: Option<crate::generated::dev::idiolect::defs::VocabRef>,
pub wants: BountyWants,
}
impl crate::Record for Bounty {
const NSID: &'static str = "dev.idiolect.bounty";
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConstraintConformance {
pub kind: ConstraintConformanceKind,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub kind_vocab: Option<crate::generated::dev::idiolect::defs::VocabRef>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub property: Option<crate::generated::dev::idiolect::defs::LensProperty>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConstraintDeadline {
pub deadline: idiolect_records::Datetime,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub grace_seconds: Option<i64>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConstraintDependency {
pub bounty: idiolect_records::AtUri,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConstraintLicense {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub allow: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub deny: Option<Vec<String>>,
pub spdx: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConstraintPerformance {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cmp: Option<ConstraintPerformanceCmp>,
pub metric: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sample_size: Option<i64>,
pub threshold: f64,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EligibilityAnd {}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EligibilityDid {
pub did: idiolect_records::Did,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EligibilityMember {
pub community: idiolect_records::AtUri,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EligibilityNot {}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EligibilityOr {}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EligibilityVerificationFor {
pub property: crate::generated::dev::idiolect::defs::LensProperty,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WantAdapter {
pub framework: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub version_range: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WantLens {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub bidirectional: Option<bool>,
pub source: crate::generated::dev::idiolect::defs::SchemaRef,
pub target: crate::generated::dev::idiolect::defs::SchemaRef,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct WantVerification {
pub kind: WantVerificationKind,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub kind_vocab: Option<crate::generated::dev::idiolect::defs::VocabRef>,
pub lens: crate::generated::dev::idiolect::defs::LensRef,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConstraintConformanceKind {
RoundtripTest,
PropertyTest,
FormalProof,
ConformanceTest,
StaticCheck,
ConvergencePreserving,
Other(String),
}
impl ConstraintConformanceKind {
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::RoundtripTest => "roundtrip-test",
Self::PropertyTest => "property-test",
Self::FormalProof => "formal-proof",
Self::ConformanceTest => "conformance-test",
Self::StaticCheck => "static-check",
Self::ConvergencePreserving => "convergence-preserving",
Self::Other(s) => s.as_str(),
}
}
#[must_use]
pub fn is_subsumed_by(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
ancestor: &str,
) -> bool {
vocab.is_subsumed_by(self.as_str(), ancestor)
}
#[must_use]
pub fn satisfies(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
relation: &str,
target: &str,
) -> bool {
if self.as_str() == target {
return true;
}
vocab
.walk_relation(self.as_str(), relation, false)
.iter()
.any(|n| n == target)
}
#[must_use]
pub fn translate_to<T: From<String>>(
&self,
src_vocab_uri: &str,
tgt_vocab_uri: &str,
registry: &idiolect_records::vocab::VocabRegistry,
) -> Option<T> {
registry
.translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
.map(T::from)
}
}
impl From<String> for ConstraintConformanceKind {
fn from(s: String) -> Self {
match s.as_str() {
"roundtrip-test" => Self::RoundtripTest,
"property-test" => Self::PropertyTest,
"formal-proof" => Self::FormalProof,
"conformance-test" => Self::ConformanceTest,
"static-check" => Self::StaticCheck,
"convergence-preserving" => Self::ConvergencePreserving,
_ => Self::Other(s),
}
}
}
impl From<&str> for ConstraintConformanceKind {
fn from(s: &str) -> Self {
match s {
"roundtrip-test" => Self::RoundtripTest,
"property-test" => Self::PropertyTest,
"formal-proof" => Self::FormalProof,
"conformance-test" => Self::ConformanceTest,
"static-check" => Self::StaticCheck,
"convergence-preserving" => Self::ConvergencePreserving,
_ => Self::Other(s.to_owned()),
}
}
}
impl serde::Serialize for ConstraintConformanceKind {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for ConstraintConformanceKind {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum ConstraintPerformanceCmp {
Lt,
Le,
Eq,
Ge,
Gt,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum WantVerificationKind {
RoundtripTest,
PropertyTest,
FormalProof,
ConformanceTest,
StaticCheck,
ConvergencePreserving,
Other(String),
}
impl WantVerificationKind {
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::RoundtripTest => "roundtrip-test",
Self::PropertyTest => "property-test",
Self::FormalProof => "formal-proof",
Self::ConformanceTest => "conformance-test",
Self::StaticCheck => "static-check",
Self::ConvergencePreserving => "convergence-preserving",
Self::Other(s) => s.as_str(),
}
}
#[must_use]
pub fn is_subsumed_by(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
ancestor: &str,
) -> bool {
vocab.is_subsumed_by(self.as_str(), ancestor)
}
#[must_use]
pub fn satisfies(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
relation: &str,
target: &str,
) -> bool {
if self.as_str() == target {
return true;
}
vocab
.walk_relation(self.as_str(), relation, false)
.iter()
.any(|n| n == target)
}
#[must_use]
pub fn translate_to<T: From<String>>(
&self,
src_vocab_uri: &str,
tgt_vocab_uri: &str,
registry: &idiolect_records::vocab::VocabRegistry,
) -> Option<T> {
registry
.translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
.map(T::from)
}
}
impl From<String> for WantVerificationKind {
fn from(s: String) -> Self {
match s.as_str() {
"roundtrip-test" => Self::RoundtripTest,
"property-test" => Self::PropertyTest,
"formal-proof" => Self::FormalProof,
"conformance-test" => Self::ConformanceTest,
"static-check" => Self::StaticCheck,
"convergence-preserving" => Self::ConvergencePreserving,
_ => Self::Other(s),
}
}
}
impl From<&str> for WantVerificationKind {
fn from(s: &str) -> Self {
match s {
"roundtrip-test" => Self::RoundtripTest,
"property-test" => Self::PropertyTest,
"formal-proof" => Self::FormalProof,
"conformance-test" => Self::ConformanceTest,
"static-check" => Self::StaticCheck,
"convergence-preserving" => Self::ConvergencePreserving,
_ => Self::Other(s.to_owned()),
}
}
}
impl serde::Serialize for WantVerificationKind {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for WantVerificationKind {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "$type")]
pub enum BountyConstraints {
#[serde(rename = "dev.idiolect.bounty#constraintPerformance")]
ConstraintPerformance(ConstraintPerformance),
#[serde(rename = "dev.idiolect.bounty#constraintConformance")]
ConstraintConformance(ConstraintConformance),
#[serde(rename = "dev.idiolect.bounty#constraintLicense")]
ConstraintLicense(ConstraintLicense),
#[serde(rename = "dev.idiolect.bounty#constraintDeadline")]
ConstraintDeadline(ConstraintDeadline),
#[serde(rename = "dev.idiolect.bounty#constraintDependency")]
ConstraintDependency(ConstraintDependency),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "$type")]
pub enum BountyEligibility {
#[serde(rename = "dev.idiolect.bounty#eligibilityMember")]
EligibilityMember(EligibilityMember),
#[serde(rename = "dev.idiolect.bounty#eligibilityVerificationFor")]
EligibilityVerificationFor(EligibilityVerificationFor),
#[serde(rename = "dev.idiolect.bounty#eligibilityDid")]
EligibilityDid(EligibilityDid),
#[serde(rename = "dev.idiolect.bounty#eligibilityAnd")]
EligibilityAnd(EligibilityAnd),
#[serde(rename = "dev.idiolect.bounty#eligibilityOr")]
EligibilityOr(EligibilityOr),
#[serde(rename = "dev.idiolect.bounty#eligibilityNot")]
EligibilityNot(EligibilityNot),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(tag = "$type")]
pub enum BountyWants {
#[serde(rename = "dev.idiolect.bounty#wantLens")]
WantLens(WantLens),
#[serde(rename = "dev.idiolect.bounty#wantVerification")]
WantVerification(WantVerification),
#[serde(rename = "dev.idiolect.bounty#wantAdapter")]
WantAdapter(WantAdapter),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum BountyStatus {
Open,
Claimed,
Fulfilled,
Withdrawn,
Other(String),
}
impl BountyStatus {
#[must_use]
pub fn as_str(&self) -> &str {
match self {
Self::Open => "open",
Self::Claimed => "claimed",
Self::Fulfilled => "fulfilled",
Self::Withdrawn => "withdrawn",
Self::Other(s) => s.as_str(),
}
}
#[must_use]
pub fn is_subsumed_by(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
ancestor: &str,
) -> bool {
vocab.is_subsumed_by(self.as_str(), ancestor)
}
#[must_use]
pub fn satisfies(
&self,
vocab: &idiolect_records::vocab::VocabGraph,
relation: &str,
target: &str,
) -> bool {
if self.as_str() == target {
return true;
}
vocab
.walk_relation(self.as_str(), relation, false)
.iter()
.any(|n| n == target)
}
#[must_use]
pub fn translate_to<T: From<String>>(
&self,
src_vocab_uri: &str,
tgt_vocab_uri: &str,
registry: &idiolect_records::vocab::VocabRegistry,
) -> Option<T> {
registry
.translate(src_vocab_uri, tgt_vocab_uri, self.as_str())
.map(T::from)
}
}
impl From<String> for BountyStatus {
fn from(s: String) -> Self {
match s.as_str() {
"open" => Self::Open,
"claimed" => Self::Claimed,
"fulfilled" => Self::Fulfilled,
"withdrawn" => Self::Withdrawn,
_ => Self::Other(s),
}
}
}
impl From<&str> for BountyStatus {
fn from(s: &str) -> Self {
match s {
"open" => Self::Open,
"claimed" => Self::Claimed,
"fulfilled" => Self::Fulfilled,
"withdrawn" => Self::Withdrawn,
_ => Self::Other(s.to_owned()),
}
}
}
impl serde::Serialize for BountyStatus {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for BountyStatus {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = String::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BountyReward {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub external_ref: Option<idiolect_records::Uri>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub summary: Option<String>,
}