Add TS CultMesh catalog factories

This commit is contained in:
Meta Vens 2026-06-16 16:18:08 +01:00
commit da48d58df7
5 changed files with 126 additions and 2 deletions

View file

@ -46,8 +46,29 @@ leases.upsert({
expiresAt: new Date(Date.now() + 60_000),
});
stopWatchingLeases();
const schemas = CultMesh.createBuiltInSchemaCatalog();
const shardCatalogRequest = schemas.get("cultnet.shard_catalog_request.v0");
const shards = CultMesh.createShardCatalog();
shards.upsert({
shardId: "notes-a",
ownerRuntimeId: "ts-peer",
epoch: 1,
schemaIds: ["cultmesh.note.v0"],
keyPrefix: "note:",
});
const noteShards = shards.list({
schemaIds: ["cultmesh.note.v0"],
recordKeys: ["note:intro"],
});
```
Schema and shard catalog factories delegate to `cultnet-ts`; the branded
`CultMesh` entrypoint does not create a second owner for schema discovery or
topology truth.
## Streaming Mode
CultMesh streaming mode is for audio, video, tensor, and opaque byte frames that

View file

@ -7,8 +7,12 @@ import {
} from "cultcache-ts";
import {
CultNetDocumentRegistry,
CultNetSchemaCatalog,
CultNetShardCatalog,
cultNetBuiltinSchemaRegistry,
defineCultNetDocumentBinding,
type CultNetDocumentBinding,
type CultNetSchemaCatalogOptions,
} from "cultnet-ts";
export interface CultMeshNodeOptions {
@ -470,6 +474,28 @@ export class CultMesh {
public static createStreamCatalog(): CultMeshStreamCatalog {
return new CultMeshStreamCatalog();
}
public static createSchemaCatalog(): CultNetSchemaCatalog {
return new CultNetSchemaCatalog();
}
public static createBuiltInSchemaCatalog(
options: CultNetSchemaCatalogOptions = {},
): CultNetSchemaCatalog {
const catalog = new CultNetSchemaCatalog();
catalog.applyResponse(cultNetBuiltinSchemaRegistry.createCatalogResponse({
schemaVersion: "cultnet.schema_catalog_request.v0",
messageId: "cultmesh-ts-builtins",
includeSchemaJson: options.includeSchemaJson,
schemaIds: options.schemaIds ? [...options.schemaIds] : undefined,
kinds: options.kinds ? [...options.kinds] : undefined,
}));
return catalog;
}
public static createShardCatalog(): CultNetShardCatalog {
return new CultNetShardCatalog();
}
}
function requireNonEmpty(value: string, name: string): void {

View file

@ -115,6 +115,79 @@ test("CultMesh TS local Verse catalog exposes sorted views and watch ergonomics"
);
});
test("CultMesh TS branded facade exposes schema and shard catalogs", () => {
const schemaCatalog = CultMesh.createSchemaCatalog();
const schemaUpdates: string[] = [];
const unsubscribeSchema = schemaCatalog.watch((descriptor) => {
schemaUpdates.push(descriptor.schemaId);
});
schemaCatalog.upsert({
schemaId: "cultmesh.ts.note.v1",
kind: "document_payload",
documentType: "cultmesh.ts-note",
wireContracts: ["cultnet.schema.v0"],
contentHash: "note-hash",
});
unsubscribeSchema();
schemaCatalog.upsert({
schemaId: "cultmesh.ts.other.v1",
kind: "document_payload",
documentType: "cultmesh.ts-other",
wireContracts: ["cultnet.schema.v0"],
contentHash: "other-hash",
});
assert.deepEqual(schemaUpdates, ["cultmesh.ts.note.v1"]);
assert.equal(
schemaCatalog.get("cultmesh.ts.note.v1")?.documentType,
"cultmesh.ts-note",
);
const builtIns = CultMesh.createBuiltInSchemaCatalog();
assert.equal(
builtIns.get("cultnet.shard_catalog_request.v0")?.schemaVersion,
"cultnet.shard_catalog_request.v0",
);
assert.equal(
builtIns.get("cultnet.shard_catalog_response.v0")?.kind,
"wire_message",
);
assert.equal(
builtIns.get(
"https://github.com/GameCult/cultnet-ts/contracts/cultnet.transport-profile.schema.json",
)?.schemaVersion,
"cultnet.transport_profile.v0",
);
const shardCatalog = CultMesh.createShardCatalog();
const shardUpdates: string[] = [];
const unsubscribeShard = shardCatalog.watch((descriptor) => {
shardUpdates.push(descriptor.shardId);
});
shardCatalog.upsert({
shardId: "notes-a",
ownerRuntimeId: "ts-runtime",
epoch: 7,
schemaIds: ["cultmesh.ts.note.v1"],
keyPrefix: "note:",
});
unsubscribeShard();
shardCatalog.upsert({
shardId: "notes-b",
ownerRuntimeId: "ts-runtime",
epoch: 8,
});
assert.deepEqual(shardUpdates, ["notes-a"]);
assert.equal(shardCatalog.get("notes-a")?.ownerRuntimeId, "ts-runtime");
assert.deepEqual(
shardCatalog
.list({ schemaIds: ["cultmesh.ts.note.v1"], recordKeys: ["note:1"] })
.map((shard) => shard.shardId),
["notes-a"],
);
});
test("CultMesh TS negotiates streaming frame body transports explicitly", () => {
const streams = CultMesh.createStreamCatalog();
const streamUpdates: string[] = [];