Skip to content

Commit

Permalink
Work on Pocketbase support
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeis committed Nov 17, 2023
1 parent f7870b4 commit d89eb05
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 56 deletions.
123 changes: 69 additions & 54 deletions ee-design/src/main/kotlin/ee/design/gen/go/DesignGoGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,16 @@ open class DesignGoGenerator(private val models: List<StructureUnitI<*>>,
companion object {
fun buildGoTemplates() = DesignGoTemplates(itemNameAsGoFileName)


fun buildSwaggerContextFactory() = DesignSwaggerContextFactory()
fun buildSwaggerTemplates() = DesignSwaggerTemplates(itemNameAsSwaggerFileName)
}

init {
models.extendForGoGeneration()
}

constructor(model: StructureUnitI<*>, targetAsSingleModule: Boolean = true) :
this(listOf(model), targetAsSingleModule)

fun generate(
target: Path,
generatorContexts: GeneratorContexts<StructureUnitI<*>> = go(),
generatorContexts: GeneratorContexts<StructureUnitI<*>> = goPocketBaseGeneration(),
shallSkip: GeneratorI<*>.(model: Any?) -> Boolean = { false }) {

models.forEach {
Expand All @@ -59,50 +54,9 @@ open class DesignGoGenerator(private val models: List<StructureUnitI<*>>,
}
}

private fun List<StructureUnitI<*>>.extendForGoGeneration() {
forEach {
it.extendForGoGeneration()
}
}

private fun StructureUnitI<*>.extendForGoGeneration() {
initsForGoGeneration()

addIdPropToEntityValues()

addIdPropToEntities()

addDeletedAtToEntities()

addCommandsAndEventsForAggregates()
open fun goPocketBaseGeneration(fileNamePrefix: String = ""): GeneratorContexts<StructureUnitI<*>> {

addQueriesForAggregates()

addAggregateHandler()

addDefaultReturnValuesForQueries()

addIdPropToCommands()

addIdPropToEvents()

addEsArtifacts()

renameArtifactsAccordingParentType()

//setOptionalTagToEventsAndCommandsProps()

//extendForGoGenerationLang()
declareAsBaseWithNonImplementedOperation()

prepareAttributesOfEnums()

defineSuperUnitsAsAnonymousProps()

defineConstructorNoProps { constructors().isEmpty() && this !is Generic && this !is CommandI<*> && this !is EventI<*>}
}

open fun go(fileNamePrefix: String = ""): GeneratorContexts<StructureUnitI<*>> {
models.extendForGoPocketBaseGeneration()

val goTemplates = buildGoTemplates()
val contextFactory = buildGoContextFactory()
Expand Down Expand Up @@ -278,6 +232,8 @@ open class DesignGoGenerator(private val models: List<StructureUnitI<*>>,

open fun goEventDriven(fileNamePrefix: String = ""): GeneratorContexts<StructureUnitI<*>> {

models.extendForGoEsGeneration()

val swaggerTemplates = buildSwaggerTemplates()
val swaggerContextFactory = buildSwaggerContextFactory()
val swaggerContextBuilder = swaggerContextFactory.build()
Expand Down Expand Up @@ -316,10 +272,6 @@ open class DesignGoGenerator(private val models: List<StructureUnitI<*>>,

val derivedTypes = mutableListOf(
"",
DesignDerivedType.Aggregate,
DesignDerivedType.AggregateEvents,
DesignDerivedType.AggregateCommands,
DesignDerivedType.Query,
DesignDerivedType.Http,
DesignDerivedType.Client,
DesignDerivedType.Cli,
Expand Down Expand Up @@ -400,7 +352,7 @@ open class DesignGoGenerator(private val models: List<StructureUnitI<*>>,
template = FragmentsTemplate(name = "${fileNamePrefix}${derivedType}ApiBase",
nameBuilder = itemAndTemplateNameAsGoFileName, fragments = {
listOf(
ItemsFragment(items = entities, fragments = { listOf(goTemplates.entity()) }),
ItemsFragment(items = entities, fragments = { listOf(goTemplates.entityEs()) }),
ItemsFragment(items = controllers, fragments = { listOf(goTemplates.pojo()) }),
ItemsFragment<StructureUnitI<*>, CompilationUnitI<*>>(items = values,
fragments = { listOf(goTemplates.pojo()) }),
Expand Down Expand Up @@ -460,6 +412,69 @@ open class DesignGoGenerator(private val models: List<StructureUnitI<*>>,
return GeneratorContexts(generator, swaggerContextBuilder, goContextBuilder)
}

private fun List<StructureUnitI<*>>.extendForGoPocketBaseGeneration() {
forEach {
it.extendForGoPocketBaseGeneration()
}
}

private fun StructureUnitI<*>.extendForGoPocketBaseGeneration() {
initsForGoGeneration()
//setOptionalTagToEventsAndCommandsProps()

//extendForGoGenerationLang()
declareAsBaseWithNonImplementedOperation()

prepareAttributesOfEnums()

defineSuperUnitsAsAnonymousProps()

defineConstructorNoProps { constructors().isEmpty() && this !is Generic && this !is CommandI<*> && this !is EventI<*>}
}

private fun List<StructureUnitI<*>>.extendForGoEsGeneration() {
forEach {
it.extendForGoEsGeneration()
}
}

private fun StructureUnitI<*>.extendForGoEsGeneration() {
initsForGoGeneration()

addIdPropToEntityValues()

addIdPropToEntities()

addDeletedAtToEntities()

addCommandsAndEventsForAggregates()

addQueriesForAggregates()

addAggregateHandler()

addDefaultReturnValuesForQueries()

addIdPropToCommands()

addIdPropToEvents()

addEsArtifacts()

renameArtifactsAccordingParentType()

//setOptionalTagToEventsAndCommandsProps()

//extendForGoGenerationLang()
declareAsBaseWithNonImplementedOperation()

prepareAttributesOfEnums()

defineSuperUnitsAsAnonymousProps()

defineConstructorNoProps { constructors().isEmpty() && this !is Generic && this !is CommandI<*> && this !is EventI<*>}
}

protected fun registerGoMacros(contextFactory: LangCommonContextFactory) {
val macros = contextFactory.macroController
macros.registerMacro(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ open class DesignGoTemplates(
Template("EventTypes", nameBuilder) { item, c -> item.toGoEventTypes(c) }

open fun <T : EntityI<*>> entity(nameBuilder: TemplateI<T>.(T) -> NamesI = defaultNameBuilder) =
Template("Entity", nameBuilder) { item, c -> item.toGoEntityImpl(c) }
Template("Entity", nameBuilder) { item, c -> item.toGoEntity(c) }

open fun <T : EntityI<*>> entityEs(nameBuilder: TemplateI<T>.(T) -> NamesI = defaultNameBuilder) =
Template("Entity", nameBuilder) { item, c -> item.toGoEntityEs(c) }

open fun stateHandler(nameBuilder: TemplateI<StateI<*>>.(StateI<*>) -> NamesI = defaultNameBuilder) =
Template("StateHandler", nameBuilder) { item, c -> item.toGoStateHandler(c) }
Expand Down
11 changes: 10 additions & 1 deletion ee-design/src/main/kotlin/ee/design/gen/go/GoEventDriven.kt
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,16 @@ fun <T : AttributeI<*>> T.toGoPropOptionalAfterBody(
): String = """`eh:"optional"`"""


fun <T : EntityI<*>> T.toGoEntityImpl(
fun <T : EntityI<*>> T.toGoEntity(
c: GenerationContext, derived: String = DesignDerivedKind.IMPL,
api: String = DesignDerivedKind.API
): String {
val name = c.n(this, derived)
return """
${toGoImpl(c, derived, api, true)}
"""
}
fun <T : EntityI<*>> T.toGoEntityEs(
c: GenerationContext, derived: String = DesignDerivedKind.IMPL,
api: String = DesignDerivedKind.API
): String {
Expand Down

0 comments on commit d89eb05

Please sign in to comment.