Add Rust CultMesh catalog factories
This commit is contained in:
parent
6229167992
commit
0308167c3e
5 changed files with 98 additions and 13 deletions
|
|
@ -56,10 +56,11 @@ surface:
|
|||
- shard catalog request/response messages
|
||||
- the canonical `ghostlight.agent-state` document payload schema
|
||||
|
||||
Use `builtin_schema_registry()` when you want the standard catalog, or register
|
||||
your own closed-world schema set with `CultNetSchemaRegistry`. Discovery stays
|
||||
explicit on purpose: peers advertise only the contracts they were compiled to
|
||||
understand, the same way CultCache only consumes the document types you
|
||||
Use `builtin_schema_registry()` or `CultMesh::create_builtin_schema_registry()`
|
||||
when you want the standard catalog, or register your own closed-world schema set
|
||||
with `CultNetSchemaRegistry` / `CultMesh::create_schema_registry()`. Discovery
|
||||
stays explicit on purpose: peers advertise only the contracts they were compiled
|
||||
to understand, the same way CultCache only consumes the document types you
|
||||
registered instead of pretending polymorphism is a public park.
|
||||
|
||||
## Shard Catalogs
|
||||
|
|
@ -68,9 +69,9 @@ Rust now exposes the same shard topology vocabulary as the other runtimes
|
|||
without claiming to be the full C# service body:
|
||||
|
||||
```rust
|
||||
use cultnet_rs::{CultNetMessage, CultNetShardCatalog, CultNetShardDescriptor};
|
||||
use cultnet_rs::{CultMesh, CultNetMessage, CultNetShardDescriptor};
|
||||
|
||||
let mut catalog = CultNetShardCatalog::new();
|
||||
let mut catalog = CultMesh::create_shard_catalog();
|
||||
catalog.upsert(CultNetShardDescriptor {
|
||||
shard_id: "notes-a".to_string(),
|
||||
owner_runtime_id: "rust-primary".to_string(),
|
||||
|
|
@ -123,9 +124,16 @@ contact and authority ergonomics:
|
|||
|
||||
```rust
|
||||
use cultnet_rs::{
|
||||
CultMesh, CultMeshPeerCard, CultMeshRudpSocketOptions,
|
||||
CultMesh, CultMeshPeerCard, CultMeshRudpSocketOptions, CultNetSchemaKind,
|
||||
};
|
||||
|
||||
let schemas = CultMesh::create_builtin_schema_registry()?;
|
||||
let shared_contracts = schemas.list(&cultnet_rs::CultNetSchemaCatalogOptions {
|
||||
include_schema_json: false,
|
||||
schema_ids: None,
|
||||
kinds: Some(vec![CultNetSchemaKind::SharedContract]),
|
||||
});
|
||||
|
||||
let mut server = CultMesh::create_rudp_server(
|
||||
"rust-server",
|
||||
0x1020_3040,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ use std::time::Duration;
|
|||
use crate::CultNetRudpSocketMode;
|
||||
use crate::CultNetRudpSocketTransportConnection;
|
||||
use crate::CultNetRudpSocketTransportOptions;
|
||||
use crate::CultNetSchemaRegistry;
|
||||
use crate::CultNetShardCatalog;
|
||||
use crate::builtin_schema_registry;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CultMeshPeerCard {
|
||||
|
|
@ -236,6 +239,18 @@ impl Default for CultMeshRudpSocketOptions {
|
|||
pub struct CultMesh;
|
||||
|
||||
impl CultMesh {
|
||||
pub fn create_schema_registry() -> CultNetSchemaRegistry {
|
||||
CultNetSchemaRegistry::new()
|
||||
}
|
||||
|
||||
pub fn create_builtin_schema_registry() -> Result<CultNetSchemaRegistry> {
|
||||
builtin_schema_registry()
|
||||
}
|
||||
|
||||
pub fn create_shard_catalog() -> CultNetShardCatalog {
|
||||
CultNetShardCatalog::new()
|
||||
}
|
||||
|
||||
pub fn create_peer_catalog() -> CultMeshPeerCatalog {
|
||||
CultMeshPeerCatalog::new()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ use cultnet_rs::CultNetRudpSocketMode;
|
|||
use cultnet_rs::CultNetRudpSocketTransportConnection;
|
||||
use cultnet_rs::CultNetRudpSocketTransportOptions;
|
||||
use cultnet_rs::CultNetSchemaKind;
|
||||
use cultnet_rs::CultNetSchemaRegistration;
|
||||
use cultnet_rs::CultNetSchemaRegistry;
|
||||
use cultnet_rs::CultNetSecret;
|
||||
use cultnet_rs::CultNetServerSecurityOptions;
|
||||
|
|
@ -1184,6 +1185,66 @@ fn cultmesh_facade_creates_rudp_client_from_peer_endpoint() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cultmesh_facade_exposes_schema_registry_and_shard_catalog_owners() -> Result<()> {
|
||||
let mut schemas = CultMesh::create_schema_registry();
|
||||
schemas.register(CultNetSchemaRegistration {
|
||||
schema_id: "rust.cultmesh.note.v1".to_string(),
|
||||
kind: CultNetSchemaKind::DocumentPayload,
|
||||
wire_contracts: vec![CultNetWireContract::CultNetSchemaV0],
|
||||
schema_version: Some("rust.cultmesh.note.v1".to_string()),
|
||||
document_type: Some("rust.cultmesh.note".to_string()),
|
||||
title: Some("Rust CultMesh Note".to_string()),
|
||||
schema_json: Some(
|
||||
r#"{"$id":"rust.cultmesh.note.v1","type":"object","properties":{"body":{"type":"string"}}}"#
|
||||
.to_string(),
|
||||
),
|
||||
})?;
|
||||
assert_eq!(
|
||||
schemas
|
||||
.get("rust.cultmesh.note.v1", false)
|
||||
.expect("registered schema is discoverable")
|
||||
.document_type
|
||||
.as_deref(),
|
||||
Some("rust.cultmesh.note")
|
||||
);
|
||||
|
||||
let builtins = CultMesh::create_builtin_schema_registry()?;
|
||||
let shared_contracts = builtins.list(&cultnet_rs::CultNetSchemaCatalogOptions {
|
||||
include_schema_json: false,
|
||||
schema_ids: None,
|
||||
kinds: Some(vec![CultNetSchemaKind::SharedContract]),
|
||||
});
|
||||
assert!(shared_contracts.iter().any(|schema| {
|
||||
schema.schema_id
|
||||
== "https://github.com/GameCult/cultnet-ts/contracts/cultnet.transport-profile.schema.json"
|
||||
&& schema.schema_version.as_deref() == Some("cultnet.transport_profile.v0")
|
||||
}));
|
||||
|
||||
let mut shards = CultMesh::create_shard_catalog();
|
||||
shards.upsert(CultNetShardDescriptor {
|
||||
shard_id: "rust-notes-a".to_string(),
|
||||
owner_runtime_id: "rust-cultmesh".to_string(),
|
||||
epoch: 7,
|
||||
is_primary: Some(true),
|
||||
schema_ids: vec!["rust.cultmesh.note.v1".to_string()],
|
||||
key_prefix: Some("note:".to_string()),
|
||||
primary_endpoints: vec!["rudp://127.0.0.1:4100".to_string()],
|
||||
replica_endpoints: Vec::new(),
|
||||
read_replica_endpoints: Vec::new(),
|
||||
region: None,
|
||||
authority_lease_id: Some("lease:rust-notes-a".to_string()),
|
||||
})?;
|
||||
let matching = shards.list(&cultnet_rs::CultNetShardCatalogOptions {
|
||||
schema_ids: Some(vec!["rust.cultmesh.note.v1".to_string()]),
|
||||
record_keys: Some(vec!["note:1".to_string()]),
|
||||
});
|
||||
assert_eq!(matching.len(), 1);
|
||||
assert_eq!(matching[0].shard_id, "rust-notes-a");
|
||||
assert!(shards.get("rust-notes-a").is_some());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cultmesh_authority_leases_gate_peer_contact_hints() -> Result<()> {
|
||||
let now = Utc::now();
|
||||
|
|
|
|||
Loading…
Reference in a new issue