Resolve embedded provider documents generically

This commit is contained in:
Meta Vens 2026-07-10 13:15:04 +01:00
commit 3d324b019f
3 changed files with 16 additions and 1 deletions

View file

@ -22,6 +22,7 @@ export declare class EveCultMeshProviderClient {
providerAdvertisement(): Promise<Record<string, unknown>>;
surface(surfaceId?: string): Promise<Record<string, unknown>>;
document(request: { schemaId: string; recordRef: string }): Promise<unknown>;
resolveDocument(request: { documentId: string; schemaId: string }): Promise<{ documentId: string; schemaId: string; document: unknown }>;
submitCommand(request: Record<string, unknown>): Promise<EveCommandSubmission>;
receipt(submission: Record<string, unknown>): Promise<unknown>;
}

View file

@ -50,6 +50,13 @@ export class EveCultMeshProviderClient {
return this.#document(schemaId, recordRef, "embedded-document");
}
async resolveDocument(request) {
const documentId = String(request?.documentId || request?.recordRef || "").trim();
const schemaId = String(request?.schemaId || "").trim();
if (!documentId || !schemaId) throw new Error("Embedded documents require documentId and schemaId.");
return { documentId, schemaId, document: await this.document({ schemaId, recordRef: documentId }) };
}
async submitCommand(request) {
const advertisement = await this.providerAdvertisement();
const surface = selectSurface(advertisement, request?.surfaceId);

View file

@ -16,7 +16,7 @@ function harness() {
const sent = [];
const connections = [];
const encoded = [];
const records = new Map([["records/provider", advertisement], ["records/world", surface], ["records/receipts:cmd-1", ["gamecult.eve.command_receipt.v1", "receipt-1", "cmd-1", "move", "accepted", "Provider", "daemon", "test-provider", "world", "moved", "now", 4]]]);
const records = new Map([["records/provider", advertisement], ["records/world", surface], ["records/objects", { entities: [1] }], ["records/receipts:cmd-1", ["gamecult.eve.command_receipt.v1", "receipt-1", "cmd-1", "move", "accepted", "Provider", "daemon", "test-provider", "world", "moved", "now", 4]]]);
const peer = { send: message => sent.push(message), close() {}, on() {} };
const mesh = {
createPeerCatalog: () => ({ upsert() {} }), createAuthorityLeaseCatalog: () => ({ upsert() {} }),
@ -60,6 +60,13 @@ test("submits at the advertised command boundary and reads the advertised receip
});
});
test("resolves embedded documents without provider-specific slot logic", async () => {
const { client } = harness();
assert.deepEqual(await client.resolveDocument({ documentId: "records/objects", schemaId: "test.objects.v1" }), {
documentId: "records/objects", schemaId: "test.objects.v1", document: { entities: [1] },
});
});
test("refuses unadvertised surfaces", async () => {
const { client } = harness();
await assert.rejects(() => client.surface("missing"), /does not advertise/);