Unwrap Rust provider advertisements
This commit is contained in:
parent
096b0d7dff
commit
188ffedadf
2 changed files with 41 additions and 6 deletions
|
|
@ -107,13 +107,19 @@ function normalizeDocumentPayload(record) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
if (Array.isArray(payload) && payload.length === 1 && payload[0] && typeof payload[0] === "object" && !Array.isArray(payload[0])) {
|
||||
return payload[0];
|
||||
let normalized = payload;
|
||||
for (let depth = 0; depth < 4; depth += 1) {
|
||||
if (Array.isArray(normalized) && normalized.length === 1 && normalized[0] && typeof normalized[0] === "object") {
|
||||
normalized = normalized[0];
|
||||
continue;
|
||||
}
|
||||
if (normalized?.value && typeof normalized.value === "object" && !Array.isArray(normalized.value)) {
|
||||
normalized = normalized.value;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (payload?.value && typeof payload.value === "object" && !Array.isArray(payload.value)) {
|
||||
return payload.value;
|
||||
}
|
||||
return payload || {};
|
||||
return normalized || {};
|
||||
}
|
||||
|
||||
function surfaceProviderId(surfaceState) {
|
||||
|
|
|
|||
29
test/provider-ingress.test.cjs
Normal file
29
test/provider-ingress.test.cjs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
const test = require("node:test");
|
||||
|
||||
const { createLiveProviderRegistry } = require("../src/odin/provider-ingress.cjs");
|
||||
|
||||
test("live provider registry unwraps Rust compatibility records", () => {
|
||||
const registry = createLiveProviderRegistry();
|
||||
registry.ingestDocument({
|
||||
schemaId: "gamecult.eve.provider_advertisement.v1",
|
||||
recordKey: "muninn.telemetry.nightwing",
|
||||
payload: [{
|
||||
value: {
|
||||
providerId: "muninn.telemetry.nightwing",
|
||||
title: "Muninn Nightwing Telemetry",
|
||||
status: "active",
|
||||
cultMeshAddress: "asgard.nightwing.muninn/telemetry",
|
||||
capabilities: ["muninn.move_evidence_stream"],
|
||||
},
|
||||
}],
|
||||
}, { address: "10.77.0.3", port: 40000 });
|
||||
|
||||
const snapshot = registry.snapshot();
|
||||
assert.equal(snapshot.providerAdvertisements.length, 1);
|
||||
assert.equal(snapshot.providerAdvertisements[0].id, "muninn.telemetry.nightwing");
|
||||
assert.deepEqual(snapshot.providerAdvertisements[0].capabilities, ["muninn.move_evidence_stream"]);
|
||||
assert.equal(snapshot.providerAdvertisements[0].source, "cultnet-rudp://10.77.0.3:40000");
|
||||
});
|
||||
Loading…
Reference in a new issue