Accept model atlas publications in Odin

This commit is contained in:
Meta Vens 2026-08-14 13:13:39 +02:00
commit d34cb7e914
4 changed files with 237 additions and 12 deletions

View file

@ -7,9 +7,12 @@ pub const ODIN_SERVICE_SCHEMA: &str = "odin.service.v1";
pub const ODIN_INTERFACE_SCHEMA: &str = "odin.interface.v1";
pub const ODIN_OBSERVATION_STREAM_SCHEMA: &str = "odin.observation_stream.v1";
pub const ODIN_TRANSLATION_ROUTE_SCHEMA: &str = "odin.translation_route.v1";
pub const EVE_SURFACE_SCHEMA: &str = "gamecult.eve.surface.v1";
pub const EVE_SURFACE_STATE_SCHEMA: &str = "gamecult.eve.surface_state.v1";
pub const EVE_INTERFACE_BINDING_SCHEMA: &str = "gamecult.eve.interface_binding.v1";
pub const EVE_PROVIDER_ADVERTISEMENT_SCHEMA: &str = "gamecult.eve.provider_advertisement.v1";
pub const MODEL_ATLAS_PUBLICATION_SCHEMA: &str = "gamecult.model.atlas_publication.v0";
pub const MODEL_ENTANGLEMENT_PROJECTION_SCHEMA: &str = "gamecult.model.entanglement_projection.v0";
pub const VOIDBOT_SWARM_STATE_SNAPSHOT_SCHEMA: &str = "voidbot.swarm_state_snapshot.v1";
pub const IDUNN_DESIRED_DAEMON_SCHEMA: &str = "idunn.desired_daemon.v1";
pub const IDUNN_DAEMON_HEALTH_SCHEMA: &str = "idunn.daemon_health.v1";
@ -190,6 +193,33 @@ pub struct EveSurfaceStateRecord {
pub surface: Value,
}
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
#[cultcache(type = "gamecult.eve.surface", schema = "gamecult.eve.surface.v1")]
pub struct EveSurfaceCompatRecord {
#[cultcache(key = 0)]
pub value: Value,
}
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
#[cultcache(
type = "gamecult.model.atlas_publication",
schema = "gamecult.model.atlas_publication.v0"
)]
pub struct ModelAtlasPublicationCompatRecord {
#[cultcache(key = 0)]
pub value: Value,
}
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
#[cultcache(
type = "gamecult.model.entanglement_projection",
schema = "gamecult.model.entanglement_projection.v0"
)]
pub struct ModelEntanglementProjectionCompatRecord {
#[cultcache(key = 0)]
pub value: Value,
}
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
#[cultcache(
type = "gamecult.eve.interface_binding",
@ -1415,9 +1445,12 @@ cultmesh_rs::cultmesh_documents!(OdinDocuments {
OdinInterfaceRecord => ODIN_INTERFACE_SCHEMA,
OdinObservationStreamRecord => ODIN_OBSERVATION_STREAM_SCHEMA,
OdinTranslationRouteRecord => ODIN_TRANSLATION_ROUTE_SCHEMA,
EveSurfaceCompatRecord => EVE_SURFACE_SCHEMA,
EveSurfaceStateRecord => EVE_SURFACE_STATE_SCHEMA,
EveInterfaceBindingCompatRecord => EVE_INTERFACE_BINDING_SCHEMA,
EveProviderAdvertisementRecord => EVE_PROVIDER_ADVERTISEMENT_SCHEMA,
ModelAtlasPublicationCompatRecord => MODEL_ATLAS_PUBLICATION_SCHEMA,
ModelEntanglementProjectionCompatRecord => MODEL_ENTANGLEMENT_PROJECTION_SCHEMA,
VoidBotSwarmStateSnapshotCompatRecord => VOIDBOT_SWARM_STATE_SNAPSHOT_SCHEMA,
IdunnDesiredDaemonRecord => IDUNN_DESIRED_DAEMON_SCHEMA,
IdunnDaemonHealthRecord => IDUNN_DAEMON_HEALTH_SCHEMA,
@ -1478,6 +1511,94 @@ mod tests {
use super::*;
use anyhow::Result;
use cultmesh_rs::{CultMesh, CultMeshNodeOptions};
use serde_json::json;
#[test]
fn model_atlas_documents_round_trip_without_odin_authored_edges() -> Result<()> {
let temp = tempfile::tempdir()?;
let store_path = temp.path().join("model-atlas.cc");
let mut node = CultMesh::create_node(
&store_path,
OdinDocuments,
CultMeshNodeOptions {
runtime_id: "odin-model-atlas-test".to_string(),
pull_on_start: true,
},
)?;
let atlas = ModelAtlasPublicationCompatRecord {
value: json!({
"publicationId": "aetheria-atlas",
"repositoryId": "GameCult/Aetheria",
"nodes": [{ "id": "aetheria.runtime" }]
}),
};
let projection = ModelEntanglementProjectionCompatRecord {
value: json!({
"projectionId": "gamecult-model-entanglement",
"sourcePublicationIds": ["aetheria-atlas"],
"edges": []
}),
};
let surface = EveSurfaceCompatRecord {
value: json!({
"schema": EVE_SURFACE_SCHEMA,
"id": "gamecult.model.atlas.surface",
"root": { "id": "root", "kind": "dashboard", "children": [] }
}),
};
node.put("atlas:aetheria", &atlas)?;
node.put("entanglement:gamecult", &projection)?;
node.put("surface:model-atlas", &surface)?;
assert_eq!(
node.documents()
.binding("gamecult.model.atlas_publication")
.and_then(|binding| binding.payload_schema_version.clone())
.as_deref(),
Some(MODEL_ATLAS_PUBLICATION_SCHEMA)
);
assert_eq!(
node.documents()
.binding("gamecult.model.entanglement_projection")
.and_then(|binding| binding.payload_schema_version.clone())
.as_deref(),
Some(MODEL_ENTANGLEMENT_PROJECTION_SCHEMA)
);
assert_eq!(
node.documents()
.binding("gamecult.eve.surface")
.and_then(|binding| binding.payload_schema_version.clone())
.as_deref(),
Some(EVE_SURFACE_SCHEMA)
);
assert!(node.documents().binding("gamecult.model.unknown").is_none());
let reloaded = CultMesh::create_node(
&store_path,
OdinDocuments,
CultMeshNodeOptions {
runtime_id: "odin-model-atlas-test-reloaded".to_string(),
pull_on_start: true,
},
)?;
let reloaded_atlas = reloaded
.get_required::<ModelAtlasPublicationCompatRecord>("atlas:aetheria")?
.value;
let reloaded_projection = reloaded
.get_required::<ModelEntanglementProjectionCompatRecord>("entanglement:gamecult")?
.value;
assert!(reloaded_atlas.get("edges").is_none());
assert_eq!(reloaded_projection["edges"], json!([]));
assert_eq!(
reloaded
.get_required::<EveSurfaceCompatRecord>("surface:model-atlas")?
.value["id"],
"gamecult.model.atlas.surface"
);
Ok(())
}
#[test]
fn muninn_media_documents_round_trip_through_cultmesh() -> Result<()> {

View file

@ -6,7 +6,7 @@ const path = require("path");
const { buildConfig, loadCultRuntime } = require("./odin/config.cjs");
const { createCultMeshRudpDocumentServer } = require("./odin/cultnet-rudp.cjs");
const { defineOdinDocuments } = require("./odin/documents.cjs");
const { defineOdinDocuments, documentDefinitionForSchema } = require("./odin/documents.cjs");
const { createInterfaceDiscovery } = require("./odin/interfaces.cjs");
const { createIdunnRudpHealthPublisher, publishIdunnRudpHealth } = require("./odin/idunn-rudp.cjs");
const { createLayoutStore } = require("./odin/layout.cjs");
@ -101,21 +101,12 @@ async function main() {
async function persistRudpDocumentPut(document) {
if (!meshNodePromise || !document?.schemaId || !document?.recordKey) return;
const definition = documentDefinitionForSchema(document.schemaId);
const definition = documentDefinitionForSchema(documents, document.schemaId);
if (!definition) return;
const node = await meshNodePromise;
await node.put(definition, document.recordKey, normalizeRudpPayload(document.payload));
}
function documentDefinitionForSchema(schemaId) {
return allDocumentDefinitions.find((definition) =>
definition?.schemaId === schemaId
|| definition?.schemaVersion === schemaId
|| definition?.schemaName === schemaId
|| definition?.type === schemaId
);
}
function normalizeRudpPayload(payload) {
if (Array.isArray(payload) && payload.length === 1 && payload[0] && typeof payload[0] === "object" && !Array.isArray(payload[0])) {
return payload[0];

View file

@ -6,6 +6,7 @@ function defineOdinDocuments(defineDocumentType) {
if (!defineDocumentType) {
return {
interfaceBindingDefinition: null,
eveSurfaceDefinition: null,
idunnCommandBoundaryDefinition: null,
idunnDaemonHealthDefinition: null,
idunnTransportProfileDefinition: null,
@ -25,6 +26,8 @@ function defineOdinDocuments(defineDocumentType) {
muninnQuestAccessDefinition: null,
muninnTelemetrySurfaceDefinition: null,
muninnTransportProfileDefinition: null,
modelAtlasPublicationDefinition: null,
modelEntanglementProjectionDefinition: null,
SleipnirInputMappingDefinition: null,
aetheriaAssetManifestDefinition: null,
aetheriaGravityViewportDefinition: null,
@ -65,6 +68,15 @@ function defineOdinDocuments(defineDocumentType) {
{ slot: 4, memberName: "surface", typeName: "object" },
],
});
const eveSurfaceDefinition = defineDocumentType({
type: "gamecult.eve.surface",
schemaName: "gamecult.eve.surface",
schemaId: "gamecult.eve.surface.v1",
schemaVersion: "gamecult.eve.surface.v1",
global: false,
name: (value) => value?.id || value?.surfaceId || value?.surface_id || "surface",
schema: parseObjectDocument("Eve surface"),
});
const interfaceBindingDefinition = defineDocumentType({
type: "gamecult.eve.interface_binding",
schemaName: "gamecult.eve.interface_binding",
@ -83,6 +95,24 @@ function defineOdinDocuments(defineDocumentType) {
name: (value) => value?.providerId || value?.provider?.id || "provider",
schema: parseObjectDocument("Eve provider advertisement"),
});
const modelAtlasPublicationDefinition = defineDocumentType({
type: "gamecult.model.atlas_publication",
schemaName: "gamecult.model.atlas_publication",
schemaId: "gamecult.model.atlas_publication.v0",
schemaVersion: "gamecult.model.atlas_publication.v0",
global: false,
name: (value) => value?.publicationId || value?.publication_id || value?.repositoryId || value?.repository_id || "model-atlas",
schema: parseObjectDocument("Model atlas publication"),
});
const modelEntanglementProjectionDefinition = defineDocumentType({
type: "gamecult.model.entanglement_projection",
schemaName: "gamecult.model.entanglement_projection",
schemaId: "gamecult.model.entanglement_projection.v0",
schemaVersion: "gamecult.model.entanglement_projection.v0",
global: false,
name: (value) => value?.projectionId || value?.projection_id || "model-entanglement",
schema: parseObjectDocument("Model entanglement projection"),
});
const interfaceLayoutDefinition = defineDocumentType({
type: "odin.interface_layout",
schemaName: "odin.interface_layout",
@ -445,6 +475,7 @@ function defineOdinDocuments(defineDocumentType) {
});
return {
eveSurfaceDefinition,
interfaceBindingDefinition,
interfaceLayoutDefinition,
idunnCommandBoundaryDefinition,
@ -465,6 +496,8 @@ function defineOdinDocuments(defineDocumentType) {
muninnQuestAccessDefinition,
muninnTelemetrySurfaceDefinition,
muninnTransportProfileDefinition,
modelAtlasPublicationDefinition,
modelEntanglementProjectionDefinition,
SleipnirInputMappingDefinition,
aetheriaAssetManifestDefinition,
aetheriaGravityViewportDefinition,
@ -489,4 +522,13 @@ function defineOdinDocuments(defineDocumentType) {
};
}
module.exports = { defineOdinDocuments };
function documentDefinitionForSchema(documents, schemaId) {
return Object.values(documents || {}).find((definition) =>
definition?.schemaId === schemaId
|| definition?.schemaVersion === schemaId
|| definition?.schemaName === schemaId
|| definition?.type === schemaId
) || null;
}
module.exports = { defineOdinDocuments, documentDefinitionForSchema };

View file

@ -0,0 +1,71 @@
"use strict";
const assert = require("node:assert/strict");
const fs = require("node:fs");
const os = require("node:os");
const path = require("node:path");
const test = require("node:test");
const { loadCultRuntime } = require("../src/odin/config.cjs");
const {
defineOdinDocuments,
documentDefinitionForSchema,
} = require("../src/odin/documents.cjs");
test("Odin persists accepted model-atlas and Eve documents without synthesizing edges", async (t) => {
const { CultMesh, defineDocumentType, error } = loadCultRuntime();
assert.ifError(error);
const documents = defineOdinDocuments(defineDocumentType);
const definitions = Object.values(documents).filter(Boolean);
const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "odin-model-atlas-"));
t.after(() => fs.rmSync(stateDir, { recursive: true, force: true }));
const atlasDefinition = documentDefinitionForSchema(
documents,
"gamecult.model.atlas_publication.v0",
);
const entanglementDefinition = documentDefinitionForSchema(
documents,
"gamecult.model.entanglement_projection.v0",
);
const surfaceDefinition = documentDefinitionForSchema(
documents,
"gamecult.eve.surface.v1",
);
assert.ok(atlasDefinition);
assert.ok(entanglementDefinition);
assert.ok(surfaceDefinition);
assert.equal(documentDefinitionForSchema(documents, "gamecult.model.unknown.v0"), null);
const node = await CultMesh.createNode(path.join(stateDir, "odin.ccmp"), {
documents: definitions,
});
const atlas = {
publicationId: "aetheria-atlas",
repositoryId: "GameCult/Aetheria",
nodes: [{ id: "aetheria.runtime" }],
};
const entanglement = {
projectionId: "gamecult-entanglement",
sourcePublicationIds: ["aetheria-atlas"],
edges: [],
};
const surface = {
schema: "gamecult.eve.surface.v1",
id: "gamecult.model.atlas.surface",
root: { id: "root", kind: "dashboard", children: [] },
};
await node.put(atlasDefinition, "atlas:aetheria", atlas);
await node.put(entanglementDefinition, "entanglement:gamecult", entanglement);
await node.put(surfaceDefinition, "surface:model-atlas", surface);
await node.flush(true);
assert.deepEqual(node.getRequired(atlasDefinition, "atlas:aetheria"), atlas);
assert.equal(node.getRequired(atlasDefinition, "atlas:aetheria").edges, undefined);
assert.deepEqual(
node.getRequired(entanglementDefinition, "entanglement:gamecult").edges,
[],
);
assert.deepEqual(node.getRequired(surfaceDefinition, "surface:model-atlas"), surface);
});