diff --git a/ee-design/src/main/kotlin/ee/design/gen/go/DesignGoGenerator.kt b/ee-design/src/main/kotlin/ee/design/gen/go/DesignGoGenerator.kt index b30b7bd..9c799d7 100644 --- a/ee-design/src/main/kotlin/ee/design/gen/go/DesignGoGenerator.kt +++ b/ee-design/src/main/kotlin/ee/design/gen/go/DesignGoGenerator.kt @@ -21,21 +21,16 @@ open class DesignGoGenerator(private val models: List>, 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> = go(), + generatorContexts: GeneratorContexts> = goPocketBaseGeneration(), shallSkip: GeneratorI<*>.(model: Any?) -> Boolean = { false }) { models.forEach { @@ -59,50 +54,9 @@ open class DesignGoGenerator(private val models: List>, } } - private fun List>.extendForGoGeneration() { - forEach { - it.extendForGoGeneration() - } - } - - private fun StructureUnitI<*>.extendForGoGeneration() { - initsForGoGeneration() - - addIdPropToEntityValues() - - addIdPropToEntities() - - addDeletedAtToEntities() - - addCommandsAndEventsForAggregates() + open fun goPocketBaseGeneration(fileNamePrefix: String = ""): GeneratorContexts> { - 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> { + models.extendForGoPocketBaseGeneration() val goTemplates = buildGoTemplates() val contextFactory = buildGoContextFactory() @@ -278,6 +232,8 @@ open class DesignGoGenerator(private val models: List>, open fun goEventDriven(fileNamePrefix: String = ""): GeneratorContexts> { + models.extendForGoEsGeneration() + val swaggerTemplates = buildSwaggerTemplates() val swaggerContextFactory = buildSwaggerContextFactory() val swaggerContextBuilder = swaggerContextFactory.build() @@ -316,10 +272,6 @@ open class DesignGoGenerator(private val models: List>, val derivedTypes = mutableListOf( "", - DesignDerivedType.Aggregate, - DesignDerivedType.AggregateEvents, - DesignDerivedType.AggregateCommands, - DesignDerivedType.Query, DesignDerivedType.Http, DesignDerivedType.Client, DesignDerivedType.Cli, @@ -400,7 +352,7 @@ open class DesignGoGenerator(private val models: List>, 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, CompilationUnitI<*>>(items = values, fragments = { listOf(goTemplates.pojo()) }), @@ -460,6 +412,69 @@ open class DesignGoGenerator(private val models: List>, return GeneratorContexts(generator, swaggerContextBuilder, goContextBuilder) } + private fun List>.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>.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( diff --git a/ee-design/src/main/kotlin/ee/design/gen/go/DesignGoTemplates.kt b/ee-design/src/main/kotlin/ee/design/gen/go/DesignGoTemplates.kt index 6f2f4a8..e7276c4 100644 --- a/ee-design/src/main/kotlin/ee/design/gen/go/DesignGoTemplates.kt +++ b/ee-design/src/main/kotlin/ee/design/gen/go/DesignGoTemplates.kt @@ -19,7 +19,10 @@ open class DesignGoTemplates( Template("EventTypes", nameBuilder) { item, c -> item.toGoEventTypes(c) } open fun > entity(nameBuilder: TemplateI.(T) -> NamesI = defaultNameBuilder) = - Template("Entity", nameBuilder) { item, c -> item.toGoEntityImpl(c) } + Template("Entity", nameBuilder) { item, c -> item.toGoEntity(c) } + + open fun > entityEs(nameBuilder: TemplateI.(T) -> NamesI = defaultNameBuilder) = + Template("Entity", nameBuilder) { item, c -> item.toGoEntityEs(c) } open fun stateHandler(nameBuilder: TemplateI>.(StateI<*>) -> NamesI = defaultNameBuilder) = Template("StateHandler", nameBuilder) { item, c -> item.toGoStateHandler(c) } diff --git a/ee-design/src/main/kotlin/ee/design/gen/go/GoEventDriven.kt b/ee-design/src/main/kotlin/ee/design/gen/go/GoEventDriven.kt index d06f39d..f9fb151 100644 --- a/ee-design/src/main/kotlin/ee/design/gen/go/GoEventDriven.kt +++ b/ee-design/src/main/kotlin/ee/design/gen/go/GoEventDriven.kt @@ -503,7 +503,16 @@ fun > T.toGoPropOptionalAfterBody( ): String = """`eh:"optional"`""" -fun > T.toGoEntityImpl( +fun > 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.toGoEntityEs( c: GenerationContext, derived: String = DesignDerivedKind.IMPL, api: String = DesignDerivedKind.API ): String {