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

Update scala SDK to support inlined views in sync #728

Merged
merged 5 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -127,7 +127,7 @@ object InstanceDefinition {
}
}

private def instancePropertyDefinitionBasedInstancePropertyTypeDecoder(
def instancePropertyDefinitionBasedInstancePropertyTypeDecoder(
types: Map[String, Map[String, Map[String, TypePropertyDefinition]]]
): Decoder[Option[Map[String, Map[String, Map[String, InstancePropertyValue]]]]] = (c: HCursor) =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.cognite.sdk.scala.v1.fdm.instances

import cats.implicits.toTraverseOps
import io.circe.generic.semiauto.deriveEncoder
import io.circe.{Decoder, Encoder, HCursor}
import io.circe.{Decoder, Encoder, HCursor, Json}

final case class InstanceSyncResponse(
items: Option[Map[String, Seq[InstanceDefinition]]] = None,
nextCursor: Option[Map[String, String]] = None
nextCursor: Option[Map[String, String]] = None,
typing: Option[Map[String, Map[String, Map[String, Map[String, TypePropertyDefinition]]]]] =
kornelione marked this conversation as resolved.
Show resolved Hide resolved
None
)

object InstanceSyncResponse {
Expand All @@ -14,21 +17,30 @@ object InstanceSyncResponse {
implicit val instanceSyncResponseDecoder: Decoder[InstanceSyncResponse] = (c: HCursor) =>
for {
nextCursor <- c.downField("nextCursor").as[Option[Map[String, String]]]
items <- c
typing <- c
.downField("typing")
.as[Option[Map[String, Map[String, Map[String, Map[String, TypePropertyDefinition]]]]]]
itemObjects <- c
.downField("items")
.as[Option[Map[String, Seq[InstanceDefinition]]]](
Decoder.decodeOption[Map[String, Seq[InstanceDefinition]]](
Decoder.decodeMap[String, Seq[InstanceDefinition]](
implicitly,
Decoder.decodeIterable[InstanceDefinition, Seq](
InstanceDefinition.instancePropertyDefinitionBasedInstanceDecoder(
None
),
implicitly
)
)
)
)
.as[Option[Map[String, Seq[Json]]]]
kornelione marked this conversation as resolved.
Show resolved Hide resolved
items <- itemObjects
.map {
_.toList
.traverse { case (groupName, values) =>
values
.traverse { item =>
item
.as[InstanceDefinition](
InstanceDefinition.instancePropertyDefinitionBasedInstanceDecoder(
typing.flatMap(_.get(groupName))
)
)
}
.map((groupName, _))
}
.map(_.toMap)
}
.traverse(identity)

} yield InstanceSyncResponse(items, nextCursor)
} yield InstanceSyncResponse(items, nextCursor, typing)
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ final case class InstanceFilterRequest(
final case class InstanceSyncRequest(
`with`: Map[String, TableExpression] = Map.empty,
cursors: Option[Map[String, String]] = None,
select: Map[String, SelectExpression] = Map.empty
select: Map[String, SelectExpression] = Map.empty,
includeTyping: Option[Boolean] = None
)

final case class TableExpression(
Expand Down
Loading
Loading