diff --git a/webapi/src/main/scala/org/knora/webapi/slice/SliceModule.scala b/webapi/src/main/scala/org/knora/webapi/slice/SliceModule.scala new file mode 100644 index 0000000000..ec94317d10 --- /dev/null +++ b/webapi/src/main/scala/org/knora/webapi/slice/SliceModule.scala @@ -0,0 +1,19 @@ +/* + * Copyright © 2021 - 2024 Swiss National Data and Service Center for the Humanities and/or DaSCH Service Platform contributors. + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.knora.webapi.slice +import zio.ZLayer + +trait SliceModule[RIn, E, ROut] { + type Dependencies = RIn + type Provided = ROut + inline def layer: ZLayer[RIn, E, ROut] +} + +type RModule[RIn, ROut] = SliceModule[RIn, Throwable, ROut] +type URModule[RIn, ROut] = SliceModule[RIn, Nothing, ROut] +type Module[E, ROut] = SliceModule[Any, E, ROut] +type UModule[ROut] = SliceModule[Any, Nothing, ROut] +type TaskModule[ROut] = SliceModule[Any, Throwable, ROut] diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/AdminModule.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/AdminModule.scala index 767e1d3590..7f79e1caee 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/AdminModule.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/AdminModule.scala @@ -9,6 +9,7 @@ import zio.URLayer import org.knora.webapi.config.AppConfig import org.knora.webapi.responders.IriService +import org.knora.webapi.slice.URModule import org.knora.webapi.slice.admin.domain.AdminDomainModule import org.knora.webapi.slice.admin.domain.service.DspIngestClient import org.knora.webapi.slice.admin.repo.AdminRepoModule @@ -19,22 +20,22 @@ import org.knora.webapi.slice.ontology.repo.service.OntologyCache import org.knora.webapi.slice.resourceinfo.domain.IriConverter import org.knora.webapi.store.triplestore.api.TriplestoreService -object AdminModule { - - type Dependencies = - // format: off - AppConfig & - CacheManager & - DspIngestClient & - IriService & - IriConverter & - OntologyRepo & - OntologyCache & - PredicateObjectMapper & - TriplestoreService - // format: on - - type Provided = AdminDomainModule.Provided - - val layer: URLayer[Dependencies, Provided] = AdminRepoModule.layer >>> AdminDomainModule.layer +object AdminModule + extends URModule[ + // format: off + AppConfig & + CacheManager & + DspIngestClient & + IriConverter & + IriService & + OntologyCache & + OntologyRepo & + PredicateObjectMapper & + TriplestoreService + , + AdminDomainModule.Provided + // format: on + ] { self => + inline def layer: URLayer[self.Dependencies, self.Provided] = + AdminRepoModule.layer >>> AdminDomainModule.layer } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/AdminApiModule.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/AdminApiModule.scala index 7b800bc69d..7a7b7e4d98 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/api/AdminApiModule.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/api/AdminApiModule.scala @@ -5,6 +5,7 @@ package org.knora.webapi.slice.admin.api +import zio.URLayer import zio.ZLayer import org.knora.webapi.config.AppConfig @@ -12,6 +13,7 @@ import org.knora.webapi.config.Features import org.knora.webapi.responders.admin.AssetPermissionsResponder import org.knora.webapi.responders.admin.ListsResponder import org.knora.webapi.responders.admin.PermissionsResponder +import org.knora.webapi.slice.URModule import org.knora.webapi.slice.admin.api.service.GroupRestService import org.knora.webapi.slice.admin.api.service.MaintenanceRestService import org.knora.webapi.slice.admin.api.service.PermissionRestService @@ -36,44 +38,47 @@ import org.knora.webapi.slice.infrastructure.CacheManager import org.knora.webapi.slice.ontology.repo.service.OntologyCache import org.knora.webapi.store.triplestore.api.TriplestoreService -object AdminApiModule { - - type Dependencies = - // format: off - AdministrativePermissionService & - AppConfig & - AssetPermissionsResponder & - AuthorizationRestService & - BaseEndpoints & - CacheManager & - Features & - GroupService & - HandlerMapper & - KnoraGroupService & - KnoraProjectService & - KnoraResponseRenderer & - KnoraUserService & - KnoraUserToUserConverter & - ListsResponder & - MaintenanceService & - OntologyCache & - PasswordService & - PermissionsResponder & - ProjectEraseService & - ProjectExportService & - ProjectImportService & - ProjectService & - TapirToPekkoInterpreter & - TriplestoreService & - UserService - // format: on - - type Provided = AdminApiEndpoints & AdminApiRoutes & - // the `*RestService`s are only exposed for the integration tests - GroupRestService & UserRestService & ProjectRestService & PermissionRestService - - val layer: ZLayer[Dependencies, Nothing, Provided] = - ZLayer.makeSome[Dependencies, Provided]( +object AdminApiModule + extends URModule[ + // format: off + AdministrativePermissionService & + AppConfig & + AssetPermissionsResponder & + AuthorizationRestService & + BaseEndpoints & + CacheManager & + Features & + GroupService & + HandlerMapper & + KnoraGroupService & + KnoraProjectService & + KnoraResponseRenderer & + KnoraUserService & + KnoraUserToUserConverter & + ListsResponder & + MaintenanceService & + OntologyCache & + PasswordService & + PermissionsResponder & + ProjectEraseService & + ProjectExportService & + ProjectImportService & + ProjectService & + TapirToPekkoInterpreter & + TriplestoreService & + UserService + , + AdminApiEndpoints & + AdminApiRoutes & + // the `*RestService`s are only exposed for the integration tests + GroupRestService & + PermissionRestService & + ProjectRestService & + UserRestService + // format: on + ] { self => + inline def layer: URLayer[self.Dependencies, self.Provided] = + ZLayer.makeSome[self.Dependencies, self.Provided]( AdminApiEndpoints.layer, AdminApiRoutes.layer, FilesEndpoints.layer, diff --git a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/AdminDomainModule.scala b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/AdminDomainModule.scala index 46f19e40ad..6d19f2865e 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/AdminDomainModule.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/admin/domain/AdminDomainModule.scala @@ -5,10 +5,12 @@ package org.knora.webapi.slice.admin.domain +import zio.URLayer import zio.ZLayer import org.knora.webapi.config.AppConfig import org.knora.webapi.responders.IriService +import org.knora.webapi.slice.URModule import org.knora.webapi.slice.admin.domain.service.* import org.knora.webapi.slice.admin.domain.service.GroupService import org.knora.webapi.slice.admin.domain.service.KnoraGroupService @@ -23,47 +25,44 @@ import org.knora.webapi.slice.ontology.repo.service.OntologyCache import org.knora.webapi.slice.resourceinfo.domain.IriConverter import org.knora.webapi.store.triplestore.api.TriplestoreService -object AdminDomainModule { - - type Dependencies = - // format: off - AdminRepoModule.Provided & - AppConfig & - CacheManager & - DspIngestClient & - IriService & - IriConverter & - OntologyRepo & - OntologyCache & - TriplestoreService - // format: on - - type Provided = - // format: off - AdministrativePermissionService & - GroupService & - KnoraGroupService & - KnoraProjectService & - KnoraUserService & - KnoraUserToUserConverter & - MaintenanceService & - PasswordService & - ProjectService & - ProjectEraseService & - UserService - // format: on - - val layer = ZLayer.makeSome[Dependencies, Provided]( - AdministrativePermissionService.layer, - GroupService.layer, - KnoraGroupService.layer, - KnoraProjectService.layer, - KnoraUserService.layer, - KnoraUserToUserConverter.layer, - MaintenanceService.layer, - PasswordService.layer, - ProjectEraseService.layer, - ProjectService.layer, - UserService.layer, - ) +object AdminDomainModule + extends URModule[ + // format: off + AdminRepoModule.Provided & + AppConfig & + CacheManager & + DspIngestClient & + IriConverter & + IriService & + OntologyCache & + OntologyRepo & + TriplestoreService + , + AdministrativePermissionService & + GroupService & + KnoraGroupService & + KnoraProjectService & + KnoraUserService & + KnoraUserToUserConverter & + MaintenanceService & + PasswordService & + ProjectEraseService & + ProjectService & + UserService + // format: on + ] { self => + inline def layer: URLayer[self.Dependencies, self.Provided] = + ZLayer.makeSome[self.Dependencies, self.Provided]( + AdministrativePermissionService.layer, + GroupService.layer, + KnoraGroupService.layer, + KnoraProjectService.layer, + KnoraUserService.layer, + KnoraUserToUserConverter.layer, + MaintenanceService.layer, + PasswordService.layer, + ProjectEraseService.layer, + ProjectService.layer, + UserService.layer, + ) } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/InfrastructureModule.scala b/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/InfrastructureModule.scala index 0694679feb..a4abbbdce3 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/InfrastructureModule.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/infrastructure/InfrastructureModule.scala @@ -5,29 +5,28 @@ package org.knora.webapi.slice.infrastructure +import zio.URLayer import zio.ZLayer import org.knora.webapi.config.DspIngestConfig import org.knora.webapi.config.JwtConfig +import org.knora.webapi.slice.URModule -object InfrastructureModule { - - type Dependencies = - // format: off - DspIngestConfig & - JwtConfig - // format: on - - type Provided = - // format: off - CacheManager & - InvalidTokenCache & - JwtService - // format: on - - val layer = ZLayer.makeSome[Dependencies, Provided]( - CacheManager.layer, - InvalidTokenCache.layer, - JwtServiceLive.layer, - ) +object InfrastructureModule + extends URModule[ + // format: off + DspIngestConfig & + JwtConfig + , + CacheManager & + InvalidTokenCache & + JwtService + // format: on + ] { self => + inline def layer: URLayer[self.Dependencies, self.Provided] = + ZLayer.makeSome[self.Dependencies, self.Provided]( + CacheManager.layer, + InvalidTokenCache.layer, + JwtServiceLive.layer, + ) } diff --git a/webapi/src/main/scala/org/knora/webapi/slice/security/SecurityModule.scala b/webapi/src/main/scala/org/knora/webapi/slice/security/SecurityModule.scala index 1342ec68b1..a23960956e 100644 --- a/webapi/src/main/scala/org/knora/webapi/slice/security/SecurityModule.scala +++ b/webapi/src/main/scala/org/knora/webapi/slice/security/SecurityModule.scala @@ -5,35 +5,34 @@ package org.knora.webapi.slice.security +import zio.URLayer import zio.ZLayer import org.knora.webapi.config.AppConfig +import org.knora.webapi.slice.URModule import org.knora.webapi.slice.admin.domain.service.KnoraProjectService import org.knora.webapi.slice.admin.domain.service.PasswordService import org.knora.webapi.slice.admin.domain.service.UserService import org.knora.webapi.slice.infrastructure.InvalidTokenCache import org.knora.webapi.slice.infrastructure.JwtService -object SecurityModule { - - type Dependencies = - // format: off - AppConfig & - InvalidTokenCache & - JwtService & - KnoraProjectService & - PasswordService & - UserService - // format: on - - type Provided = - // format: off - ScopeResolver & - Authenticator - // format: on - - val layer = ZLayer.makeSome[Dependencies, Provided]( - ScopeResolver.layer, - AuthenticatorLive.layer, - ) +object SecurityModule + extends URModule[ + // format: off + AppConfig & + InvalidTokenCache & + JwtService & + KnoraProjectService & + PasswordService & + UserService + , + ScopeResolver & + Authenticator + // format: on + ] { self => + inline def layer: URLayer[self.Dependencies, self.Provided] = + ZLayer.makeSome[self.Dependencies, self.Provided]( + ScopeResolver.layer, + AuthenticatorLive.layer, + ) }