Collapse RTS publication readers into CultMesh catalog
This commit is contained in:
parent
e7f379168d
commit
20a1d11163
5 changed files with 131 additions and 172 deletions
|
|
@ -2,6 +2,9 @@ import { encode } from "@msgpack/msgpack";
|
|||
import { performance } from "node:perf_hooks";
|
||||
import { CultMesh } from "cultmesh-ts";
|
||||
import type {
|
||||
CultMeshDocumentCatalog,
|
||||
CultMeshDocumentPublicationSource,
|
||||
CultMeshPublicationDocumentBinding,
|
||||
CultMeshOperationContext,
|
||||
CultMeshQueryContext,
|
||||
CultMeshSurfaceCatalogIndexDiagnostic,
|
||||
|
|
@ -42,8 +45,6 @@ import {
|
|||
type ViewportRequest,
|
||||
type ViewportResponse,
|
||||
} from "./aetheria-rts-bindings.js";
|
||||
import { AetheriaLocalPublicationReader } from "./aetheria-local-publication-reader.js";
|
||||
import { AetheriaRemotePublicationReader } from "./aetheria-remote-publication-reader.js";
|
||||
import {
|
||||
projectAuthorityStatus,
|
||||
projectDaemonHealth,
|
||||
|
|
@ -57,13 +58,9 @@ import {
|
|||
|
||||
const connectionId = 0x43554c54;
|
||||
|
||||
type AetheriaPublicationReader = {
|
||||
readonly statePathDescription: string;
|
||||
readDaemonFrame(): Promise<unknown>;
|
||||
readDaemonHealth(): Promise<unknown>;
|
||||
readAuthorityPolicy(): Promise<unknown>;
|
||||
readStarbridgeSessionSummary(): Promise<unknown>;
|
||||
close?(): Promise<void>;
|
||||
type AetheriaPublicationDocumentSpec = CultMeshPublicationDocumentBinding & {
|
||||
readonly localPath: string;
|
||||
readonly remoteRecordKey?: string;
|
||||
};
|
||||
|
||||
export type AetheriaCultMeshClientOptions = {
|
||||
|
|
@ -103,19 +100,24 @@ export class AetheriaCultMeshClient {
|
|||
options: AetheriaCultMeshClientOptions = {},
|
||||
) {
|
||||
const publicationMode = options.publicationMode ?? "local";
|
||||
this.publications = publicationMode === "remote"
|
||||
? new AetheriaRemotePublicationReader(
|
||||
this.endpoint,
|
||||
`${this.runtimeId}-reader`,
|
||||
options.snapshotTimeoutMs)
|
||||
: new AetheriaLocalPublicationReader(statePath);
|
||||
this.publicationDescription = publicationMode === "remote" ? this.endpoint : statePath;
|
||||
this.verse = CultMesh.verse("aetheria.local", this.runtimeId);
|
||||
this.queryVerse = publicationMode === "remote"
|
||||
? this.verse.withRoute("network", this.publications.statePathDescription)
|
||||
: this.verse.withRoute("shared-memory", this.publications.statePathDescription);
|
||||
? this.verse.withRoute("network", this.publicationDescription)
|
||||
: this.verse.withRoute("shared-memory", this.publicationDescription);
|
||||
this.commandVerse = this.verse
|
||||
.withRoute("network", this.endpoint)
|
||||
.withClaim("commander-control", { shardId: "aetheria.local" });
|
||||
this.publications = CultMesh.documentsFromPublication(
|
||||
this.createPublicationSource(publicationMode),
|
||||
createAetheriaPublicationDocuments(statePath, publicationMode),
|
||||
{
|
||||
routeHint: this.queryVerse.context.routeHint,
|
||||
timeoutMs: options.snapshotTimeoutMs,
|
||||
pollMs: 50,
|
||||
messageIdPrefix: `${this.runtimeId}:snapshot`,
|
||||
},
|
||||
);
|
||||
const executors = {
|
||||
mapViewport: async (request: ViewportRequest) => projectViewportFromFrame(await this.fetchLatestFrameDocument(), request),
|
||||
objectsViewport: async (request: ViewportRequest) => projectObjectsViewportFromFrame(await this.fetchLatestFrameDocument(), request),
|
||||
|
|
@ -161,14 +163,14 @@ export class AetheriaCultMeshClient {
|
|||
);
|
||||
}
|
||||
|
||||
private readonly publications: AetheriaPublicationReader;
|
||||
private readonly publicationDescription: string;
|
||||
private readonly publications: CultMeshDocumentCatalog;
|
||||
private readonly queries: ReturnType<typeof createAetheriaRuntimeRtsQueryHandles>;
|
||||
private readonly documents: AetheriaRuntimeRtsDocuments;
|
||||
private readonly operations: AetheriaRuntimeRtsOperationHandles;
|
||||
private readonly aetheria: AetheriaRuntimeRtsVerseFacade;
|
||||
|
||||
public async close(): Promise<void> {
|
||||
await this.publications.close?.();
|
||||
this.#peer?.close();
|
||||
this.#peer = null;
|
||||
}
|
||||
|
|
@ -221,6 +223,7 @@ export class AetheriaCultMeshClient {
|
|||
return this.aetheria.daemon.starbridgeSession();
|
||||
}
|
||||
|
||||
|
||||
public projectionDiagnostics(): Readonly<Record<string, AetheriaRuntimeRtsProjectionDiagnostic>> {
|
||||
return describeAetheriaRuntimeRtsQueryHandles(this.queries);
|
||||
}
|
||||
|
|
@ -267,19 +270,41 @@ export class AetheriaCultMeshClient {
|
|||
}
|
||||
|
||||
private async fetchLatestFrameDocument(): Promise<unknown> {
|
||||
return this.publications.readDaemonFrame();
|
||||
return this.fetchPublicationDocument(AetheriaRtsSchemas.daemonFrame);
|
||||
}
|
||||
|
||||
private async fetchDaemonHealthDocument(): Promise<unknown> {
|
||||
return this.publications.readDaemonHealth();
|
||||
return this.fetchPublicationDocument(AetheriaRtsSchemas.daemonHealth);
|
||||
}
|
||||
|
||||
private async fetchAuthorityPolicyDocument(): Promise<unknown> {
|
||||
return this.publications.readAuthorityPolicy();
|
||||
return this.fetchPublicationDocument(AetheriaRtsSchemas.verseAuthorityPolicy);
|
||||
}
|
||||
|
||||
private async fetchStarbridgeSessionSummaryDocument(): Promise<unknown> {
|
||||
return this.publications.readStarbridgeSessionSummary();
|
||||
return this.fetchPublicationDocument(AetheriaRtsSchemas.starbridgeSessionSummary);
|
||||
}
|
||||
|
||||
|
||||
private fetchPublicationDocument(schemaId: string): Promise<unknown> {
|
||||
return this.publications.latest({ schemaId }, this.queryContext());
|
||||
}
|
||||
|
||||
private createPublicationSource(
|
||||
mode: "local" | "remote",
|
||||
): (binding: CultMeshPublicationDocumentBinding) => CultMeshDocumentPublicationSource {
|
||||
if (mode === "remote") {
|
||||
return () => ({
|
||||
kind: "peer-snapshot",
|
||||
peer: () => this.peer(),
|
||||
endpoint: this.endpoint,
|
||||
});
|
||||
}
|
||||
|
||||
return binding => ({
|
||||
kind: "single-file",
|
||||
path: (binding as AetheriaPublicationDocumentSpec).localPath,
|
||||
});
|
||||
}
|
||||
|
||||
private createViewportFeed() {
|
||||
|
|
@ -438,6 +463,67 @@ function composeViewport(
|
|||
};
|
||||
}
|
||||
|
||||
function createAetheriaPublicationDocuments(
|
||||
statePath: string,
|
||||
mode: "local" | "remote",
|
||||
): readonly AetheriaPublicationDocumentSpec[] {
|
||||
const documents: readonly AetheriaPublicationDocumentSpec[] = [
|
||||
{
|
||||
...CultMesh.publicationDocument(
|
||||
AetheriaRtsSchemas.daemonFrame,
|
||||
"daemon:aetheria.frame.latest.v1",
|
||||
{
|
||||
documentId: "daemon:aetheria.frame.latest.v1",
|
||||
sourceId: "daemon:aetheria.frame.latest.v1",
|
||||
},
|
||||
),
|
||||
localPath: `${statePath}.daemon.frame.cc`,
|
||||
},
|
||||
{
|
||||
...CultMesh.publicationDocument(
|
||||
AetheriaRtsSchemas.daemonHealth,
|
||||
"daemon:aetheria.health.latest.v1",
|
||||
{
|
||||
documentId: "daemon:aetheria.health.latest.v1",
|
||||
sourceId: "daemon:aetheria.health.latest.v1",
|
||||
},
|
||||
),
|
||||
localPath: `${statePath}.daemon.health.cc`,
|
||||
remoteRecordKey: "daemon:aetheria.health.v1",
|
||||
},
|
||||
{
|
||||
...CultMesh.publicationDocument(
|
||||
AetheriaRtsSchemas.verseAuthorityPolicy,
|
||||
"daemon:aetheria.authority.policy.latest.v1",
|
||||
{
|
||||
documentId: "daemon:aetheria.authority.policy.latest.v1",
|
||||
sourceId: "daemon:aetheria.authority.policy.latest.v1",
|
||||
},
|
||||
),
|
||||
localPath: `${statePath}.authority.policy.cc`,
|
||||
remoteRecordKey: "global:aetheria.verse_authority_policy.v1",
|
||||
},
|
||||
{
|
||||
...CultMesh.publicationDocument(
|
||||
AetheriaRtsSchemas.starbridgeSessionSummary,
|
||||
"daemon:aetheria.starbridge.session.latest.v1",
|
||||
{
|
||||
documentId: "daemon:aetheria.starbridge.session.latest.v1",
|
||||
sourceId: "daemon:aetheria.starbridge.session.latest.v1",
|
||||
},
|
||||
),
|
||||
localPath: `${statePath}.daemon.starbridge.session.cc`,
|
||||
},
|
||||
];
|
||||
|
||||
return documents.map(document => mode === "remote" && document.remoteRecordKey
|
||||
? {
|
||||
...document,
|
||||
recordKey: document.remoteRecordKey,
|
||||
}
|
||||
: document);
|
||||
}
|
||||
|
||||
function delay(milliseconds: number): Promise<void> {
|
||||
return new Promise(resolve => setTimeout(resolve, milliseconds));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
import { CultMesh } from "cultmesh-ts";
|
||||
|
||||
export class AetheriaLocalPublicationReader {
|
||||
public constructor(private readonly statePath: string) {}
|
||||
|
||||
public get statePathDescription(): string {
|
||||
return this.statePath;
|
||||
}
|
||||
|
||||
public readDaemonFrame(): Promise<unknown> {
|
||||
return this.readSingleDocument(
|
||||
`${this.statePath}.daemon.frame.cc`,
|
||||
"gamecult.aetheria.daemon_frame.v1",
|
||||
"daemon:aetheria.frame.latest.v1");
|
||||
}
|
||||
|
||||
public readDaemonHealth(): Promise<unknown> {
|
||||
return this.readSingleDocument(
|
||||
`${this.statePath}.daemon.health.cc`,
|
||||
"gamecult.aetheria.daemon_health.v1",
|
||||
"daemon:aetheria.health.latest.v1");
|
||||
}
|
||||
|
||||
public readAuthorityPolicy(): Promise<unknown> {
|
||||
return this.readSingleDocument(
|
||||
`${this.statePath}.authority.policy.cc`,
|
||||
"gamecult.aetheria.verse_authority_policy.v1",
|
||||
"daemon:aetheria.authority.policy.latest.v1");
|
||||
}
|
||||
|
||||
public readStarbridgeSessionSummary(): Promise<unknown> {
|
||||
return this.readSingleDocument(
|
||||
`${this.statePath}.daemon.starbridge.session.cc`,
|
||||
"gamecult.aetheria.starbridge_session_summary.v1",
|
||||
"daemon:aetheria.starbridge.session.latest.v1");
|
||||
}
|
||||
|
||||
private readSingleDocument(
|
||||
path: string,
|
||||
schemaId: string,
|
||||
documentId: string,
|
||||
): Promise<unknown> {
|
||||
return CultMesh.documentFromPublication({
|
||||
kind: "single-file",
|
||||
path,
|
||||
}, schemaId, documentId, {
|
||||
documentId,
|
||||
sourceId: documentId,
|
||||
}).latest();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
import { CultMesh } from "cultmesh-ts";
|
||||
import type { CultNetPeer } from "cultnet-ts";
|
||||
|
||||
const connectionId = 0x43554c54;
|
||||
|
||||
export class AetheriaRemotePublicationReader {
|
||||
#peer: CultNetPeer | null = null;
|
||||
|
||||
public constructor(
|
||||
private readonly endpoint: string,
|
||||
private readonly runtimeId = "aetheria-rts-remote-reader",
|
||||
private readonly timeoutMs = 2_500,
|
||||
) {}
|
||||
|
||||
public get statePathDescription(): string {
|
||||
return this.endpoint;
|
||||
}
|
||||
|
||||
public async close(): Promise<void> {
|
||||
this.#peer?.close();
|
||||
this.#peer = null;
|
||||
}
|
||||
|
||||
public readDaemonFrame(): Promise<unknown> {
|
||||
return this.readSingleDocument(
|
||||
"gamecult.aetheria.daemon_frame.v1",
|
||||
"daemon:aetheria.frame.latest.v1");
|
||||
}
|
||||
|
||||
public readDaemonHealth(): Promise<unknown> {
|
||||
return this.readSingleDocument(
|
||||
"gamecult.aetheria.daemon_health.v1",
|
||||
"daemon:aetheria.health.v1");
|
||||
}
|
||||
|
||||
public readAuthorityPolicy(): Promise<unknown> {
|
||||
return this.readSingleDocument(
|
||||
"gamecult.aetheria.verse_authority_policy.v1",
|
||||
"global:aetheria.verse_authority_policy.v1");
|
||||
}
|
||||
|
||||
public readStarbridgeSessionSummary(): Promise<unknown> {
|
||||
return this.readSingleDocument(
|
||||
"gamecult.aetheria.starbridge_session_summary.v1",
|
||||
"daemon:aetheria.starbridge.session.latest.v1");
|
||||
}
|
||||
|
||||
private async readSingleDocument(schemaId: string, recordKey: string): Promise<unknown> {
|
||||
return CultMesh.documentFromPublication(
|
||||
{
|
||||
kind: "peer-snapshot",
|
||||
peer: () => this.peer(),
|
||||
endpoint: this.endpoint,
|
||||
},
|
||||
schemaId,
|
||||
recordKey,
|
||||
{
|
||||
documentId: recordKey,
|
||||
routeHint: CultMesh.routeHint("network", this.endpoint),
|
||||
timeoutMs: this.timeoutMs,
|
||||
messageIdPrefix: `${this.runtimeId}:snapshot`,
|
||||
},
|
||||
).latest();
|
||||
}
|
||||
|
||||
private async peer(): Promise<CultNetPeer> {
|
||||
if (this.#peer)
|
||||
return this.#peer;
|
||||
|
||||
this.#peer = await CultMesh.createRudpPeer(this.runtimeId, connectionId, this.endpoint, {
|
||||
connectTimeoutMs: 2_000,
|
||||
maxFragmentBytes: 1200,
|
||||
maxPendingReliablePackets: 512,
|
||||
});
|
||||
this.#peer.on("close", () => {
|
||||
this.#peer = null;
|
||||
});
|
||||
return this.#peer;
|
||||
}
|
||||
}
|
||||
|
|
@ -285,12 +285,18 @@ if (check) {
|
|||
|
||||
function readExisting(path) {
|
||||
try {
|
||||
return readFileSync(path, "utf8");
|
||||
return normalizeGeneratedText(readFileSync(path, "utf8"));
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeGeneratedText(text) {
|
||||
return text
|
||||
.replace(/^\uFEFF/u, "")
|
||||
.replace(/\r\n/gu, "\n");
|
||||
}
|
||||
|
||||
function parseEnum(text, enumName) {
|
||||
const body = readTypeBody(text, `enum ${enumName}`);
|
||||
const entries = [];
|
||||
|
|
|
|||
|
|
@ -103,21 +103,19 @@ if ($LASTEXITCODE -gt 1) {
|
|||
}
|
||||
|
||||
$remotePublicationReaderPatterns = @(
|
||||
'@msgpack/msgpack',
|
||||
'sendSnapshotRequest',
|
||||
'snapshot_response_raw',
|
||||
'CultNetSnapshotResponseRawMessage',
|
||||
'recordKeys',
|
||||
'decode\('
|
||||
)
|
||||
|
||||
$remotePublicationReaderPattern = ($remotePublicationReaderPatterns -join '|')
|
||||
$remotePublicationReaderHits = & rg -n $remotePublicationReaderPattern Electron/aetheria-remote-publication-reader.ts 2>$null
|
||||
$remotePublicationReaderHits = & rg -n $remotePublicationReaderPattern Electron/aetheria-cultmesh.ts 2>$null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Error "Stage 7B verifier failed: RTS remote publication reader still owns raw snapshot/codec details.`n$remotePublicationReaderHits"
|
||||
Write-Error "Stage 7B verifier failed: RTS CultMesh client still owns raw snapshot/codec details.`n$remotePublicationReaderHits"
|
||||
}
|
||||
if ($LASTEXITCODE -gt 1) {
|
||||
Write-Error "Stage 7B verifier could not run rg for remote publication reader layout checks."
|
||||
Write-Error "Stage 7B verifier could not run rg for remote publication layout checks."
|
||||
}
|
||||
|
||||
$requiredBindingSymbols = @(
|
||||
|
|
@ -240,15 +238,15 @@ if (-not $clientText.Contains('this.documents = createAetheriaRuntimeRtsDocument
|
|||
|
||||
if (-not $clientText.Contains('daemonFrame: async () => this.fetchLatestFrameDocument()') -or
|
||||
-not $clientText.Contains('authorityPolicy: async () => this.fetchAuthorityPolicyDocument()')) {
|
||||
Write-Error "Stage 7B verifier failed: RTS client document handles are not resolving through daemon publication readers."
|
||||
Write-Error "Stage 7B verifier failed: RTS client document handles are not resolving through the daemon publication catalog."
|
||||
}
|
||||
|
||||
if (-not $clientText.Contains('this.verse = CultMesh.verse("aetheria.local", this.runtimeId)')) {
|
||||
Write-Error "Stage 7B verifier failed: RTS client should bind to the shared CultMesh Verse primitive instead of constructing local contexts directly."
|
||||
}
|
||||
|
||||
if (-not $clientText.Contains('? this.verse.withRoute("network", this.publications.statePathDescription)') -or
|
||||
-not $clientText.Contains(': this.verse.withRoute("shared-memory", this.publications.statePathDescription)')) {
|
||||
if (-not $clientText.Contains('? this.verse.withRoute("network", this.publicationDescription)') -or
|
||||
-not $clientText.Contains(': this.verse.withRoute("shared-memory", this.publicationDescription)')) {
|
||||
Write-Error "Stage 7B verifier failed: RTS client is not deriving publication-mode Verse views for projection reads."
|
||||
}
|
||||
|
||||
|
|
@ -258,7 +256,7 @@ if (-not $clientText.Contains('this.commandVerse = this.verse') -or
|
|||
Write-Error "Stage 7B verifier failed: RTS client is not deriving a network Verse view with an explicit command authority claim."
|
||||
}
|
||||
|
||||
if (-not $clientText.Contains('this.publications.statePathDescription')) {
|
||||
if (-not $clientText.Contains('this.publicationDescription = publicationMode === "remote" ? this.endpoint : statePath')) {
|
||||
Write-Error "Stage 7B verifier failed: RTS client projection route metadata does not include the local publication source description."
|
||||
}
|
||||
|
||||
|
|
@ -491,25 +489,25 @@ foreach ($symbol in $requiredProjectionSymbols) {
|
|||
}
|
||||
}
|
||||
|
||||
& rg -q 'CultMesh.documentFromPublication' Electron/aetheria-local-publication-reader.ts
|
||||
& rg -q 'CultMesh.documentsFromPublication' Electron/aetheria-cultmesh.ts
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "Stage 7B verifier failed: local publications should be read through configured CultMesh document handles."
|
||||
Write-Error "Stage 7B verifier failed: RTS publications should be read through a configured CultMesh document catalog."
|
||||
}
|
||||
|
||||
$forbiddenLocalPublicationReaderPlumbing = & rg -n 'SingleFileMessagePackBackingStore|decode\(|pullAll\(' Electron/aetheria-local-publication-reader.ts 2>$null
|
||||
$forbiddenPublicationReaderFiles = & rg -n 'AetheriaLocalPublicationReader|AetheriaRemotePublicationReader|aetheria-local-publication-reader|aetheria-remote-publication-reader' Electron 2>$null
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
Write-Error "Stage 7B verifier failed: local publication reader still owns backing-store or MessagePack plumbing.`n$forbiddenLocalPublicationReaderPlumbing"
|
||||
Write-Error "Stage 7B verifier failed: RTS publication reader wrappers should be collapsed into the CultMesh document catalog.`n$forbiddenPublicationReaderFiles"
|
||||
}
|
||||
if ($LASTEXITCODE -gt 1) {
|
||||
Write-Error "Stage 7B verifier could not run rg for local publication reader plumbing checks."
|
||||
Write-Error "Stage 7B verifier could not run rg for stale publication reader checks."
|
||||
}
|
||||
|
||||
& rg -q 'readStarbridgeSessionSummary' Electron/aetheria-local-publication-reader.ts
|
||||
& rg -q 'AetheriaRtsSchemas.starbridgeSessionSummary' Electron/aetheria-cultmesh.ts
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "Stage 7B verifier failed: local Starbridge summary publication reader was not found."
|
||||
Write-Error "Stage 7B verifier failed: Starbridge summary publication binding was not found."
|
||||
}
|
||||
|
||||
& rg -q '.daemon.starbridge.session.cc' Electron/aetheria-local-publication-reader.ts
|
||||
& rg -q '.daemon.starbridge.session.cc' Electron/aetheria-cultmesh.ts
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "Stage 7B verifier failed: RTS client is not reading the daemon Starbridge sidecar publication."
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue