Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break circular dependencies #4783

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@ import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.ApiMappings
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverResolution.ResourceResolution
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.{ResolverContextResolution, Resolvers, ResourceResolution}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.Resources.{ResourceDefinition, ResourceLog}
import ch.epfl.bluebrain.nexus.delta.sdk.resources._
import ch.epfl.bluebrain.nexus.delta.sdk.resources.model.{Resource, ResourceEvent}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.{DetectChange, Resources, ResourcesConfig, ResourcesImpl, ValidateResource}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.Schemas
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.FetchSchema
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.model.Schema
import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors
import ch.epfl.bluebrain.nexus.delta.sourcing.{ScopedEventLog, Transactors}
import izumi.distage.model.definition.{Id, ModuleDef}

/**
* Resources wiring
*/
object ResourcesModule extends ModuleDef {
make[ResourceResolution[Schema]].from { (aclCheck: AclCheck, resolvers: Resolvers, fetchSchema: FetchSchema) =>
ResourceResolution.schemaResource(aclCheck, resolvers, fetchSchema, excludeDeprecated = false)
}

make[ValidateResource].from {
(resourceResolution: ResourceResolution[Schema], rcr: RemoteContextResolution @Id("aggregate")) =>
ValidateResource(resourceResolution)(rcr)
Expand All @@ -40,39 +45,40 @@ object ResourcesModule extends ModuleDef {

make[DetectChange].from { (config: ResourcesConfig) => DetectChange(config.skipUpdateNoChange) }

make[ResourceDefinition].from { (validateResource: ValidateResource, detectChange: DetectChange, clock: Clock[IO]) =>
Resources.definition(validateResource, detectChange, clock)
}

make[ResourceLog].from { (scopedDefinition: ResourceDefinition, config: ResourcesConfig, xas: Transactors) =>
ScopedEventLog(scopedDefinition, config.eventLog, xas)
}

make[Resources].from {
(
validate: ValidateResource,
detectChange: DetectChange,
resourceLog: ResourceLog,
fetchContext: FetchContext,
config: ResourcesConfig,
resolverContextResolution: ResolverContextResolution,
api: JsonLdApi,
xas: Transactors,
clock: Clock[IO],
uuidF: UUIDF
) =>
ResourcesImpl(
validate,
detectChange,
resourceLog,
fetchContext,
resolverContextResolution,
config,
xas,
clock
resolverContextResolution
)(
api,
uuidF
)
}

make[ResolverContextResolution].from {
(aclCheck: AclCheck, resolvers: Resolvers, resources: Resources, rcr: RemoteContextResolution @Id("aggregate")) =>
ResolverContextResolution(aclCheck, resolvers, resources, rcr)
}

make[ResourceResolution[Schema]].from { (aclCheck: AclCheck, resolvers: Resolvers, schemas: Schemas) =>
ResourceResolution.schemaResource(aclCheck, resolvers, schemas, excludeDeprecated = false)
(
aclCheck: AclCheck,
resolvers: Resolvers,
rcr: RemoteContextResolution @Id("aggregate"),
fetchResource: FetchResource
) =>
ResolverContextResolution(aclCheck, resolvers, rcr, fetchResource)
}

make[ResourcesRoutes].from {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import ch.epfl.bluebrain.nexus.delta.sdk.model.metrics.ScopedEventMetricEncoder
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContext
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.ApiMappings
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.{ResolverContextResolution, Resolvers}
import ch.epfl.bluebrain.nexus.delta.sdk.resources.Resources
import ch.epfl.bluebrain.nexus.delta.sdk.resources.FetchResource
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.Schemas.{SchemaDefinition, SchemaLog}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas._
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.model.{Schema, SchemaEvent}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.{SchemaImports, Schemas, SchemasImpl, ValidateSchema}
import ch.epfl.bluebrain.nexus.delta.sdk.sse.SseEncoder
import ch.epfl.bluebrain.nexus.delta.sourcing.Transactors
import ch.epfl.bluebrain.nexus.delta.sourcing.{ScopedEventLog, Transactors}
import izumi.distage.model.definition.{Id, ModuleDef}

/**
Expand All @@ -40,37 +41,43 @@ object SchemasModule extends ModuleDef {

}

make[SchemaDefinition].from { (validateSchema: ValidateSchema, clock: Clock[IO]) =>
Schemas.definition(validateSchema, clock)
}

make[SchemaLog].from { (scopedDefinition: SchemaDefinition, config: AppConfig, xas: Transactors) =>
ScopedEventLog(scopedDefinition, config.schemas.eventLog, xas)
}

make[FetchSchema].from { (schemaLog: SchemaLog) =>
FetchSchema(schemaLog)
}

make[Schemas].from {
(
schemaLog: SchemaLog,
fetchContext: FetchContext,
schemaImports: SchemaImports,
api: JsonLdApi,
validate: ValidateSchema,
resolverContextResolution: ResolverContextResolution,
config: AppConfig,
xas: Transactors,
clock: Clock[IO],
uuidF: UUIDF
) =>
SchemasImpl(
schemaLog,
fetchContext,
schemaImports,
resolverContextResolution,
validate,
config.schemas,
xas,
clock
resolverContextResolution
)(api, uuidF)
}

make[SchemaImports].from {
(
aclCheck: AclCheck,
resolvers: Resolvers,
resources: Resources,
schemas: Schemas
fetchSchema: FetchSchema,
fetchResource: FetchResource
) =>
SchemaImports(aclCheck, resolvers, schemas, resources)
SchemaImports(aclCheck, resolvers, fetchSchema, fetchResource)
}

make[SchemasRoutes].from {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ import ch.epfl.bluebrain.nexus.delta.sdk.generators.{ProjectGen, ResourceResolut
import ch.epfl.bluebrain.nexus.delta.sdk.identities.IdentitiesDummy
import ch.epfl.bluebrain.nexus.delta.sdk.identities.model.Caller
import ch.epfl.bluebrain.nexus.delta.sdk.implicits._
import ch.epfl.bluebrain.nexus.delta.sdk.model.Fetch.FetchF
import ch.epfl.bluebrain.nexus.delta.sdk.model.{IdSegmentRef, ResourceUris}
import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions.resources
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContextDummy
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.ApiMappings
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverResolution.FetchResource
import ch.epfl.bluebrain.nexus.delta.sdk.resources.NexusSource.DecodingOption
import ch.epfl.bluebrain.nexus.delta.sdk.resources.{DetectChange, Resources, ResourcesConfig, ResourcesImpl, ValidateResource}
import ch.epfl.bluebrain.nexus.delta.sdk.resources._
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.model.Schema
import ch.epfl.bluebrain.nexus.delta.sdk.utils.BaseRouteSpec
import ch.epfl.bluebrain.nexus.delta.sourcing.ScopedEventLog
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authenticated, Group, Subject, User}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Tag.UserTag
import ch.epfl.bluebrain.nexus.delta.sourcing.model.{ProjectRef, ResourceRef}
Expand Down Expand Up @@ -87,7 +88,7 @@ class ResourcesRoutesSpec extends BaseRouteSpec with CatsIOValues {

private val aclCheck = AclSimpleCheck().accepted

private val fetchSchema: (ResourceRef, ProjectRef) => FetchResource[Schema] = {
private val fetchSchema: (ResourceRef, ProjectRef) => FetchF[Schema] = {
case (ref, _) if ref.iri == schema2.id => IO.pure(Some(SchemaGen.resourceFor(schema2, deprecated = true)))
case (ref, _) if ref.iri == schema1.id => IO.pure(Some(SchemaGen.resourceFor(schema1)))
case (ref, _) if ref.iri == schema3.id => IO.pure(Some(SchemaGen.resourceFor(schema3)))
Expand All @@ -101,14 +102,17 @@ class ResourcesRoutesSpec extends BaseRouteSpec with CatsIOValues {
private val resolverContextResolution: ResolverContextResolution = ResolverContextResolution(rcr)

private def routesWithDecodingOption(implicit decodingOption: DecodingOption): (Route, Resources) = {
val resourceDef = Resources.definition(validator, DetectChange(enabled = true), clock)
val scopedLog = ScopedEventLog(
resourceDef,
ResourcesConfig(eventLogConfig, decodingOption, skipUpdateNoChange = true).eventLog,
xas
)

val resources = ResourcesImpl(
validator,
DetectChange(enabled = true),
scopedLog,
fetchContext,
resolverContextResolution,
ResourcesConfig(eventLogConfig, decodingOption, skipUpdateNoChange = true),
xas,
clock
resolverContextResolution
)
(
Route.seal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import ch.epfl.bluebrain.nexus.delta.sdk.permissions.Permissions.schemas
import ch.epfl.bluebrain.nexus.delta.sdk.projects.FetchContextDummy
import ch.epfl.bluebrain.nexus.delta.sdk.projects.model.ApiMappings
import ch.epfl.bluebrain.nexus.delta.sdk.resolvers.ResolverContextResolution
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.{SchemaImports, SchemasConfig, SchemasImpl, ValidateSchema}
import ch.epfl.bluebrain.nexus.delta.sdk.schemas.{SchemaImports, Schemas, SchemasConfig, SchemasImpl, ValidateSchema}
import ch.epfl.bluebrain.nexus.delta.sdk.utils.BaseRouteSpec
import ch.epfl.bluebrain.nexus.delta.sourcing.ScopedEventLog
import ch.epfl.bluebrain.nexus.delta.sourcing.model.Identity.{Anonymous, Authenticated, Group, Subject, User}
import ch.epfl.bluebrain.nexus.delta.sourcing.model.ProjectRef
import ch.epfl.bluebrain.nexus.testkit.ce.IOFromMap
Expand Down Expand Up @@ -78,12 +79,15 @@ class SchemasRoutesSpec extends BaseRouteSpec with IOFromMap with CatsIOValues {

private val config = SchemasConfig(eventLogConfig)

private val schemaDef = Schemas.definition(ValidateSchema.apply, clock)
private lazy val schemaLog = ScopedEventLog(schemaDef, config.eventLog, xas)

private lazy val routes =
Route.seal(
SchemasRoutes(
identities,
aclCheck,
SchemasImpl(fetchContext, schemaImports, resolverContextResolution, ValidateSchema.apply, config, xas, clock),
SchemasImpl(schemaLog, fetchContext, schemaImports, resolverContextResolution),
groupDirectives,
IndexingAction.noop
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,12 @@ object BlazegraphViews {
BlazegraphViewCommand,
BlazegraphViewEvent,
BlazegraphViewRejection
] =
] = {
val stateMachine = StateMachine(None, next)
val evaluator = CommandEvaluator(stateMachine, evaluate(validate, clock))
ScopedEntityDefinition.untagged(
entityType,
StateMachine(
None,
evaluate(validate, clock),
next
),
evaluator,
BlazegraphViewEvent.serializer,
BlazegraphViewState.serializer,
{ s =>
Expand All @@ -503,6 +501,7 @@ object BlazegraphViews {
case c => IncorrectRev(c.rev, c.rev + 1)
}
)
}

/**
* Constructs a [[BlazegraphViews]] instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,10 +442,18 @@ object CompositeViews {

def definition(validate: ValidateCompositeView, clock: Clock[IO])(implicit
uuidF: UUIDF
): ScopedEntityDefinition[Iri, CompositeViewState, CompositeViewCommand, CompositeViewEvent, CompositeViewRejection] =
): ScopedEntityDefinition[
Iri,
CompositeViewState,
CompositeViewCommand,
CompositeViewEvent,
CompositeViewRejection
] = {
val stateMachine = StateMachine(None, next)
val evaluator = CommandEvaluator(stateMachine, evaluate(validate, clock))
ScopedEntityDefinition.untagged(
entityType,
StateMachine(None, evaluate(validate, clock)(_, _), next),
evaluator,
CompositeViewEvent.serializer,
CompositeViewState.serializer,
state =>
Expand All @@ -462,6 +470,7 @@ object CompositeViews {
case c => IncorrectRev(c.rev, c.rev + 1)
}
)
}

def apply(
fetchContext: FetchContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,13 @@ object ElasticSearchViews {
ElasticSearchViewCommand,
ElasticSearchViewEvent,
ElasticSearchViewRejection
] =
] = {
val stateMachine = StateMachine(None, next)
val evaluator = CommandEvaluator(stateMachine, evaluate(validate, clock))

ScopedEntityDefinition.untagged(
entityType,
StateMachine(
None,
evaluate(validate, clock)(_, _),
next
),
evaluator,
ElasticSearchViewEvent.serializer,
ElasticSearchViewState.serializer,
{ s =>
Expand All @@ -573,4 +572,5 @@ object ElasticSearchViews {
case c => IncorrectRev(c.rev, c.rev + 1)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -726,10 +726,13 @@ object Files {
*/
def definition(
clock: Clock[IO]
): ScopedEntityDefinition[Iri, FileState, FileCommand, FileEvent, FileRejection] =
): ScopedEntityDefinition[Iri, FileState, FileCommand, FileEvent, FileRejection] = {
val stateMachine = StateMachine(None, next)
val evaluator = CommandEvaluator(stateMachine, evaluate(clock))

ScopedEntityDefinition(
entityType,
StateMachine(None, evaluate(clock)(_, _), next),
evaluator,
FileEvent.serializer,
FileState.serializer,
Tagger[FileEvent](
Expand All @@ -752,6 +755,7 @@ object Files {
case c => IncorrectRev(c.rev, c.rev + 1)
}
)
}

/**
* Constructs a Files instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,13 @@ object Storages {
access: StorageAccess,
fetchPermissions: IO[Set[Permission]],
clock: Clock[IO]
): ScopedEntityDefinition[Iri, StorageState, StorageCommand, StorageEvent, StorageRejection] =
): ScopedEntityDefinition[Iri, StorageState, StorageCommand, StorageEvent, StorageRejection] = {
val stateMachine = StateMachine(None, next)
val evaluator = CommandEvaluator(stateMachine, evaluate(access, fetchPermissions, config, clock))

ScopedEntityDefinition.untagged(
entityType,
StateMachine(None, evaluate(access, fetchPermissions, config, clock)(_, _), next),
evaluator,
StorageEvent.serializer,
StorageState.serializer,
_ => None,
Expand All @@ -473,6 +476,7 @@ object Storages {
case c => IncorrectRev(c.rev, c.rev + 1)
}
)
}

/**
* Constructs a Storages instance
Expand Down
Loading
Loading