Skip to content

Commit bbfc3d2

Browse files
committed
EntitySpec Interface can return a schema
1 parent 3b75c34 commit bbfc3d2

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

java/arcs/core/storage/api/Entity.kt

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ package arcs.core.storage.api
1313

1414
import arcs.core.common.Referencable
1515
import arcs.core.data.RawEntity
16+
import arcs.core.data.Schema
1617
import arcs.core.data.util.ReferencablePrimitive
1718
import kotlin.IllegalArgumentException
1819
import kotlin.reflect.KClass
@@ -38,6 +39,9 @@ interface EntitySpec<T : Entity> {
3839
* TODO: replace this with kotlinx.serialization
3940
*/
4041
fun deserialize(data: RawEntity): T
42+
43+
/** Returns the corresponding [Schema] for the specified [Entity]. */
44+
fun schema(): Schema
4145
}
4246

4347
/**

src/tools/schema2kotlin.ts

+2
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ ${this.opts.wasm ? '' : `\
315315
SchemaRegistry.register(schema)
316316
}
317317
}
318+
319+
override fun schema() = schema
318320
`}
319321
override fun create() = ${name}()
320322
${!this.opts.wasm ? `

src/tools/tests/goldens/generated-schemas.jvm.kt

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class GoldInternal1_Spec() : EntitySpec<GoldInternal1> {
8787
}
8888
}
8989

90+
override fun schema() = schema
91+
9092
override fun create() = GoldInternal1()
9193

9294
override fun deserialize(data: RawEntity): GoldInternal1 {
@@ -215,6 +217,8 @@ class Gold_Data_Spec() : EntitySpec<Gold_Data> {
215217
}
216218
}
217219

220+
override fun schema() = schema
221+
218222
override fun create() = Gold_Data()
219223

220224
override fun deserialize(data: RawEntity): Gold_Data {

0 commit comments

Comments
 (0)