Skip to content

Commit dcefb16

Browse files
committed
Generation adds to schema registry
1 parent f3b9ae5 commit dcefb16

File tree

4 files changed

+91
-9
lines changed

4 files changed

+91
-9
lines changed

java/arcs/core/data/SchemaRegistry.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package arcs.core.data
2+
3+
object SchemaRegistry {
4+
var schemas: MutableMap<String, Schema> = mutableMapOf()
5+
}

src/tools/schema2kotlin.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,9 @@ package ${this.scope}
5454
// Current implementation doesn't support references or optional field detection
5555
5656
import arcs.sdk.*
57+
import arcs.sdk.Entity
5758
import arcs.core.data.*
5859
${this.opts.wasm ? 'import arcs.sdk.wasm.*' : 'import arcs.core.storage.api.toPrimitiveValue\nimport arcs.core.data.RawEntity\nimport arcs.core.data.util.toReferencable\nimport arcs.core.data.util.ReferencablePrimitive'}
59-
60-
object SchemaRegistry {
61-
var schemas: Map<String, Schema> = mutableMapOf()
62-
}
6360
`;
6461
}
6562

@@ -299,11 +296,13 @@ ${this.opts.wasm ? `
299296
300297
class ${name}_Spec() : ${this.getType('EntitySpec')}<${name}> {
301298
302-
init {
303-
SchemaRegistry.schemas += mapOf(
304-
"${schemaHash}" to
305-
${this.leftPad(this.createSchema(schemaHash), 12)}
306-
)
299+
companion object {
300+
init {
301+
SchemaRegistry.schemas.plusAssign(mapOf(
302+
"${schemaHash}" to
303+
${this.leftPad(this.createSchema(schemaHash), 16)}
304+
))
305+
}
307306
}
308307
309308
override fun create() = ${name}()

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ package arcs.sdk
99
// Current implementation doesn't support references or optional field detection
1010

1111
import arcs.sdk.*
12+
import arcs.sdk.Entity
13+
import arcs.core.data.*
1214
import arcs.core.storage.api.toPrimitiveValue
1315
import arcs.core.data.RawEntity
1416
import arcs.core.data.util.toReferencable
@@ -69,8 +71,25 @@ class GoldInternal1() : Entity {
6971
override fun toString() = "GoldInternal1(val_ = $val_)"
7072
}
7173

74+
7275
class GoldInternal1_Spec() : EntitySpec<GoldInternal1> {
7376

77+
companion object {
78+
init {
79+
SchemaRegistry.schemas.plusAssign(mapOf(
80+
"485712110d89359a3e539dac987329cd2649d889" to
81+
Schema(
82+
listOf(),
83+
SchemaFields(
84+
singletons = mapOf("val" to FieldType.Text),
85+
collections = emptyMap()
86+
),
87+
"485712110d89359a3e539dac987329cd2649d889"
88+
)
89+
))
90+
}
91+
}
92+
7493
override fun create() = GoldInternal1()
7594

7695
override fun deserialize(data: RawEntity): GoldInternal1 {
@@ -177,8 +196,28 @@ class Gold_Data() : Entity {
177196
override fun toString() = "Gold_Data(num = $num, txt = $txt, lnk = $lnk, flg = $flg)"
178197
}
179198

199+
180200
class Gold_Data_Spec() : EntitySpec<Gold_Data> {
181201

202+
companion object {
203+
init {
204+
SchemaRegistry.schemas.plusAssign(mapOf(
205+
"d8058d336e472da47b289eafb39733f77eadb111" to
206+
Schema(
207+
listOf(),
208+
SchemaFields(
209+
singletons = mapOf("num" to FieldType.Number,
210+
"txt" to FieldType.Text,
211+
"lnk" to FieldType.Text,
212+
"flg" to FieldType.Boolean),
213+
collections = emptyMap()
214+
),
215+
"d8058d336e472da47b289eafb39733f77eadb111"
216+
)
217+
))
218+
}
219+
}
220+
182221
override fun create() = Gold_Data()
183222

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

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ package arcs.sdk
99
// Current implementation doesn't support references or optional field detection
1010

1111
import arcs.sdk.*
12+
import arcs.sdk.Entity
13+
import arcs.core.data.*
1214
import arcs.sdk.wasm.*
1315

1416
class GoldInternal1() : WasmEntity {
@@ -66,8 +68,25 @@ class GoldInternal1() : WasmEntity {
6668
override fun toString() = "GoldInternal1(val_ = $val_)"
6769
}
6870

71+
6972
class GoldInternal1_Spec() : WasmEntitySpec<GoldInternal1> {
7073

74+
companion object {
75+
init {
76+
SchemaRegistry.schemas.plusAssign(mapOf(
77+
"485712110d89359a3e539dac987329cd2649d889" to
78+
Schema(
79+
listOf(),
80+
SchemaFields(
81+
singletons = mapOf("val" to FieldType.Text),
82+
collections = emptyMap()
83+
),
84+
"485712110d89359a3e539dac987329cd2649d889"
85+
)
86+
))
87+
}
88+
}
89+
7190
override fun create() = GoldInternal1()
7291

7392

@@ -201,8 +220,28 @@ class Gold_Data() : WasmEntity {
201220
override fun toString() = "Gold_Data(num = $num, txt = $txt, lnk = $lnk, flg = $flg)"
202221
}
203222

223+
204224
class Gold_Data_Spec() : WasmEntitySpec<Gold_Data> {
205225

226+
companion object {
227+
init {
228+
SchemaRegistry.schemas.plusAssign(mapOf(
229+
"d8058d336e472da47b289eafb39733f77eadb111" to
230+
Schema(
231+
listOf(),
232+
SchemaFields(
233+
singletons = mapOf("num" to FieldType.Number,
234+
"txt" to FieldType.Text,
235+
"lnk" to FieldType.Text,
236+
"flg" to FieldType.Boolean),
237+
collections = emptyMap()
238+
),
239+
"d8058d336e472da47b289eafb39733f77eadb111"
240+
)
241+
))
242+
}
243+
}
244+
206245
override fun create() = Gold_Data()
207246

208247

0 commit comments

Comments
 (0)