Skip to content

Commit

Permalink
record checkpoint to index wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lann committed Jul 21, 2023
1 parent b0a2c18 commit 75a702a
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 190 deletions.
18 changes: 4 additions & 14 deletions crates/api/src/v1/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::{borrow::Cow, collections::HashMap};
use thiserror::Error;
use warg_crypto::hash::AnyHash;
use warg_protocol::{
registry::{LogId, MapCheckpoint, PackageId, RecordId},
ProtoEnvelopeBody, SerdeEnvelope,
registry::{LogId, PackageId, RecordId},
ProtoEnvelopeBody,
};

/// Represents the supported kinds of content sources.
Expand Down Expand Up @@ -45,16 +45,6 @@ pub struct PackageRecord {
}

impl PackageRecord {
/// Gets the checkpoint of the record.
///
/// Returns `None` if the record hasn't been published yet.
pub fn checkpoint(&self) -> Option<&SerdeEnvelope<MapCheckpoint>> {
match &self.state {
PackageRecordState::Published { checkpoint, .. } => Some(checkpoint),
_ => None,
}
}

/// Gets the missing content digests of the record.
pub fn missing_content(&self) -> &[AnyHash] {
match &self.state {
Expand Down Expand Up @@ -89,10 +79,10 @@ pub enum PackageRecordState {
},
/// The package record was successfully published to the log.
Published {
/// The checkpoint that the record was included in.
checkpoint: SerdeEnvelope<MapCheckpoint>,
/// The envelope of the package record.
record: ProtoEnvelopeBody,
/// The index of the record in the registry log.
registry_log_index: u32,
/// The content sources of the record.
content_sources: HashMap<AnyHash, Vec<ContentSource>>,
},
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/src/hash/static.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{ByteVisitor, VisitBytes};

use super::{Output, SupportedDigest};

#[derive(PartialOrd, Ord)]
#[derive(Default, PartialOrd, Ord)]
pub struct Hash<D: SupportedDigest> {
pub(crate) digest: Output<D>,
}
Expand Down
4 changes: 4 additions & 0 deletions crates/protocol/src/serde_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ impl<Contents> SerdeEnvelope<Contents> {
})
}

pub fn into_contents(self) -> Contents {
self.contents
}

pub fn key_id(&self) -> &signing::KeyID {
&self.key_id
}
Expand Down
6 changes: 3 additions & 3 deletions crates/server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -746,9 +746,9 @@ components:
description: The state of the package record.
enum: [published]
example: published
checkpoint:
"$ref": "#/components/schemas/SignedMapCheckpoint"
description: The checkpoint of the record.
registryLogIndex:
type: number
description: The index of the record in the registry log.
record:
"$ref": "#/components/schemas/EnvelopeBody"
description: The package record.
Expand Down
2 changes: 1 addition & 1 deletion crates/server/src/api/v1/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ async fn get_record(
id: record_id,
state: PackageRecordState::Published {
record: record.envelope.into(),
checkpoint: record.checkpoint.unwrap(),
registry_log_index: record.registry_log_index.unwrap(),
content_sources,
},
}))
Expand Down
Loading

0 comments on commit 75a702a

Please sign in to comment.