Skip to content

Commit 0af1cfa

Browse files
committed
feat: add inferadb-ledger-proto crate
1 parent 16967af commit 0af1cfa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1181
-1012
lines changed

.github/workflows/canary.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
- 'crates/types/**'
6262
- 'crates/store/**'
6363
- 'crates/state/**'
64+
- 'crates/proto/**'
6465
- 'crates/raft/**'
6566
- 'crates/sdk/**'
6667
- 'proto/**'
@@ -459,7 +460,7 @@ jobs:
459460
460461
# Update inter-crate dependency versions to use exact prerelease version
461462
# (semver ranges like ^0.1.0 don't match prereleases)
462-
for crate in inferadb-ledger-types inferadb-ledger-store inferadb-ledger-state inferadb-ledger-raft inferadb-ledger-sdk; do
463+
for crate in inferadb-ledger-types inferadb-ledger-store inferadb-ledger-state inferadb-ledger-proto inferadb-ledger-raft inferadb-ledger-sdk; do
463464
sed -i "s/\(${crate} = { version = \)\"[^\"]*\"/\1\"=${CRATE_VERSION}\"/" Cargo.toml
464465
done
465466
@@ -474,7 +475,7 @@ jobs:
474475
env:
475476
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
476477
run: |
477-
for crate in inferadb-ledger-types inferadb-ledger-store inferadb-ledger-state inferadb-ledger-raft inferadb-ledger-sdk; do
478+
for crate in inferadb-ledger-types inferadb-ledger-store inferadb-ledger-state inferadb-ledger-proto inferadb-ledger-raft inferadb-ledger-sdk; do
478479
echo "Publishing ${crate}..."
479480
cargo publish -p "${crate}" --token "$CARGO_REGISTRY_TOKEN" --allow-dirty
480481
echo "Waiting for crates.io to index..."

.github/workflows/nightly.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
104104
# Check if library files changed since last nightly
105105
LIBRARY_CHANGES=$(git diff --name-only "$LAST_SHA"..HEAD -- \
106-
crates/types crates/store crates/state crates/raft crates/sdk \
106+
crates/types crates/store crates/state crates/proto crates/raft crates/sdk \
107107
proto Cargo.toml Cargo.lock | wc -l)
108108
109109
if [ "$LIBRARY_CHANGES" -gt 0 ]; then
@@ -536,7 +536,7 @@ jobs:
536536
537537
# Update inter-crate dependency versions to use exact prerelease version
538538
# (semver ranges like ^0.1.0 don't match prereleases)
539-
for crate in inferadb-ledger-types inferadb-ledger-store inferadb-ledger-state inferadb-ledger-raft inferadb-ledger-sdk; do
539+
for crate in inferadb-ledger-types inferadb-ledger-store inferadb-ledger-state inferadb-ledger-proto inferadb-ledger-raft inferadb-ledger-sdk; do
540540
sed -i "s/\(${crate} = { version = \)\"[^\"]*\"/\1\"=${VERSION}\"/" Cargo.toml
541541
done
542542
@@ -551,7 +551,7 @@ jobs:
551551
env:
552552
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
553553
run: |
554-
for crate in inferadb-ledger-types inferadb-ledger-store inferadb-ledger-state inferadb-ledger-raft inferadb-ledger-sdk; do
554+
for crate in inferadb-ledger-types inferadb-ledger-store inferadb-ledger-state inferadb-ledger-proto inferadb-ledger-raft inferadb-ledger-sdk; do
555555
echo "Publishing ${crate}..."
556556
cargo publish -p "${crate}" --token "$CARGO_REGISTRY_TOKEN" --allow-dirty
557557
echo "Waiting for crates.io to index..."

.github/workflows/release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,14 @@ jobs:
494494
echo "Waiting for crates.io to index..."
495495
sleep 45
496496
497+
- name: Publish inferadb-ledger-proto
498+
env:
499+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
500+
run: |
501+
cargo publish -p inferadb-ledger-proto --token "$CARGO_REGISTRY_TOKEN" --allow-dirty
502+
echo "Waiting for crates.io to index..."
503+
sleep 45
504+
497505
- name: Publish inferadb-ledger-raft
498506
env:
499507
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

Cargo.lock

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"crates/types",
55
"crates/store",
66
"crates/state",
7+
"crates/proto",
78
"crates/raft",
89
"crates/server",
910
"crates/sdk",
@@ -124,6 +125,7 @@ async-stream = "0.3"
124125
inferadb-ledger-types = { version = "0.1.0", path = "crates/types" }
125126
inferadb-ledger-store = { version = "0.1.0", path = "crates/store" }
126127
inferadb-ledger-state = { version = "0.1.0", path = "crates/state" }
128+
inferadb-ledger-proto = { version = "0.1.0", path = "crates/proto" }
127129
inferadb-ledger-raft = { version = "0.1.0", path = "crates/raft" }
128130
inferadb-ledger-server = { path = "crates/server" }
129131
inferadb-ledger-sdk = { version = "0.1.0", path = "crates/sdk" }

crates/proto/Cargo.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[package]
2+
name = "inferadb-ledger-proto"
3+
description = "Protobuf types and conversions for InferaDB Ledger"
4+
version.workspace = true
5+
edition.workspace = true
6+
rust-version.workspace = true
7+
license.workspace = true
8+
repository.workspace = true
9+
authors.workspace = true
10+
documentation = "https://docs.rs/inferadb-ledger-proto"
11+
readme = "README.md"
12+
keywords = ["protobuf", "grpc", "ledger", "types"]
13+
categories = ["encoding", "network-programming"]
14+
15+
[dependencies]
16+
# Internal
17+
inferadb-ledger-types.workspace = true
18+
19+
# gRPC / proto
20+
tonic.workspace = true
21+
tonic-prost.workspace = true
22+
prost.workspace = true
23+
prost-types.workspace = true
24+
25+
# Raft (for Vote type in conversions)
26+
openraft.workspace = true
27+
28+
# Error handling (for tonic::Status in TryFrom)
29+
snafu.workspace = true
30+
31+
[build-dependencies]
32+
tonic-build.workspace = true
33+
tonic-prost-build.workspace = true
34+
35+
[dev-dependencies]
36+
inferadb-ledger-test-utils.workspace = true
37+
proptest.workspace = true
38+
uuid.workspace = true
39+
chrono.workspace = true
40+
41+
[lints]
42+
workspace = true
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Build script for inferadb-ledger-raft.
1+
//! Build script for inferadb-ledger-proto.
22
//!
33
//! Compiles protobuf definitions into Rust code using tonic-prost-build.
44
//! When publishing to crates.io, proto files aren't available, so we use
Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,28 @@
1212
//! # Usage
1313
//!
1414
//! ```ignore
15-
//! use crate::proto_convert::*;
15+
//! use inferadb_ledger_proto::convert;
1616
//!
1717
//! // Domain to proto
1818
//! let proto_op: proto::Operation = domain_op.into();
1919
//!
20-
//! // Proto to domain
20+
//! // Proto to domain
2121
//! let domain_vote: Vote<LedgerNodeId> = proto_vote.into();
2222
//! ```
23+
//!
24+
//! # Note
25+
//!
26+
//! The `NamespaceStatus` conversion lives in the `raft` crate because it
27+
//! depends on `inferadb_ledger_state::system::NamespaceStatus`.
2328
24-
use inferadb_ledger_types::merkle::MerkleProof as InternalMerkleProof;
29+
use inferadb_ledger_types::{
30+
BlockRetentionMode, BlockRetentionPolicy, LedgerNodeId,
31+
merkle::MerkleProof as InternalMerkleProof,
32+
};
2533
use openraft::Vote;
2634
use tonic::Status;
2735

28-
use crate::{
29-
proto,
30-
types::{BlockRetentionMode, BlockRetentionPolicy, LedgerNodeId},
31-
};
36+
use crate::proto;
3237

3338
// =============================================================================
3439
// Vote conversions (openraft::Vote <-> proto::RaftVote)
@@ -237,24 +242,6 @@ impl TryFrom<proto::Operation> for inferadb_ledger_types::Operation {
237242
}
238243
}
239244

240-
// =============================================================================
241-
// NamespaceStatus conversions
242-
// =============================================================================
243-
244-
impl From<inferadb_ledger_state::system::NamespaceStatus> for proto::NamespaceStatus {
245-
fn from(status: inferadb_ledger_state::system::NamespaceStatus) -> Self {
246-
use inferadb_ledger_state::system::NamespaceStatus;
247-
248-
match status {
249-
NamespaceStatus::Active => proto::NamespaceStatus::Active,
250-
NamespaceStatus::Migrating => proto::NamespaceStatus::Migrating,
251-
NamespaceStatus::Suspended => proto::NamespaceStatus::Suspended,
252-
NamespaceStatus::Deleting => proto::NamespaceStatus::Deleting,
253-
NamespaceStatus::Deleted => proto::NamespaceStatus::Deleted,
254-
}
255-
}
256-
}
257-
258245
// =============================================================================
259246
// Entity conversions (inferadb_ledger_types::Entity -> proto::Entity)
260247
// =============================================================================
@@ -956,36 +943,6 @@ mod tests {
956943
);
957944
}
958945

959-
// -------------------------------------------------------------------------
960-
// NamespaceStatus conversion tests
961-
// -------------------------------------------------------------------------
962-
963-
#[test]
964-
fn test_namespace_status_all_variants() {
965-
use inferadb_ledger_state::system::NamespaceStatus;
966-
967-
assert_eq!(
968-
proto::NamespaceStatus::from(NamespaceStatus::Active),
969-
proto::NamespaceStatus::Active
970-
);
971-
assert_eq!(
972-
proto::NamespaceStatus::from(NamespaceStatus::Migrating),
973-
proto::NamespaceStatus::Migrating
974-
);
975-
assert_eq!(
976-
proto::NamespaceStatus::from(NamespaceStatus::Suspended),
977-
proto::NamespaceStatus::Suspended
978-
);
979-
assert_eq!(
980-
proto::NamespaceStatus::from(NamespaceStatus::Deleting),
981-
proto::NamespaceStatus::Deleting
982-
);
983-
assert_eq!(
984-
proto::NamespaceStatus::from(NamespaceStatus::Deleted),
985-
proto::NamespaceStatus::Deleted
986-
);
987-
}
988-
989946
// -------------------------------------------------------------------------
990947
// Entity conversion tests
991948
// -------------------------------------------------------------------------

crates/proto/src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//! Protobuf types and conversions for InferaDB Ledger.
2+
//!
3+
//! This crate provides:
4+
//! - Generated protobuf types and gRPC service traits ([`proto`])
5+
//! - Bidirectional conversions between domain types and proto types ([`convert`])
6+
//!
7+
//! # Architecture
8+
//!
9+
//! Extracted from the `raft` crate so that consumers needing only wire-format
10+
//! types (e.g., the SDK) can avoid pulling in Raft consensus internals.
11+
12+
#![deny(unsafe_code)]
13+
// gRPC services return tonic::Status (176 bytes) - standard practice for gRPC error handling
14+
#![allow(clippy::result_large_err)]
15+
16+
/// Generated protobuf types and service traits.
17+
pub mod proto {
18+
#![allow(clippy::all)]
19+
#![allow(missing_docs)]
20+
21+
// Use pre-generated code when proto files aren't available (crates.io)
22+
#[cfg(use_pregenerated_proto)]
23+
include!("generated/ledger.v1.rs");
24+
25+
// Use build-time generated code in development
26+
#[cfg(not(use_pregenerated_proto))]
27+
tonic::include_proto!("ledger.v1");
28+
}
29+
30+
pub mod convert;

0 commit comments

Comments
 (0)