diff --git a/packages/cultmesh-kotlin/README.md b/packages/cultmesh-kotlin/README.md index 79d86db6..a4fde508 100644 --- a/packages/cultmesh-kotlin/README.md +++ b/packages/cultmesh-kotlin/README.md @@ -15,6 +15,7 @@ val peers = CultMesh.createPeerCatalog() val leases = CultMesh.createAuthorityLeaseCatalog() val streams = CultMesh.createStreamCatalog() val schemas = CultMesh.createSchemaCatalog() +val builtIns = CultMesh.createBuiltInSchemaCatalog(kinds = listOf("shared_contract")) val shards = CultMesh.createShardCatalog() ``` @@ -137,12 +138,13 @@ val response = catalog.createResponse( `cultnet.schema_catalog_response.v0` descriptors from other runtimes and keeps their content hashes, wire contracts, schema ids, and optional schema JSON. `CultMesh.createBuiltInSchemaCatalog(...)` returns the Kotlin-supported -CultNet/CultMesh wire-message descriptors on the same catalog surface, including -schema catalog, shard catalog, shard log, Verse catalog, peer exchange, and the -shared transport profile contract. Descriptors for shared schema files keep the -canonical schema ids and content hashes; Kotlin-local descriptor bodies use -schema-version ids until shared schema files exist. Inline schema JSON is opt-in -and only emitted for descriptor bodies Kotlin owns. +CultNet/CultMesh descriptors on the same catalog surface, with optional +`schemaIds`, `kinds`, and inline-schema filters. It includes schema catalog, +shard catalog, shard log, Verse catalog, peer exchange, and the shared transport +profile contract. Descriptors for shared schema files keep the canonical schema +ids and content hashes; Kotlin-local descriptor bodies use schema-version ids +until shared schema files exist. Inline schema JSON is opt-in and only emitted +for descriptor bodies Kotlin owns. Shard catalogs and shard-log responses use the same schema-v0 lane: diff --git a/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/CultMesh.kt b/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/CultMesh.kt index ab8a0b97..b5181c2e 100644 --- a/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/CultMesh.kt +++ b/packages/cultmesh-kotlin/src/main/kotlin/org/gamecult/cultmesh/CultMesh.kt @@ -287,8 +287,15 @@ object CultMesh { fun createSchemaCatalog(): CultNetSchemaCatalog = CultNetSchemaCatalog() - fun createBuiltInSchemaCatalog(includeSchemaJson: Boolean = false): CultNetSchemaCatalog = - cultNetBuiltInSchemaCatalog(includeSchemaJson) + fun createBuiltInSchemaCatalog( + includeSchemaJson: Boolean = false, + schemaIds: List = emptyList(), + kinds: List = emptyList(), + ): CultNetSchemaCatalog = cultNetBuiltInSchemaCatalog( + includeSchemaJson = includeSchemaJson, + schemaIds = schemaIds, + kinds = kinds, + ) fun createShardCatalog(): CultNetShardCatalog = CultNetShardCatalog() @@ -1086,9 +1093,18 @@ private val cultNetBuiltInSchemaSpecs = listOf( ), ) -fun cultNetBuiltInSchemaCatalog(includeSchemaJson: Boolean = false): CultNetSchemaCatalog { +fun cultNetBuiltInSchemaCatalog( + includeSchemaJson: Boolean = false, + schemaIds: List = emptyList(), + kinds: List = emptyList(), +): CultNetSchemaCatalog { val catalog = CultNetSchemaCatalog() - cultNetBuiltInSchemaSpecs.forEach { spec -> + val requestedSchemaIds = schemaIds.toSet() + val requestedKinds = kinds.toSet() + cultNetBuiltInSchemaSpecs.filter { spec -> + (requestedSchemaIds.isEmpty() || spec.schemaId in requestedSchemaIds) && + (requestedKinds.isEmpty() || spec.kind in requestedKinds) + }.forEach { spec -> val schemaJson = cultNetBuiltInSchemaJson(spec, spec.schemaId) val inlineSchemaJson = if (spec.contentHash == null && includeSchemaJson) schemaJson else null catalog.upsert( @@ -3192,6 +3208,19 @@ private fun cultNetBuiltInSchemaCatalogAdvertisesWireContracts() { check(transportProfile["contentHash"] == "84473264f543ca3443267999e43d72b7993b61b7b2ac53c642c9cbe8b6de0217") check(!transportProfile.containsKey("schemaJson")) + val filteredTransportCatalog = CultMesh.createBuiltInSchemaCatalog( + includeSchemaJson = true, + schemaIds = listOf("$cultNetSchemaBase/cultnet.transport-profile.schema.json"), + ) + check(filteredTransportCatalog.schemas.single().schemaVersion == "cultnet.transport_profile.v0") + val filteredSharedContracts = CultMesh.createBuiltInSchemaCatalog(kinds = listOf("shared_contract")) + check(filteredSharedContracts.schemas.single().schemaId == "$cultNetSchemaBase/cultnet.transport-profile.schema.json") + val filteredInlineCatalog = CultMesh.createBuiltInSchemaCatalog( + includeSchemaJson = true, + schemaIds = listOf("cultmesh.peer_exchange_request.v0"), + ) + check(filteredInlineCatalog.schemas.single().schemaJson?.contains("cultmesh.peer_exchange_request.v0") == true) + val inlineResponse = inlineCatalog.createResponse( cultNetSchemaCatalogRequest( messageId = "kotlin-builtins-inline",