Skip to content

Commit 9cbbfc3

Browse files
authored
Merge pull request #12 from bee-produced/11-bee-persistent-blaze
Better alternatives to entity graph: `bee.persistent.blaze`
2 parents 3563d84 + a6f76fe commit 9cbbfc3

File tree

114 files changed

+10651
-494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+10651
-494
lines changed

.github/workflows/github-actions.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- name: Make gradlew executable
2222
run: |
2323
chmod +x ./bee.persistent/gradlew
24+
chmod +x ./bee.persistent.test/gradlew
2425
chmod +x ./bee.functional/gradlew
2526
chmod +x ./bee.functional.test/gradlew
2627
chmod +x ./bee.buzz/gradlew
@@ -31,6 +32,9 @@ jobs:
3132
- name: Build & Test bee.persistent
3233
working-directory: ./bee.persistent
3334
run: ./gradlew build
35+
- name: Test bee.persistent.blaze
36+
working-directory: ./bee.persistent.test
37+
run: ./gradlew build
3438
- name: Build & Test bee.generative
3539
working-directory: ./bee.generative
3640
run: ./gradlew build

README.md

+3-10
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,10 @@ An example project showcasing `bee-built` can be found under [example](./example
1414

1515
### Modules
1616

17-
Extend DGS:
18-
19-
* `bee.fetched`
20-
Automatically generate nested data fetchers for usage with data loaders, [documentation](./bee.fetched/README.md)
21-
22-
---
23-
24-
Some changes are currently being made:
25-
2617
* `bee.persistent`
27-
Easier data handling for GraphQL + JPA, [documentation](./bee.persistent/README.md)
18+
Easier data handling for GraphQL + JPA, [choose implementation](./bee.persistent/README.md)
19+
* `bee.fetched`
20+
Automatically generate nested data fetchers for usage with data loaders in DGS, [documentation](./bee.fetched/README.md)
2821
* `bee.functional`
2922
Functional Kotlin bindings, integration with DGS, `bee.persistent` & more, [documentation](./bee.functional/README.md)
3023
* `bee.buzz`

bee.fetched/src/processor/kotlin/com/beeproduced/bee/fetched/codegen/BeeFetchedCodegen.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.beeproduced.bee.fetched.codegen.BeeFetchedCodegen.PoetConstants._PROP
1010
import com.beeproduced.bee.fetched.codegen.BeeFetchedCodegen.PoetConstants.__DATA_LOADER_NAME
1111
import com.beeproduced.bee.fetched.codegen.BeeFetchedCodegen.PoetConstants.__DTO_NAME
1212
import com.beeproduced.bee.generative.util.*
13+
import com.beeproduced.bee.generative.util.PoetMap.Companion.addNStatementBuilder
1314
import com.google.devtools.ksp.processing.CodeGenerator
1415
import com.google.devtools.ksp.processing.Dependencies
1516
import com.google.devtools.ksp.processing.KSPLogger
@@ -45,7 +46,7 @@ class BeeFetchedCodegen(
4546
private lateinit var typedInternals: Map<String, List<FetcherInternalTypeDefinition>>
4647
private lateinit var typedSafeModeOverrides: Map<String, List<FetcherSafeModeOverrideDefinition>>
4748

48-
private val poetMap: PoetMap = mutableMapOf()
49+
private val poetMap: PoetMap = PoetMap()
4950
private fun FunSpec.Builder.addNStatement(format: String)
5051
= addNStatementBuilder(format, poetMap)
5152
@Suppress("ConstPropertyName")

bee.generative/src/main/kotlin/com/beeproduced/bee/generative/BeeGenerativePlugin.kt

+28-3
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,40 @@ open class BeeDependencies(private val dependencies: DependencyHandler) {
3030
val main = dependencies.add("implementation", dependencyNotation)
3131
val processorMain = dependencies.add("ksp", dependencyNotation)
3232
val processorCapability = dependencies.add("ksp", dependencyNotation, closureOf<DefaultExternalModuleDependency> {
33-
val capabilityNotation = if (version != null) {
34-
"$group:$name-processor:$version"
35-
} else "$group:$name-processor"
33+
val capabilityNotation = "$group:$name-processor${versionString(version)}"
3634
capabilities {
3735
requireCapability(capabilityNotation)
3836
}
3937
})
4038
return Triple(main, processorMain, processorCapability)
4139
}
40+
41+
operator fun invoke(dependencyNotation: String, capability: String): Triple<Dependency?, Dependency?, Dependency?> {
42+
val capabilityMain = dependencies.add("implementation", dependencyNotation, closureOf<DefaultExternalModuleDependency> {
43+
val capabilityNotation = "$group:$name-$capability${versionString(version)}"
44+
capabilities {
45+
requireCapability(capabilityNotation)
46+
}
47+
})
48+
val processorMain = dependencies.add("ksp", dependencyNotation, closureOf<DefaultExternalModuleDependency> {
49+
val capabilityNotation = "$group:$name-$capability${versionString(version)}"
50+
capabilities {
51+
requireCapability(capabilityNotation)
52+
}
53+
})
54+
val processorCapability = dependencies.add("ksp", dependencyNotation, closureOf<DefaultExternalModuleDependency> {
55+
val capabilityNotation = "$group:$name-$capability-processor${versionString(version)}"
56+
capabilities {
57+
requireCapability(capabilityNotation)
58+
}
59+
})
60+
return Triple(capabilityMain, processorMain, processorCapability)
61+
}
62+
63+
private fun versionString(version: String?): String {
64+
return if (version == null) ""
65+
else ":$version"
66+
}
4267
}
4368

4469
class BeeGenerativePlugin : Plugin<Project>{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
package com.beeproduced.bee.generative.util
2+
3+
/**
4+
*
5+
*
6+
* @author Kacper Urbaniec
7+
* @version 2023-12-16
8+
*/
9+
10+
11+
import com.google.devtools.ksp.symbol.*
12+
13+
object DummyKsp {
14+
val propertyDeclaration = DummyKSPropertyDeclaration()
15+
val type = DummyKSType()
16+
}
17+
18+
class DummyKSPropertyDeclaration : KSPropertyDeclaration {
19+
override val annotations: Sequence<KSAnnotation>
20+
get() = emptySequence() // Empty sequence for dummy implementation
21+
22+
override val containingFile: KSFile?
23+
get() = null // Null for dummy implementation
24+
25+
override val docString: String?
26+
get() = null // Null for dummy implementation
27+
28+
override val extensionReceiver: KSTypeReference?
29+
get() = null // Null for dummy implementation
30+
31+
override val getter: KSPropertyGetter?
32+
get() = null // Null for dummy implementation
33+
34+
override val hasBackingField: Boolean
35+
get() = false // Default to false
36+
37+
override val isActual: Boolean
38+
get() = false // Default to false
39+
40+
override val isExpect: Boolean
41+
get() = false // Default to false
42+
43+
override val isMutable: Boolean
44+
get() = false // Default to false
45+
46+
override val location: Location
47+
get() = NonExistLocation // Using Location.None for simplicity
48+
49+
override val modifiers: Set<Modifier>
50+
get() = emptySet() // Empty set for dummy implementation
51+
52+
override val origin: Origin
53+
get() = Origin.SYNTHETIC // Using SYNTHETIC for dummy implementation
54+
55+
override val packageName: KSName
56+
get() = DummyKSName()
57+
58+
override val parent: KSNode?
59+
get() = null // Null for dummy implementation
60+
61+
override val parentDeclaration: KSDeclaration?
62+
get() = null // Null for dummy implementation
63+
64+
override val qualifiedName: KSName?
65+
get() = DummyKSName()
66+
67+
override val setter: KSPropertySetter?
68+
get() = null // Null for dummy implementation
69+
70+
override val simpleName: KSName
71+
get() = DummyKSName()
72+
73+
override val type: KSTypeReference
74+
get() = DummyKSTypeReference() // A dummy type reference
75+
76+
override val typeParameters: List<KSTypeParameter>
77+
get() = emptyList() // Empty list for dummy implementation
78+
79+
override fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R {
80+
throw NotImplementedError("Dummy implementation does not support this method.")
81+
}
82+
83+
override fun asMemberOf(containing: KSType): KSType {
84+
throw NotImplementedError("Dummy implementation does not support this method.")
85+
}
86+
87+
override fun findActuals(): Sequence<KSDeclaration> {
88+
return emptySequence() // Empty sequence for dummy implementation
89+
}
90+
91+
override fun findExpects(): Sequence<KSDeclaration> {
92+
return emptySequence() // Empty sequence for dummy implementation
93+
}
94+
95+
override fun findOverridee(): KSPropertyDeclaration? {
96+
return null // Null for dummy implementation
97+
}
98+
99+
override fun isDelegated(): Boolean {
100+
return false // Default to false
101+
}
102+
}
103+
104+
class DummyKSName : KSName {
105+
override fun asString(): String = ""
106+
107+
override fun getQualifier(): String = ""
108+
109+
override fun getShortName(): String = ""
110+
}
111+
112+
class DummyKSTypeReference : KSTypeReference {
113+
override val annotations: Sequence<KSAnnotation>
114+
get() = emptySequence()
115+
116+
override val element: KSReferenceElement
117+
get() = throw NotImplementedError("Dummy implementation does not support this property.")
118+
override val location: Location
119+
get() = NonExistLocation
120+
override val modifiers: Set<Modifier>
121+
get() = emptySet()
122+
123+
override val origin: Origin
124+
get() = Origin.SYNTHETIC
125+
126+
override val parent: KSNode?
127+
get() = null
128+
129+
override fun resolve(): KSType {
130+
throw NotImplementedError("Dummy implementation does not support this method.")
131+
}
132+
133+
override fun <D, R> accept(visitor: KSVisitor<D, R>, data: D): R {
134+
throw NotImplementedError("Dummy implementation does not support this method.")
135+
}
136+
}
137+
138+
class DummyKSType : KSType {
139+
override val annotations: Sequence<KSAnnotation>
140+
get() = emptySequence()
141+
override val arguments: List<KSTypeArgument>
142+
get() = emptyList()
143+
override val declaration: KSDeclaration
144+
get() = TODO("Not yet implemented")
145+
override val isError: Boolean
146+
get() = false
147+
override val isFunctionType: Boolean
148+
get() = false
149+
override val isMarkedNullable: Boolean
150+
get() = false
151+
override val isSuspendFunctionType: Boolean
152+
get() = false
153+
override val nullability: Nullability
154+
get() = Nullability.NOT_NULL
155+
156+
override fun isAssignableFrom(that: KSType): Boolean = false
157+
158+
override fun isCovarianceFlexible(): Boolean = false
159+
160+
override fun isMutabilityFlexible(): Boolean = false
161+
162+
override fun makeNotNullable(): KSType = DummyKSType()
163+
164+
override fun makeNullable(): KSType = DummyKSType()
165+
166+
override fun replace(arguments: List<KSTypeArgument>): KSType = DummyKSType()
167+
168+
override fun starProjection(): KSType = DummyKSType()
169+
170+
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.beeproduced.bee.generative.util
22

3-
import com.squareup.kotlinpoet.FunSpec
3+
import com.squareup.kotlinpoet.*
44

55
/**
66
*
@@ -9,28 +9,66 @@ import com.squareup.kotlinpoet.FunSpec
99
* @version 2023-10-15
1010
*/
1111

12-
typealias PoetMap = MutableMap<String, Any>
12+
class PoetMap {
13+
private val poetMappings = mutableMapOf<String, Any>()
14+
private val originalMappings = mutableMapOf<String, Any>()
15+
private val literalMappings = mutableMapOf<String, String>()
16+
private val stringMappings = mutableMapOf<String, String>()
17+
private val classMappings = mutableMapOf<String, ClassName>()
1318

14-
fun PoetMap.addMapping(key: String, mapping: Any) {
15-
put(mappingKey(key), mapping)
16-
}
19+
val args get(): Map<String, Any> = poetMappings
20+
val mappings get(): Map<String, Any> = originalMappings
1721

18-
fun PoetMap.addMappings(map: Map<String, Any>) {
19-
map
20-
.mapKeys { (k) -> mappingKey(k) }
21-
.let { m -> putAll(m) }
22-
}
22+
fun literalMapping(key: String) = literalMappings.getValue(key)
23+
fun stringMapping(key: String) = stringMappings.getValue(key)
24+
fun classMapping(key: String) = classMappings.getValue(key)
25+
26+
fun addMapping(key: String, mapping: Any) {
27+
originalMappings[key] = mapping
28+
addSpecialisedMapping(key, mapping)
29+
poetMappings[mappingKey(key)] = mapping
30+
}
31+
32+
fun addMappings(map: Map<String, Any>) {
33+
originalMappings.putAll(map)
34+
map.forEach(::addSpecialisedMapping)
35+
map
36+
.mapKeys { (k) -> mappingKey(k) }
37+
.let { m -> poetMappings.putAll(m) }
38+
}
39+
40+
private fun addSpecialisedMapping(key: String, mapping: Any) {
41+
if (key.endsWith(":L") && mapping is String) literalMappings[key] = mapping
42+
else if (key.endsWith(":S") && mapping is String) stringMappings[key] = mapping
43+
else if (key.endsWith(":T") && mapping is ClassName) classMappings[key] = mapping
44+
}
45+
46+
private fun mappingKey(input: String): String {
47+
// Check if the string starts with "%" and remove it if true
48+
val withoutPrefix = if (input.startsWith("%")) input.substring(1) else input
49+
// Check if the string has a ":" followed by another character and remove them if true
50+
return if (withoutPrefix.contains(":")) withoutPrefix.substring(
51+
0,
52+
withoutPrefix.lastIndexOf(":")
53+
) else withoutPrefix
54+
}
2355

24-
fun FunSpec.Builder.addNStatementBuilder(format: String, map: PoetMap): FunSpec.Builder {
25-
return addNamedCode(format, map).addStatement("")
56+
companion object {
57+
fun FunSpec.Builder.addNStatementBuilder(format: String, map: PoetMap): FunSpec.Builder {
58+
return addNamedCode(format, map.args).addStatement("")
59+
}
60+
61+
fun CodeBlock.Builder.addNStatementBuilder(format: String, map: PoetMap): CodeBlock.Builder {
62+
return addNamed(format, map.args).addStatement("")
63+
}
64+
65+
fun FileSpec.Builder.addNStatementBuilder(format: String, map: PoetMap): FileSpec.Builder {
66+
return addStatement(format, map.args).addStatement("")
67+
}
68+
}
2669
}
2770

28-
private fun mappingKey(input: String): String {
29-
// Check if the string starts with "%" and remove it if true
30-
val withoutPrefix = if (input.startsWith("%")) input.substring(1) else input
31-
// Check if the string has a ":" followed by another character and remove them if true
32-
return if (withoutPrefix.contains(":")) withoutPrefix.substring(
33-
0,
34-
withoutPrefix.lastIndexOf(":")
35-
) else withoutPrefix
36-
}
71+
72+
73+
74+

0 commit comments

Comments
 (0)