diff --git a/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala b/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala index 5f9e2b1f9..7dc0f3722 100644 --- a/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala +++ b/zio-schema-json/shared/src/main/scala/zio/schema/codec/JsonCodec.scala @@ -101,21 +101,21 @@ object JsonCodec extends Codec { } private[codec] def schemaEncoder[A](schema: Schema[A]): JsonEncoder[A] = schema match { - case Schema.Primitive(standardType) => primitiveCodec(standardType) - case Schema.Sequence(schema, _, g) => JsonEncoder.chunk(schemaEncoder(schema)).contramap(g) - case Schema.Transform(c, _, g) => transformEncoder(c, g) - case Schema.Tuple(l, r) => JsonEncoder.tuple2(schemaEncoder(l), schemaEncoder(r)) - case Schema.Optional(schema) => JsonEncoder.option(schemaEncoder(schema)) - case Schema.Fail(_) => unitEncoder.contramap(_ => ()) - case Schema.GenericRecord(structure) => recordEncoder(structure.toChunk) - case EitherSchema(left, right) => JsonEncoder.either(schemaEncoder(left), schemaEncoder(right)) - case l @ Schema.Lazy(_) => schemaEncoder(l.schema) - case Schema.Meta(_) => astEncoder - case ProductEncoder(encoder) => encoder - case Schema.Enum1(c, _) => enumEncoder(c) - case Schema.Enum2(c1, c2, _) => enumEncoder(c1, c2) - case Schema.Enum3(c1, c2, c3, _) => enumEncoder(c1, c2, c3) - case Schema.EnumN(cs, _) => enumEncoder(cs.toSeq: _*) + case Schema.Primitive(standardType, _) => primitiveCodec(standardType) + case Schema.Sequence(schema, _, g, _) => JsonEncoder.chunk(schemaEncoder(schema)).contramap(g) + case Schema.Transform(c, _, g, _) => transformEncoder(c, g) + case Schema.Tuple(l, r, _) => JsonEncoder.tuple2(schemaEncoder(l), schemaEncoder(r)) + case Schema.Optional(schema, _) => JsonEncoder.option(schemaEncoder(schema)) + case Schema.Fail(_, _) => unitEncoder.contramap(_ => ()) + case Schema.GenericRecord(structure, _) => recordEncoder(structure.toChunk) + case EitherSchema(left, right, _) => JsonEncoder.either(schemaEncoder(left), schemaEncoder(right)) + case l @ Schema.Lazy(_) => schemaEncoder(l.schema) + case Schema.Meta(_, _) => astEncoder + case ProductEncoder(encoder) => encoder + case Schema.Enum1(c, _) => enumEncoder(c) + case Schema.Enum2(c1, c2, _) => enumEncoder(c1, c2) + case Schema.Enum3(c1, c2, c3, _) => enumEncoder(c1, c2, c3) + case Schema.EnumN(cs, _) => enumEncoder(cs.toSeq: _*) } private val astEncoder: JsonEncoder[Schema[_]] = @@ -188,21 +188,21 @@ object JsonCodec extends Codec { schemaDecoder(schema).decodeJson(json) private[codec] def schemaDecoder[A](schema: Schema[A]): JsonDecoder[A] = schema match { - case Schema.Primitive(standardType) => primitiveCodec(standardType) - case Schema.Optional(codec) => JsonDecoder.option(schemaDecoder(codec)) - case Schema.Tuple(left, right) => JsonDecoder.tuple2(schemaDecoder(left), schemaDecoder(right)) - case Schema.Transform(codec, f, _) => schemaDecoder(codec).mapOrFail(f) - case Schema.Sequence(codec, f, _) => JsonDecoder.chunk(schemaDecoder(codec)).map(f) - case Schema.Fail(message) => failDecoder(message) - case Schema.GenericRecord(structure) => recordDecoder(structure.toChunk) - case Schema.EitherSchema(left, right) => JsonDecoder.either(schemaDecoder(left), schemaDecoder(right)) - case l @ Schema.Lazy(_) => schemaDecoder(l.schema) - case Schema.Meta(_) => astDecoder - case ProductDecoder(decoder) => decoder - case Schema.Enum1(c, _) => enumDecoder(c) - case Schema.Enum2(c1, c2, _) => enumDecoder(c1, c2) - case Schema.Enum3(c1, c2, c3, _) => enumDecoder(c1, c2, c3) - case Schema.EnumN(cs, _) => enumDecoder(cs.toSeq: _*) + case Schema.Primitive(standardType, _) => primitiveCodec(standardType) + case Schema.Optional(codec, _) => JsonDecoder.option(schemaDecoder(codec)) + case Schema.Tuple(left, right, _) => JsonDecoder.tuple2(schemaDecoder(left), schemaDecoder(right)) + case Schema.Transform(codec, f, _, _) => schemaDecoder(codec).mapOrFail(f) + case Schema.Sequence(codec, f, _, _) => JsonDecoder.chunk(schemaDecoder(codec)).map(f) + case Schema.Fail(message, _) => failDecoder(message) + case Schema.GenericRecord(structure, _) => recordDecoder(structure.toChunk) + case Schema.EitherSchema(left, right, _) => JsonDecoder.either(schemaDecoder(left), schemaDecoder(right)) + case l @ Schema.Lazy(_) => schemaDecoder(l.schema) + case Schema.Meta(_, _) => astDecoder + case ProductDecoder(decoder) => decoder + case Schema.Enum1(c, _) => enumDecoder(c) + case Schema.Enum2(c1, c2, _) => enumDecoder(c1, c2) + case Schema.Enum3(c1, c2, c3, _) => enumDecoder(c1, c2, c3) + case Schema.EnumN(cs, _) => enumDecoder(cs.toSeq: _*) } private def astDecoder: JsonDecoder[Schema[_]] = diff --git a/zio-schema-protobuf/shared/src/main/scala/zio/schema/codec/ProtobufCodec.scala b/zio-schema-protobuf/shared/src/main/scala/zio/schema/codec/ProtobufCodec.scala index 24fd8df5c..4bfc756dd 100644 --- a/zio-schema-protobuf/shared/src/main/scala/zio/schema/codec/ProtobufCodec.scala +++ b/zio-schema-protobuf/shared/src/main/scala/zio/schema/codec/ProtobufCodec.scala @@ -84,15 +84,15 @@ object ProtobufCodec extends Codec { */ @scala.annotation.tailrec def canBePacked(schema: Schema[_]): Boolean = schema match { - case Schema.Sequence(element, _, _) => canBePacked(element) - case Schema.Transform(codec, _, _) => canBePacked(codec) - case Schema.Primitive(standardType) => canBePacked(standardType) - case _: Schema.Tuple[_, _] => false - case _: Schema.Optional[_] => false - case _: Schema.Fail[_] => false - case _: Schema.EitherSchema[_, _] => false - case lzy @ Schema.Lazy(_) => canBePacked(lzy.schema) - case _ => false + case Schema.Sequence(element, _, _, _) => canBePacked(element) + case Schema.Transform(codec, _, _, _) => canBePacked(codec) + case Schema.Primitive(standardType, _) => canBePacked(standardType) + case _: Schema.Tuple[_, _] => false + case _: Schema.Optional[_] => false + case _: Schema.Fail[_] => false + case _: Schema.EitherSchema[_, _] => false + case lzy @ Schema.Lazy(_) => canBePacked(lzy.schema) + case _ => false } private def canBePacked(standardType: StandardType[_]): Boolean = standardType match { @@ -134,21 +134,21 @@ object ProtobufCodec extends Codec { def encode[A](fieldNumber: Option[Int], schema: Schema[A], value: A): Chunk[Byte] = (schema, value) match { - case (Schema.GenericRecord(structure), v: Map[String, _]) => encodeRecord(fieldNumber, structure.toChunk, v) - case (Schema.Sequence(element, _, g), v) => encodeSequence(fieldNumber, element, g(v)) - case (Schema.Transform(codec, _, g), _) => g(value).map(encode(fieldNumber, codec, _)).getOrElse(Chunk.empty) - case (Schema.Primitive(standardType), v) => encodePrimitive(fieldNumber, standardType, v) - case (Schema.Tuple(left, right), v @ (_, _)) => encodeTuple(fieldNumber, left, right, v) - case (Schema.Optional(codec), v: Option[_]) => encodeOptional(fieldNumber, codec, v) - case (Schema.EitherSchema(left, right), v: Either[_, _]) => encodeEither(fieldNumber, left, right, v) - case (lzy @ Schema.Lazy(_), v) => encode(fieldNumber, lzy.schema, v) - case (Schema.Meta(ast), _) => encode(fieldNumber, Schema[SchemaAst], ast) - case ProductEncoder(encode) => encode(fieldNumber) - case (Schema.Enum1(c, _), v) => encodeEnum(fieldNumber, v, c) - case (Schema.Enum2(c1, c2, _), v) => encodeEnum(fieldNumber, v, c1, c2) - case (Schema.Enum3(c1, c2, c3, _), v) => encodeEnum(fieldNumber, v, c1, c2, c3) - case (Schema.EnumN(cs, _), v) => encodeEnum(fieldNumber, v, cs.toSeq: _*) - case (_, _) => Chunk.empty + case (Schema.GenericRecord(structure, _), v: Map[String, _]) => encodeRecord(fieldNumber, structure.toChunk, v) + case (Schema.Sequence(element, _, g, _), v) => encodeSequence(fieldNumber, element, g(v)) + case (Schema.Transform(codec, _, g, _), _) => g(value).map(encode(fieldNumber, codec, _)).getOrElse(Chunk.empty) + case (Schema.Primitive(standardType, _), v) => encodePrimitive(fieldNumber, standardType, v) + case (Schema.Tuple(left, right, _), v @ (_, _)) => encodeTuple(fieldNumber, left, right, v) + case (Schema.Optional(codec, _), v: Option[_]) => encodeOptional(fieldNumber, codec, v) + case (Schema.EitherSchema(left, right, _), v: Either[_, _]) => encodeEither(fieldNumber, left, right, v) + case (lzy @ Schema.Lazy(_), v) => encode(fieldNumber, lzy.schema, v) + case (Schema.Meta(ast, _), _) => encode(fieldNumber, Schema[SchemaAst], ast) + case ProductEncoder(encode) => encode(fieldNumber) + case (Schema.Enum1(c, _), v) => encodeEnum(fieldNumber, v, c) + case (Schema.Enum2(c1, c2, _), v) => encodeEnum(fieldNumber, v, c1, c2) + case (Schema.Enum3(c1, c2, c3, _), v) => encodeEnum(fieldNumber, v, c1, c2, c3) + case (Schema.EnumN(cs, _), v) => encodeEnum(fieldNumber, v, cs.toSeq: _*) + case (_, _) => Chunk.empty } private def encodeEnum[Z](fieldNumber: Option[Int], value: Z, cases: Schema.Case[_, Z]*): Chunk[Byte] = { @@ -424,11 +424,11 @@ object ProtobufCodec extends Codec { private[codec] def decoder[A](schema: Schema[A]): Decoder[A] = schema match { - case Schema.GenericRecord(structure) => recordDecoder(structure.toChunk) - case Schema.Sequence(elementSchema @ Schema.Sequence(_, _, _), fromChunk, _) => + case Schema.GenericRecord(structure, _) => recordDecoder(structure.toChunk) + case Schema.Sequence(elementSchema @ Schema.Sequence(_, _, _, _), fromChunk, _, _) => if (canBePacked(elementSchema)) packedSequenceDecoder(elementSchema).map(fromChunk) else nonPackedSequenceDecoder(elementSchema).map(fromChunk) - case Schema.Sequence(elementSchema, fromChunk, _) => + case Schema.Sequence(elementSchema, fromChunk, _, _) => Decoder[A]( { bytes => { @@ -443,19 +443,19 @@ object ProtobufCodec extends Codec { }, true ) - case Schema.Transform(codec, f, _) => transformDecoder(codec, f) - case Schema.Primitive(standardType) => primitiveDecoder(standardType) - case Schema.Tuple(left, right) => tupleDecoder(left, right) - case Schema.Optional(codec) => optionalDecoder(codec) - case Schema.Fail(message) => fail(message) - case Schema.EitherSchema(left, right) => eitherDecoder(left, right) - case lzy @ Schema.Lazy(_) => decoder(lzy.schema) - case Schema.Meta(_) => astDecoder - case ProductDecoder(decoder) => decoder - case Schema.Enum1(c, _) => enumDecoder(c) - case Schema.Enum2(c1, c2, _) => enumDecoder(c1, c2) - case Schema.Enum3(c1, c2, c3, _) => enumDecoder(c1, c2, c3) - case Schema.EnumN(cs, _) => enumDecoder(cs.toSeq: _*) + case Schema.Transform(codec, f, _, _) => transformDecoder(codec, f) + case Schema.Primitive(standardType, _) => primitiveDecoder(standardType) + case Schema.Tuple(left, right, _) => tupleDecoder(left, right) + case Schema.Optional(codec, _) => optionalDecoder(codec) + case Schema.Fail(message, _) => fail(message) + case Schema.EitherSchema(left, right, _) => eitherDecoder(left, right) + case lzy @ Schema.Lazy(_) => decoder(lzy.schema) + case Schema.Meta(_, _) => astDecoder + case ProductDecoder(decoder) => decoder + case Schema.Enum1(c, _) => enumDecoder(c) + case Schema.Enum2(c1, c2, _) => enumDecoder(c1, c2) + case Schema.Enum3(c1, c2, c3, _) => enumDecoder(c1, c2, c3) + case Schema.EnumN(cs, _) => enumDecoder(cs.toSeq: _*) } private val astDecoder: Decoder[Schema[_]] = @@ -563,7 +563,7 @@ object ProtobufCodec extends Codec { private def transformDecoder[A, B](schema: Schema[B], f: B => Either[String, A]): Decoder[A] = schema match { - case Schema.Primitive(typ) if typ == StandardType.UnitType => + case Schema.Primitive(typ, _) if typ == StandardType.UnitType => Decoder { (chunk: Chunk[Byte]) => f(().asInstanceOf[B]) match { case Left(err) => Left(err) diff --git a/zio-schema/shared/src/main/scala/zio/schema/Diff.scala b/zio-schema/shared/src/main/scala/zio/schema/Diff.scala index e37d797e1..19b0e8950 100644 --- a/zio-schema/shared/src/main/scala/zio/schema/Diff.scala +++ b/zio-schema/shared/src/main/scala/zio/schema/Diff.scala @@ -71,45 +71,45 @@ trait Differ[A] { self => object Differ { def fromSchema[A](schema: Schema[A]): Differ[A] = schema match { - case Schema.Primitive(StandardType.BinaryType) => binary - case Schema.Primitive(StandardType.IntType) => numeric[Int] - case Schema.Primitive(StandardType.ShortType) => numeric[Short] - case Schema.Primitive(StandardType.DoubleType) => numeric[Double] - case Schema.Primitive(StandardType.FloatType) => numeric[Float] - case Schema.Primitive(StandardType.LongType) => numeric[Long] - case Schema.Primitive(StandardType.CharType) => numeric[Char] - case Schema.Primitive(StandardType.BoolType) => bool - case Schema.Primitive(StandardType.BigDecimalType) => bigDecimal - case Schema.Primitive(StandardType.BigIntegerType) => bigInt - case Schema.Primitive(StandardType.StringType) => string - case Schema.Primitive(StandardType.UUIDType) => string.transform(_.toString) - case Schema.Primitive(StandardType.ZoneId) => string.transform[ZoneId](_.getId) - case Schema.Primitive(StandardType.DayOfWeekType) => dayOfWeek - case Schema.Primitive(StandardType.Month) => month - case Schema.Primitive(StandardType.MonthDay) => monthDay - case Schema.Primitive(StandardType.Year) => year - case Schema.Primitive(StandardType.YearMonth) => yearMonth - case Schema.Primitive(StandardType.LocalDate(_)) => localDate - case Schema.Primitive(StandardType.Instant(_)) => instant - case Schema.Primitive(StandardType.Duration(_)) => duration - case Schema.Primitive(StandardType.LocalTime(_)) => localTime - case Schema.Primitive(StandardType.LocalDateTime(_)) => localDateTime - case Schema.Primitive(StandardType.OffsetTime(_)) => offsetTime - case Schema.Primitive(StandardType.OffsetDateTime(_)) => offsetDateTime - case Schema.Primitive(StandardType.ZonedDateTime(_)) => zonedDateTime - case Schema.Tuple(leftSchema, rightSchema) => fromSchema(leftSchema) <*> fromSchema(rightSchema) - case Schema.Optional(schema) => fromSchema(schema).optional - case Schema.Sequence(schema, _, f) => fromSchema(schema).foreach(f) - case Schema.EitherSchema(leftSchema, rightSchema) => either(fromSchema(leftSchema), fromSchema(rightSchema)) - case s @ Schema.Lazy(_) => fromSchema(s.schema) - case Schema.Transform(schema, _, f) => fromSchema(schema).transformOrFail(f) - case Schema.Fail(_) => fail - case Schema.GenericRecord(structure) => record(structure.toChunk) - case ProductDiffer(differ) => differ - case Schema.Enum1(c, _) => enum(c) - case Schema.Enum2(c1, c2, _) => enum(c1, c2) - case Schema.Enum3(c1, c2, c3, _) => enum(c1, c2, c3) - case Schema.EnumN(cs, _) => enum(cs.toSeq: _*) + case Schema.Primitive(StandardType.BinaryType, _) => binary + case Schema.Primitive(StandardType.IntType, _) => numeric[Int] + case Schema.Primitive(StandardType.ShortType, _) => numeric[Short] + case Schema.Primitive(StandardType.DoubleType, _) => numeric[Double] + case Schema.Primitive(StandardType.FloatType, _) => numeric[Float] + case Schema.Primitive(StandardType.LongType, _) => numeric[Long] + case Schema.Primitive(StandardType.CharType, _) => numeric[Char] + case Schema.Primitive(StandardType.BoolType, _) => bool + case Schema.Primitive(StandardType.BigDecimalType, _) => bigDecimal + case Schema.Primitive(StandardType.BigIntegerType, _) => bigInt + case Schema.Primitive(StandardType.StringType, _) => string + case Schema.Primitive(StandardType.UUIDType, _) => string.transform(_.toString) + case Schema.Primitive(StandardType.ZoneId, _) => string.transform[ZoneId](_.getId) + case Schema.Primitive(StandardType.DayOfWeekType, _) => dayOfWeek + case Schema.Primitive(StandardType.Month, _) => month + case Schema.Primitive(StandardType.MonthDay, _) => monthDay + case Schema.Primitive(StandardType.Year, _) => year + case Schema.Primitive(StandardType.YearMonth, _) => yearMonth + case Schema.Primitive(StandardType.LocalDate(_), _) => localDate + case Schema.Primitive(StandardType.Instant(_), _) => instant + case Schema.Primitive(StandardType.Duration(_), _) => duration + case Schema.Primitive(StandardType.LocalTime(_), _) => localTime + case Schema.Primitive(StandardType.LocalDateTime(_), _) => localDateTime + case Schema.Primitive(StandardType.OffsetTime(_), _) => offsetTime + case Schema.Primitive(StandardType.OffsetDateTime(_), _) => offsetDateTime + case Schema.Primitive(StandardType.ZonedDateTime(_), _) => zonedDateTime + case Schema.Tuple(leftSchema, rightSchema, _) => fromSchema(leftSchema) <*> fromSchema(rightSchema) + case Schema.Optional(schema, _) => fromSchema(schema).optional + case Schema.Sequence(schema, _, f, _) => fromSchema(schema).foreach(f) + case Schema.EitherSchema(leftSchema, rightSchema, _) => either(fromSchema(leftSchema), fromSchema(rightSchema)) + case s @ Schema.Lazy(_) => fromSchema(s.schema) + case Schema.Transform(schema, _, f, _) => fromSchema(schema).transformOrFail(f) + case Schema.Fail(_, _) => fail + case Schema.GenericRecord(structure, _) => record(structure.toChunk) + case ProductDiffer(differ) => differ + case Schema.Enum1(c, _) => enum(c) + case Schema.Enum2(c1, c2, _) => enum(c1, c2) + case Schema.Enum3(c1, c2, c3, _) => enum(c1, c2, c3) + case Schema.EnumN(cs, _) => enum(cs.toSeq: _*) } def binary: Differ[Chunk[Byte]] = @@ -363,21 +363,21 @@ sealed trait Diff { self => import zio.schema.Schema._ (schema, self) match { - case (_, NotComparable) => Left(s"Not Comparable: Schema=$schema and Diff=$self.") - case (_, Identical) => Right(a) - case (Schema.Primitive(StandardType.StringType), Myers(edits)) => patchStringFromMyersEdits(a, edits) - case (Schema.Primitive(StandardType.UUIDType), Myers(edits)) => patchStringFromMyersEdits(a.toString, edits).map(UUID.fromString) - case (Schema.Primitive(StandardType.ZoneId), Myers(edits)) => patchStringFromMyersEdits(a.getId(), edits).map(ZoneId.of) - case (Primitive(StandardType.IntType), Number(distance: Int)) => patchNumeric[Int](a, distance) - case (Primitive(StandardType.ShortType), Number(distance: Short)) => patchNumeric[Short](a, distance) - case (Primitive(StandardType.DoubleType), Number(distance: Double)) => patchNumeric[Double](a, distance) - case (Primitive(StandardType.FloatType), Number(distance: Float)) => patchNumeric[Float](a, distance) - case (Primitive(StandardType.LongType), Number(distance: Long)) => patchNumeric[Long](a, distance) - case (Primitive(StandardType.CharType), Number(distance: Char)) => patchNumeric[Char](a, distance) - case (Primitive(StandardType.BoolType), Bool(xor: Boolean)) => Right(a ^ xor) - case (Primitive(StandardType.BigDecimalType), BigDecimal(distance: java.math.BigDecimal)) => Right(a.subtract(distance)) - case (Primitive(StandardType.BigIntegerType), BigInt(distance: java.math.BigInteger)) => Right(a.subtract(distance)) - case (Primitive(StandardType.BinaryType), Diff.Sequence(diffs)) => + case (_, NotComparable) => Left(s"Not Comparable: Schema=$schema and Diff=$self.") + case (_, Identical) => Right(a) + case (Schema.Primitive(StandardType.StringType, _), Myers(edits)) => patchStringFromMyersEdits(a, edits) + case (Schema.Primitive(StandardType.UUIDType, _), Myers(edits)) => patchStringFromMyersEdits(a.toString, edits).map(UUID.fromString) + case (Schema.Primitive(StandardType.ZoneId, _), Myers(edits)) => patchStringFromMyersEdits(a.getId(), edits).map(ZoneId.of) + case (Primitive(StandardType.IntType, _), Number(distance: Int)) => patchNumeric[Int](a, distance) + case (Primitive(StandardType.ShortType, _), Number(distance: Short)) => patchNumeric[Short](a, distance) + case (Primitive(StandardType.DoubleType, _), Number(distance: Double)) => patchNumeric[Double](a, distance) + case (Primitive(StandardType.FloatType, _), Number(distance: Float)) => patchNumeric[Float](a, distance) + case (Primitive(StandardType.LongType, _), Number(distance: Long)) => patchNumeric[Long](a, distance) + case (Primitive(StandardType.CharType, _), Number(distance: Char)) => patchNumeric[Char](a, distance) + case (Primitive(StandardType.BoolType, _), Bool(xor: Boolean)) => Right(a ^ xor) + case (Primitive(StandardType.BigDecimalType, _), BigDecimal(distance: java.math.BigDecimal)) => Right(a.subtract(distance)) + case (Primitive(StandardType.BigIntegerType, _), BigInt(distance: java.math.BigInteger)) => Right(a.subtract(distance)) + case (Primitive(StandardType.BinaryType, _), Diff.Sequence(diffs)) => diffs .zipAll(a) .flatMap { @@ -393,26 +393,26 @@ sealed trait Diff { self => case (Chunk.empty, values) => Right(values) case (errors, _) => Left(s"Running patch produced the following error(s): ${errors.toList}.") } - case (Primitive(StandardType.Year), Temporal(distance :: Nil)) => Right(Year.of(a.getValue - distance.toInt)) - case (Primitive(StandardType.YearMonth), Temporal(distance :: Nil)) => Right(YearMonth.now().`with`(ChronoField.PROLEPTIC_MONTH, a.getLong(ChronoField.PROLEPTIC_MONTH) - distance)) - case (Primitive(StandardType.LocalDate(_)), Temporal(distance :: Nil)) => Right(LocalDate.ofEpochDay(a.toEpochDay - distance)) - case (Primitive(StandardType.Instant(_)), Temporal(dist1 :: dist2 :: Nil)) => Right(Instant.ofEpochSecond(a.getEpochSecond - dist1, a.getNano() - dist2)) - case (Primitive(StandardType.LocalTime(_)), Temporal(distance :: Nil)) => Right(LocalTime.ofNanoOfDay(a.toNanoOfDay - distance)) - case (Primitive(StandardType.LocalDateTime(_)), Temporal(dist1 :: dist2 :: Nil)) => + case (Primitive(StandardType.Year, _), Temporal(distance :: Nil)) => Right(Year.of(a.getValue - distance.toInt)) + case (Primitive(StandardType.YearMonth, _), Temporal(distance :: Nil)) => Right(YearMonth.now().`with`(ChronoField.PROLEPTIC_MONTH, a.getLong(ChronoField.PROLEPTIC_MONTH) - distance)) + case (Primitive(StandardType.LocalDate(_), _), Temporal(distance :: Nil)) => Right(LocalDate.ofEpochDay(a.toEpochDay - distance)) + case (Primitive(StandardType.Instant(_), _), Temporal(dist1 :: dist2 :: Nil)) => Right(Instant.ofEpochSecond(a.getEpochSecond - dist1, a.getNano() - dist2)) + case (Primitive(StandardType.LocalTime(_), _), Temporal(distance :: Nil)) => Right(LocalTime.ofNanoOfDay(a.toNanoOfDay - distance)) + case (Primitive(StandardType.LocalDateTime(_), _), Temporal(dist1 :: dist2 :: Nil)) => Right { LocalDateTime.of( LocalDate.ofEpochDay(a.toLocalDate.toEpochDay - dist1), LocalTime.ofNanoOfDay(a.toLocalTime.toNanoOfDay - dist2) ) } - case (Primitive(StandardType.OffsetTime(_)), Temporal(dist1 :: dist2 :: Nil)) => + case (Primitive(StandardType.OffsetTime(_), _), Temporal(dist1 :: dist2 :: Nil)) => Right { OffsetTime.of( LocalTime.ofNanoOfDay(a.toLocalTime.toNanoOfDay - dist1), ZoneOffset.ofTotalSeconds(a.getOffset.getTotalSeconds - dist2.toInt) ) } - case (Primitive(StandardType.OffsetDateTime(_)), Temporal(dist1 :: dist2 :: dist3 :: Nil)) => + case (Primitive(StandardType.OffsetDateTime(_), _), Temporal(dist1 :: dist2 :: dist3 :: Nil)) => Right { OffsetDateTime.of( LocalDate.ofEpochDay(a.toLocalDate.toEpochDay - dist1), @@ -420,48 +420,48 @@ sealed trait Diff { self => ZoneOffset.ofTotalSeconds(a.getOffset.getTotalSeconds - dist3.toInt) ) } - case (Primitive(StandardType.ZonedDateTime(_)), ZonedDateTime(Identical, Identical)) => Right(a) - case (Primitive(StandardType.ZonedDateTime(_)), ZonedDateTime(Identical, Myers(edits))) => + case (Primitive(StandardType.ZonedDateTime(_), _), ZonedDateTime(Identical, Identical)) => Right(a) + case (Primitive(StandardType.ZonedDateTime(_), _), ZonedDateTime(Identical, Myers(edits))) => patchStringFromMyersEdits(a.getZone.getId, edits).map { zoneIdString => JZonedDateTime.of(a.toLocalDateTime, ZoneId.of(zoneIdString)) } - case (Primitive(StandardType.ZonedDateTime(_)), ZonedDateTime(Temporal(dist1 :: dist2 :: Nil), Identical)) => { + case (Primitive(StandardType.ZonedDateTime(_), _), ZonedDateTime(Temporal(dist1 :: dist2 :: Nil), Identical)) => { val localDateTime = LocalDateTime.of(LocalDate.ofEpochDay(a.toLocalDate.toEpochDay - dist1), LocalTime.ofNanoOfDay(a.toLocalTime.toNanoOfDay - dist2)) Right(JZonedDateTime.of(localDateTime, a.getZone)) } - case (Primitive(StandardType.ZonedDateTime(_)), ZonedDateTime(Temporal(dist1 :: dist2 :: Nil), Myers(edits))) => { + case (Primitive(StandardType.ZonedDateTime(_), _), ZonedDateTime(Temporal(dist1 :: dist2 :: Nil), Myers(edits))) => { val localDateTime = LocalDateTime.of(LocalDate.ofEpochDay(a.toLocalDate.toEpochDay - dist1), LocalTime.ofNanoOfDay(a.toLocalTime.toNanoOfDay - dist2)) patchStringFromMyersEdits(a.getZone.getId, edits).map { zoneIdString => JZonedDateTime.of(localDateTime, ZoneId.of(zoneIdString)) } } - case (Primitive(StandardType.DayOfWeekType), Temporal(distance :: Nil)) => Right(a.plus(distance)) - case (Primitive(StandardType.Month), Temporal(distance :: Nil)) => Right(a.plus(distance)) - case (Primitive(StandardType.Duration(_)), Temporal(dist1 :: dist2 :: Nil)) => Right(JDuration.ofSeconds(a.getSeconds - dist1, a.getNano() - dist2)) + case (Primitive(StandardType.DayOfWeekType, _), Temporal(distance :: Nil)) => Right(a.plus(distance)) + case (Primitive(StandardType.Month, _), Temporal(distance :: Nil)) => Right(a.plus(distance)) + case (Primitive(StandardType.Duration(_), _), Temporal(dist1 :: dist2 :: Nil)) => Right(JDuration.ofSeconds(a.getSeconds - dist1, a.getNano() - dist2)) // TODO need to deal with leap year differences - case (Primitive(StandardType.MonthDay), Temporal(regDiff :: _ :: Nil)) => Right(MonthDay.from(ChronoUnit.DAYS.addTo(a.atYear(2001), regDiff.toLong))) - case (s @ Schema.Lazy(_), diff) => diff.patch(a)(s.schema) - case (Optional(_), Total(_, Diff.Tag.Left)) => Right(None) - case (Optional(_), Total(right, Diff.Tag.Right)) => Right(Some(right)) - case (Optional(schema), diff) => + case (Primitive(StandardType.MonthDay, _), Temporal(regDiff :: _ :: Nil)) => Right(MonthDay.from(ChronoUnit.DAYS.addTo(a.atYear(2001), regDiff.toLong))) + case (s @ Schema.Lazy(_), diff) => diff.patch(a)(s.schema) + case (Optional(_, _), Total(_, Diff.Tag.Left)) => Right(None) + case (Optional(_, _), Total(right, Diff.Tag.Right)) => Right(Some(right)) + case (Optional(schema, _), diff) => a match { case None => Right(None) case Some(b) => diff.patch(b)(schema).map(Some(_)) } - case (EitherSchema(_, rightSchema), Diff.Either(diff, Diff.Tag.Right)) => + case (EitherSchema(_, rightSchema, _), Diff.Either(diff, Diff.Tag.Right)) => a match { case Right(b) => diff.patch(b)(rightSchema).map(Right(_)) case e @ Left(_) => Left(s"Value should be Right not: $e.") } - case (EitherSchema(leftSchema, _), Diff.Either(diff, Diff.Tag.Left)) => + case (EitherSchema(leftSchema, _, _), Diff.Either(diff, Diff.Tag.Left)) => a match { case Left(b) => diff.patch(b)(leftSchema).map(Left(_)) case e @ Right(_) => Left(s"Value should be Left not: $e.") } - case (Schema.Tuple(leftSchema, rightSchema), Diff.Tuple(leftDiff, rightDiff)) => { + case (Schema.Tuple(leftSchema, rightSchema, _), Diff.Tuple(leftDiff, rightDiff)) => { val (left, right) = a val leftPatch = leftDiff.patch(left)(leftSchema) val rightPatch = rightDiff.patch(right)(rightSchema) @@ -474,7 +474,7 @@ sealed trait Diff { self => } } - case (Schema.Sequence(schema, fromChunk, toChunk), Diff.Sequence(diffs)) => + case (Schema.Sequence(schema, fromChunk, toChunk, _), Diff.Sequence(diffs)) => diffs .zipAll(toChunk(a)) .flatMap { @@ -490,14 +490,14 @@ sealed trait Diff { self => case (errors, _) => Left(s"Running patch produced the following error(s): ${errors.toList}.") } - case (Schema.Transform(schema, f, g), diff) => + case (Schema.Transform(schema, f, g, _), diff) => for { b <- g(a) patched <- diff.patch(b)(schema) backToA <- f(patched) } yield backToA - case (Schema.GenericRecord(structure: FieldSet), Diff.Record(diffs: ListMap[String, Diff])) => { + case (Schema.GenericRecord(structure: FieldSet, _), Diff.Record(diffs: ListMap[String, Diff])) => { val values: ListMap[String, DynamicValue] = schema.toDynamic(a) match { case DynamicValue.Record(values) => values case _ => ListMap.empty @@ -519,7 +519,7 @@ sealed trait Diff { self => case (Schema.Enum2(c1, c2, _), diff) => patchEnumData(a, diff, c1, c2) case (Schema.Enum3(c1, c2, c3, _), diff) => patchEnumData(a, diff, c1, c2, c3) case (Schema.EnumN(cases, _), diff) => patchEnumData(a, diff, cases.toSeq: _*) - case (schema @ Fail(_), _) => Left(s"Failed Schema=$schema cannot be patched.") + case (schema @ Fail(_, _), _) => Left(s"Failed Schema=$schema cannot be patched.") case (_, _) => Left(s"Incompatible Schema=$schema and Diff=$self.") } } diff --git a/zio-schema/shared/src/main/scala/zio/schema/DynamicValue.scala b/zio-schema/shared/src/main/scala/zio/schema/DynamicValue.scala index 2cbe24836..eba6b960a 100644 --- a/zio-schema/shared/src/main/scala/zio/schema/DynamicValue.scala +++ b/zio-schema/shared/src/main/scala/zio/schema/DynamicValue.scala @@ -15,10 +15,10 @@ trait DynamicValue { self => def toTypedValue[A](schema: Schema[A]): Either[String, A] = (self, schema) match { - case (DynamicValue.Primitive(value, p), Schema.Primitive(p2)) if p == p2 => + case (DynamicValue.Primitive(value, p), Schema.Primitive(p2, _)) if p == p2 => Right(value.asInstanceOf[A]) - case (DynamicValue.Record(values), Schema.GenericRecord(structure)) => + case (DynamicValue.Record(values), Schema.GenericRecord(structure, _)) => DynamicValue.decodeStructure(values, structure.toChunk).asInstanceOf[Either[String, A]] case (DynamicValue.Record(values), s: Schema.Record[A]) => @@ -30,13 +30,13 @@ trait DynamicValue { self => case None => Left(s"Failed to find case $key in enum $s") } - case (DynamicValue.LeftValue(value), Schema.EitherSchema(schema1, _)) => + case (DynamicValue.LeftValue(value), Schema.EitherSchema(schema1, _, _)) => value.toTypedValue(schema1).map(Left(_)) - case (DynamicValue.RightValue(value), Schema.EitherSchema(_, schema1)) => + case (DynamicValue.RightValue(value), Schema.EitherSchema(_, schema1, _)) => value.toTypedValue(schema1).map(Right(_)) - case (DynamicValue.Tuple(leftValue, rightValue), Schema.Tuple(leftSchema, rightSchema)) => + case (DynamicValue.Tuple(leftValue, rightValue), Schema.Tuple(leftSchema, rightSchema, _)) => val typedLeft = leftValue.toTypedValue(leftSchema) val typedRight = rightValue.toTypedValue(rightSchema) (typedLeft, typedRight) match { @@ -46,7 +46,7 @@ trait DynamicValue { self => case (Right(a), Right(b)) => Right(a -> b) } - case (DynamicValue.Sequence(values), Schema.Sequence(schema, f, _)) => + case (DynamicValue.Sequence(values), Schema.Sequence(schema, f, _, _)) => values .foldLeft[Either[String, Chunk[_]]](Right[String, Chunk[A]](Chunk.empty)) { case (err @ Left(_), _) => err @@ -55,16 +55,16 @@ trait DynamicValue { self => } .map(f) - case (DynamicValue.SomeValue(value), Schema.Optional(schema: Schema[_])) => + case (DynamicValue.SomeValue(value), Schema.Optional(schema: Schema[_], _)) => value.toTypedValue(schema).map(Some(_)) - case (DynamicValue.NoneValue, Schema.Optional(_)) => + case (DynamicValue.NoneValue, Schema.Optional(_, _)) => Right(None) - case (DynamicValue.Transform(DynamicValue.Error(message)), Schema.Transform(_, _, _)) => + case (DynamicValue.Transform(DynamicValue.Error(message)), Schema.Transform(_, _, _, _)) => Left(message) - case (DynamicValue.Transform(value), Schema.Transform(schema, f, _)) => + case (DynamicValue.Transform(value), Schema.Transform(schema, f, _, _)) => value.toTypedValue(schema).flatMap(f) case (_, l @ Schema.Lazy(_)) => @@ -87,9 +87,9 @@ object DynamicValue { case l @ Schema.Lazy(_) => fromSchemaAndValue(l.schema, value) - case Schema.Primitive(p) => DynamicValue.Primitive(value, p) + case Schema.Primitive(p, _) => DynamicValue.Primitive(value, p) - case Schema.GenericRecord(structure) => + case Schema.GenericRecord(structure, _) => val map: ListMap[String, _] = value DynamicValue.Record( ListMap.empty ++ structure.toChunk.map { @@ -947,34 +947,34 @@ object DynamicValue { case None => DynamicValue.NoneValue } - case Schema.Fail(message) => DynamicValue.Error(message) + case Schema.Fail(message, _) => DynamicValue.Error(message) - case Schema.Sequence(schema, _, toChunk) => + case Schema.Sequence(schema, _, toChunk, _) => DynamicValue.Sequence(toChunk(value).map(fromSchemaAndValue(schema, _))) - case Schema.EitherSchema(left, right) => + case Schema.EitherSchema(left, right, _) => value match { case Left(a) => DynamicValue.LeftValue(fromSchemaAndValue(left, a)) case Right(b) => DynamicValue.RightValue(fromSchemaAndValue(right, b)) } - case Schema.Tuple(schemaA, schemaB) => + case Schema.Tuple(schemaA, schemaB, _) => val (a, b) = value DynamicValue.Tuple(fromSchemaAndValue(schemaA, a), fromSchemaAndValue(schemaB, b)) - case Schema.Optional(schema) => + case Schema.Optional(schema, _) => value match { case Some(value) => DynamicValue.SomeValue(fromSchemaAndValue(schema, value)) case None => DynamicValue.NoneValue } - case Schema.Transform(schema, _, g) => + case Schema.Transform(schema, _, g, _) => g(value) match { case Left(message) => DynamicValue.Transform(DynamicValue.Error(message)) case Right(a) => DynamicValue.Transform(fromSchemaAndValue(schema, a)) } - case Schema.Meta(ast) => DynamicValue.DynamicAst(ast) + case Schema.Meta(ast, _) => DynamicValue.DynamicAst(ast) case Schema.CaseClass1(_, f, _, ext) => DynamicValue.Record(ListMap(f.label -> fromSchemaAndValue(f.schema, ext(value)))) diff --git a/zio-schema/shared/src/main/scala/zio/schema/Schema.scala b/zio-schema/shared/src/main/scala/zio/schema/Schema.scala index 262a18a8a..4be1d42fb 100644 --- a/zio-schema/shared/src/main/scala/zio/schema/Schema.scala +++ b/zio-schema/shared/src/main/scala/zio/schema/Schema.scala @@ -46,6 +46,16 @@ sealed trait Schema[A] { */ def <+>[B](that: Schema[B]): Schema[Either[A, B]] = self.orElseEither(that) + /** + * Chunk of annotations for this schema + */ + def annotations: Chunk[Any] + + /** + * Returns a new schema that with `annotation` + */ + def annotate(annotation: Any): Schema[A] + /** * Convert to Schema[B] iff B and A are homomorphic. * @@ -112,14 +122,14 @@ sealed trait Schema[A] { * between `A` and `B`, without possibility of failure. */ def transform[B](f: A => B, g: B => A): Schema[B] = - Schema.Transform[A, B](self, a => Right(f(a)), b => Right(g(b))) + Schema.Transform[A, B](self, a => Right(f(a)), b => Right(g(b)), annotations) /** * Transforms this `Schema[A]` into a `Schema[B]`, by supplying two functions that can transform * between `A` and `B` (possibly failing in some cases). */ def transformOrFail[B](f: A => Either[String, B], g: B => Either[String, A]): Schema[B] = - Schema.Transform[A, B](self, f, g) + Schema.Transform[A, B](self, f, g, annotations) /** * Returns a new schema that combines this schema and the specified schema together, modeling @@ -194,7 +204,7 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas { implicit val none: Schema[None.type] = Schema[Unit].transform(_ => None, _ => ()) implicit def chunk[A](implicit schemaA: Schema[A]): Schema[Chunk[A]] = - Schema.Sequence[Chunk[A], A](schemaA, identity, identity) + Schema.Sequence[Chunk[A], A](schemaA, identity, identity, Chunk.empty) implicit def either[A, B](implicit left: Schema[A], right: Schema[B]): Schema[Either[A, B]] = EitherSchema(left, right) @@ -203,13 +213,13 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas { schemaA.transform(Left(_), _.value) implicit def list[A](implicit schemaA: Schema[A]): Schema[List[A]] = - Schema.Sequence[List[A], A](schemaA, _.toList, Chunk.fromIterable(_)) + Schema.Sequence[List[A], A](schemaA, _.toList, Chunk.fromIterable(_), Chunk.empty) implicit def option[A](implicit element: Schema[A]): Schema[Option[A]] = Optional(element) implicit def primitive[A](implicit standardType: StandardType[A]): Schema[A] = - Primitive(standardType) + Primitive(standardType, Chunk.empty) implicit def right[A, B](implicit schemaB: Schema[B]): Schema[Right[Nothing, B]] = schemaB.transform(Right(_), _.value) @@ -221,48 +231,63 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas { chunk(element).transform(_.toVector, Chunk.fromIterable(_)) sealed trait Enum[A] extends Schema[A] { - def annotations: Chunk[Any] def structure: ListMap[String, Schema[_]] } sealed trait Record[R] extends Schema[R] { def structure: Chunk[Field[_]] - def annotations: Chunk[Any] = Chunk.empty def rawConstruct(values: Chunk[Any]): Either[String, R] } final case class Sequence[Col, Elem]( schemaA: Schema[Elem], fromChunk: Chunk[Elem] => Col, - toChunk: Col => Chunk[Elem] + toChunk: Col => Chunk[Elem], + override val annotations: Chunk[Any] ) extends Schema[Col] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = Traversal[Col, Elem] + override def annotate(annotation: Any): Sequence[Col, Elem] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): b.Traversal[Col, Elem] = b.makeTraversal(self, schemaA) override def toString: String = s"Sequence($schemaA)" + } - final case class Transform[A, B](codec: Schema[A], f: A => Either[String, B], g: B => Either[String, A]) - extends Schema[B] { + final case class Transform[A, B]( + codec: Schema[A], + f: A => Either[String, B], + g: B => Either[String, A], + annotations: Chunk[Any] + ) extends Schema[B] { override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = codec.Accessors[Lens, Prism, Traversal] override def makeAccessors(b: AccessorBuilder): codec.Accessors[b.Lens, b.Prism, b.Traversal] = codec.makeAccessors(b) + override def annotate(annotation: Any): Transform[A, B] = copy(annotations = annotations :+ annotation) + override def serializable: Schema[Schema[_]] = Meta(SchemaAst.fromSchema(codec)) override def toString: String = s"Transform($codec)" + } - final case class Primitive[A](standardType: StandardType[A]) extends Schema[A] { + final case class Primitive[A](standardType: StandardType[A], annotations: Chunk[Any] = Chunk.empty) + extends Schema[A] { type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = Unit + override def annotate(annotation: Any): Primitive[A] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): Unit = () } - final case class Optional[A](codec: Schema[A]) extends Schema[Option[A]] { self => + final case class Optional[A](codec: Schema[A], annotations: Chunk[Any] = Chunk.empty) extends Schema[Option[A]] { + self => private[schema] val someCodec: Schema[Some[A]] = codec.transform(a => Some(a), _.get) + override def annotate(annotation: Any): Optional[A] = copy(annotations = annotations :+ annotation) + override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Option[A], Some[A]], Prism[Option[A], None.type]) @@ -274,17 +299,23 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas { override def makeAccessors(b: AccessorBuilder): (b.Prism[Option[A], Some[A]], b.Prism[Option[A], None.type]) = b.makePrism(toEnum, toEnum.case1) -> b.makePrism(toEnum, toEnum.case2) + } - final case class Fail[A](message: String) extends Schema[A] { + final case class Fail[A](message: String, annotations: Chunk[Any] = Chunk.empty) extends Schema[A] { override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = Unit + override def annotate(annotation: Any): Fail[A] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): Unit = () } - final case class Tuple[A, B](left: Schema[A], right: Schema[B]) extends Schema[(A, B)] { self => + final case class Tuple[A, B](left: Schema[A], right: Schema[B], annotations: Chunk[Any] = Chunk.empty) + extends Schema[(A, B)] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[(A, B), A], Lens[(A, B), B]) + override def annotate(annotation: Any): Tuple[A, B] = copy(annotations = annotations :+ annotation) + val toRecord: CaseClass2[A, B, (A, B)] = CaseClass2[A, B, (A, B)]( field1 = Field("_1", left), field2 = Field("_2", right), @@ -295,12 +326,16 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas { override def makeAccessors(b: AccessorBuilder): (b.Lens[(A, B), A], b.Lens[(A, B), B]) = b.makeLens(toRecord, toRecord.field1) -> b.makeLens(toRecord, toRecord.field2) + } - final case class EitherSchema[A, B](left: Schema[A], right: Schema[B]) extends Schema[Either[A, B]] { self => + final case class EitherSchema[A, B](left: Schema[A], right: Schema[B], annotations: Chunk[Any] = Chunk.empty) + extends Schema[Either[A, B]] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Either[A, B], Right[Nothing, B]], Prism[Either[A, B], Left[A, Nothing]]) + override def annotate(annotation: Any): EitherSchema[A, B] = copy(annotations = annotations :+ annotation) + val rightSchema: Schema[Right[Nothing, B]] = right.transform(b => Right(b), _.value) val leftSchema: Schema[Left[A, Nothing]] = left.transform(a => Left(a), _.value) @@ -314,30 +349,39 @@ object Schema extends TupleSchemas with RecordSchemas with EnumSchemas { b: AccessorBuilder ): (b.Prism[Either[A, B], Right[Nothing, B]], b.Prism[Either[A, B], Left[A, Nothing]]) = b.makePrism(toEnum, toEnum.case1) -> b.makePrism(toEnum, toEnum.case2) + } final case class Lazy[A](private val schema0: () => Schema[A]) extends Schema[A] { override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = schema.Accessors[Lens, Prism, Traversal] + override def annotate(annotation: Any): Lazy[A] = Lazy(() => schema0().annotate(annotation)) + lazy val schema: Schema[A] = schema0() override def makeAccessors(b: AccessorBuilder): schema.Accessors[b.Lens, b.Prism, b.Traversal] = schema.makeAccessors(b) override def toString: String = "$Lazy$" + + override def annotations: Chunk[Any] = schema0().annotations } - final case class Meta(ast: SchemaAst) extends Schema[Schema[_]] { + final case class Meta(ast: SchemaAst, annotations: Chunk[Any] = Chunk.empty) extends Schema[Schema[_]] { + + override def annotate(annotation: Any): Meta = copy(annotations = annotations :+ annotation) + override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = Unit override def makeAccessors(b: AccessorBuilder): Unit = () + } } //scalafmt: { maxColumn = 400 } sealed trait EnumSchemas { self: Schema.type => - sealed case class Case[A, Z](id: String, codec: Schema[A], unsafeDeconstruct: Z => A, annotations: Chunk[Any]) { + sealed case class Case[A, Z](id: String, codec: Schema[A], unsafeDeconstruct: Z => A, annotations: Chunk[Any] = Chunk.empty) { def deconstruct(z: Z): Option[A] = try { @@ -347,18 +391,22 @@ sealed trait EnumSchemas { self: Schema.type => override def toString: String = s"Case($id,$codec,$annotations)" } - sealed case class Enum1[A <: Z, Z](case1: Case[A, Z], override val annotations: Chunk[Any]) extends Enum[Z] { self => + sealed case class Enum1[A <: Z, Z](case1: Case[A, Z], annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = Prism[Z, A] + override def annotate(annotation: Any): Enum1[A, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): b.Prism[Z, A] = b.makePrism(self, case1) override def structure: ListMap[String, Schema[_]] = ListMap(case1.id -> case1.codec) } - sealed case class Enum2[A1 <: Z, A2 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], override val annotations: Chunk[Any]) extends Enum[Z] { self => + sealed case class Enum2[A1 <: Z, A2 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2]) + override def annotate(annotation: Any): Enum2[A1, A2, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2]) = (b.makePrism(self, case1), b.makePrism(self, case2)) @@ -366,9 +414,11 @@ sealed trait EnumSchemas { self: Schema.type => ListMap(case1.id -> case1.codec, case2.id -> case2.codec) } - sealed case class Enum3[A1 <: Z, A2 <: Z, A3 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], override val annotations: Chunk[Any]) extends Enum[Z] { self => + sealed case class Enum3[A1 <: Z, A2 <: Z, A3 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3]) + override def annotate(annotation: Any): Enum3[A1, A2, A3, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3)) @@ -376,9 +426,11 @@ sealed trait EnumSchemas { self: Schema.type => ListMap(case1.id -> case1.codec, case2.id -> case2.codec, case3.id -> case3.codec) } - sealed case class Enum4[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], override val annotations: Chunk[Any]) extends Enum[Z] { self => + sealed case class Enum4[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4]) + override def annotate(annotation: Any): Enum4[A1, A2, A3, A4, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3), b.makePrism(self, case4)) @@ -386,9 +438,11 @@ sealed trait EnumSchemas { self: Schema.type => ListMap(case1.id -> case1.codec, case2.id -> case2.codec, case3.id -> case3.codec, case4.id -> case4.codec) } - sealed case class Enum5[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], override val annotations: Chunk[Any]) extends Enum[Z] { self => + sealed case class Enum5[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5]) + override def annotate(annotation: Any): Enum5[A1, A2, A3, A4, A5, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3), b.makePrism(self, case4), b.makePrism(self, case5)) @@ -396,9 +450,11 @@ sealed trait EnumSchemas { self: Schema.type => ListMap(case1.id -> case1.codec, case2.id -> case2.codec, case3.id -> case3.codec, case4.id -> case4.codec, case5.id -> case5.codec) } - sealed case class Enum6[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], override val annotations: Chunk[Any]) extends Enum[Z] { self => + sealed case class Enum6[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6]) + override def annotate(annotation: Any): Enum6[A1, A2, A3, A4, A5, A6, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3), b.makePrism(self, case4), b.makePrism(self, case5), b.makePrism(self, case6)) @@ -406,9 +462,11 @@ sealed trait EnumSchemas { self: Schema.type => ListMap(case1.id -> case1.codec, case2.id -> case2.codec, case3.id -> case3.codec, case4.id -> case4.codec, case5.id -> case5.codec, case6.id -> case6.codec) } - sealed case class Enum7[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, A7 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], case7: Case[A7, Z], override val annotations: Chunk[Any]) extends Enum[Z] { self => + sealed case class Enum7[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, A7 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], case7: Case[A7, Z], annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7]) + override def annotate(annotation: Any): Enum7[A1, A2, A3, A4, A5, A6, A7, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3), b.makePrism(self, case4), b.makePrism(self, case5), b.makePrism(self, case6), b.makePrism(self, case7)) @@ -424,9 +482,11 @@ sealed trait EnumSchemas { self: Schema.type => ) } - sealed case class Enum8[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, A7 <: Z, A8 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], case7: Case[A7, Z], case8: Case[A8, Z], override val annotations: Chunk[Any]) extends Enum[Z] { self => + sealed case class Enum8[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, A7 <: Z, A8 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], case7: Case[A7, Z], case8: Case[A8, Z], annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8]) + override def annotate(annotation: Any): Enum8[A1, A2, A3, A4, A5, A6, A7, A8, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3), b.makePrism(self, case4), b.makePrism(self, case5), b.makePrism(self, case6), b.makePrism(self, case7), b.makePrism(self, case8)) @@ -443,9 +503,11 @@ sealed trait EnumSchemas { self: Schema.type => ) } - sealed case class Enum9[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, A7 <: Z, A8 <: Z, A9 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], case7: Case[A7, Z], case8: Case[A8, Z], case9: Case[A9, Z], override val annotations: Chunk[Any]) extends Enum[Z] { self => + sealed case class Enum9[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, A7 <: Z, A8 <: Z, A9 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], case7: Case[A7, Z], case8: Case[A8, Z], case9: Case[A9, Z], annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9]) + override def annotate(annotation: Any): Enum9[A1, A2, A3, A4, A5, A6, A7, A8, A9, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3), b.makePrism(self, case4), b.makePrism(self, case5), b.makePrism(self, case6), b.makePrism(self, case7), b.makePrism(self, case8), b.makePrism(self, case9)) @@ -462,9 +524,11 @@ sealed trait EnumSchemas { self: Schema.type => case9.id -> case9.codec ) } - sealed case class Enum10[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, A7 <: Z, A8 <: Z, A9 <: Z, A10 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], case7: Case[A7, Z], case8: Case[A8, Z], case9: Case[A9, Z], case10: Case[A10, Z], override val annotations: Chunk[Any]) extends Enum[Z] { self => + sealed case class Enum10[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, A7 <: Z, A8 <: Z, A9 <: Z, A10 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], case7: Case[A7, Z], case8: Case[A8, Z], case9: Case[A9, Z], case10: Case[A10, Z], annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10]) + override def annotate(annotation: Any): Enum10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3), b.makePrism(self, case4), b.makePrism(self, case5), b.makePrism(self, case6), b.makePrism(self, case7), b.makePrism(self, case8), b.makePrism(self, case9), b.makePrism(self, case10)) @@ -482,10 +546,12 @@ sealed trait EnumSchemas { self: Schema.type => case10.id -> case10.codec ) } - sealed case class Enum11[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, A7 <: Z, A8 <: Z, A9 <: Z, A10 <: Z, A11 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], case7: Case[A7, Z], case8: Case[A8, Z], case9: Case[A9, Z], case10: Case[A10, Z], case11: Case[A11, Z], override val annotations: Chunk[Any]) + sealed case class Enum11[A1 <: Z, A2 <: Z, A3 <: Z, A4 <: Z, A5 <: Z, A6 <: Z, A7 <: Z, A8 <: Z, A9 <: Z, A10 <: Z, A11 <: Z, Z](case1: Case[A1, Z], case2: Case[A2, Z], case3: Case[A3, Z], case4: Case[A4, Z], case5: Case[A5, Z], case6: Case[A6, Z], case7: Case[A7, Z], case8: Case[A8, Z], case9: Case[A9, Z], case10: Case[A10, Z], case11: Case[A11, Z], annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11]) + override def annotate(annotation: Any): Enum11[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3), b.makePrism(self, case4), b.makePrism(self, case5), b.makePrism(self, case6), b.makePrism(self, case7), b.makePrism(self, case8), b.makePrism(self, case9), b.makePrism(self, case10), b.makePrism(self, case11)) @@ -517,10 +583,12 @@ sealed trait EnumSchemas { self: Schema.type => case10: Case[A10, Z], case11: Case[A11, Z], case12: Case[A12, Z], - override val annotations: Chunk[Any] + annotations: Chunk[Any] = Chunk.empty ) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11], Prism[Z, A12]) + override def annotate(annotation: Any): Enum12[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11], b.Prism[Z, A12]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3), b.makePrism(self, case4), b.makePrism(self, case5), b.makePrism(self, case6), b.makePrism(self, case7), b.makePrism(self, case8), b.makePrism(self, case9), b.makePrism(self, case10), b.makePrism(self, case11), b.makePrism(self, case12)) @@ -554,10 +622,12 @@ sealed trait EnumSchemas { self: Schema.type => case11: Case[A11, Z], case12: Case[A12, Z], case13: Case[A13, Z], - override val annotations: Chunk[Any] + annotations: Chunk[Any] = Chunk.empty ) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11], Prism[Z, A12], Prism[Z, A13]) + override def annotate(annotation: Any): Enum13[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11], b.Prism[Z, A12], b.Prism[Z, A13]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3), b.makePrism(self, case4), b.makePrism(self, case5), b.makePrism(self, case6), b.makePrism(self, case7), b.makePrism(self, case8), b.makePrism(self, case9), b.makePrism(self, case10), b.makePrism(self, case11), b.makePrism(self, case12), b.makePrism(self, case13)) @@ -594,9 +664,12 @@ sealed trait EnumSchemas { self: Schema.type => case12: Case[A12, Z], case13: Case[A13, Z], case14: Case[A14, Z], - override val annotations: Chunk[Any] + annotations: Chunk[Any] = Chunk.empty ) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11], Prism[Z, A12], Prism[Z, A13], Prism[Z, A14]) + + override def annotate(annotation: Any): Enum14[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11], b.Prism[Z, A12], b.Prism[Z, A13], b.Prism[Z, A14]) = (b.makePrism(self, case1), b.makePrism(self, case2), b.makePrism(self, case3), b.makePrism(self, case4), b.makePrism(self, case5), b.makePrism(self, case6), b.makePrism(self, case7), b.makePrism(self, case8), b.makePrism(self, case9), b.makePrism(self, case10), b.makePrism(self, case11), b.makePrism(self, case12), b.makePrism(self, case13), b.makePrism(self, case14)) @@ -634,9 +707,12 @@ sealed trait EnumSchemas { self: Schema.type => case13: Case[A13, Z], case14: Case[A14, Z], case15: Case[A15, Z], - override val annotations: Chunk[Any] + annotations: Chunk[Any] = Chunk.empty ) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11], Prism[Z, A12], Prism[Z, A13], Prism[Z, A14], Prism[Z, A15]) + + override def annotate(annotation: Any): Enum15[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11], b.Prism[Z, A12], b.Prism[Z, A13], b.Prism[Z, A14], b.Prism[Z, A15]) = ( b.makePrism(self, case1), @@ -696,6 +772,8 @@ sealed trait EnumSchemas { self: Schema.type => ) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11], Prism[Z, A12], Prism[Z, A13], Prism[Z, A14], Prism[Z, A15], Prism[Z, A16]) + override def annotate(annotation: Any): Enum16[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11], b.Prism[Z, A12], b.Prism[Z, A13], b.Prism[Z, A14], b.Prism[Z, A15], b.Prism[Z, A16]) = ( b.makePrism(self, case1), @@ -754,10 +832,12 @@ sealed trait EnumSchemas { self: Schema.type => case15: Case[A15, Z], case16: Case[A16, Z], case17: Case[A17, Z], - override val annotations: Chunk[Any] + annotations: Chunk[Any] = Chunk.empty ) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11], Prism[Z, A12], Prism[Z, A13], Prism[Z, A14], Prism[Z, A15], Prism[Z, A16], Prism[Z, A17]) + override def annotate(annotation: Any): Enum17[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11], b.Prism[Z, A12], b.Prism[Z, A13], b.Prism[Z, A14], b.Prism[Z, A15], b.Prism[Z, A16], b.Prism[Z, A17]) = ( b.makePrism(self, case1), @@ -819,10 +899,12 @@ sealed trait EnumSchemas { self: Schema.type => case16: Case[A16, Z], case17: Case[A17, Z], case18: Case[A18, Z], - override val annotations: Chunk[Any] + annotations: Chunk[Any] = Chunk.empty ) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11], Prism[Z, A12], Prism[Z, A13], Prism[Z, A14], Prism[Z, A15], Prism[Z, A16], Prism[Z, A17], Prism[Z, A18]) + override def annotate(annotation: Any): Enum18[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11], b.Prism[Z, A12], b.Prism[Z, A13], b.Prism[Z, A14], b.Prism[Z, A15], b.Prism[Z, A16], b.Prism[Z, A17], b.Prism[Z, A18]) = ( b.makePrism(self, case1), @@ -887,10 +969,12 @@ sealed trait EnumSchemas { self: Schema.type => case17: Case[A17, Z], case18: Case[A18, Z], case19: Case[A19, Z], - override val annotations: Chunk[Any] + annotations: Chunk[Any] = Chunk.empty ) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11], Prism[Z, A12], Prism[Z, A13], Prism[Z, A14], Prism[Z, A15], Prism[Z, A16], Prism[Z, A17], Prism[Z, A18], Prism[Z, A19]) + override def annotate(annotation: Any): Enum19[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11], b.Prism[Z, A12], b.Prism[Z, A13], b.Prism[Z, A14], b.Prism[Z, A15], b.Prism[Z, A16], b.Prism[Z, A17], b.Prism[Z, A18], b.Prism[Z, A19]) = ( b.makePrism(self, case1), @@ -958,10 +1042,12 @@ sealed trait EnumSchemas { self: Schema.type => case18: Case[A18, Z], case19: Case[A19, Z], case20: Case[A20, Z], - override val annotations: Chunk[Any] + annotations: Chunk[Any] = Chunk.empty ) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11], Prism[Z, A12], Prism[Z, A13], Prism[Z, A14], Prism[Z, A15], Prism[Z, A16], Prism[Z, A17], Prism[Z, A18], Prism[Z, A19], Prism[Z, A20]) + override def annotate(annotation: Any): Enum20[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11], b.Prism[Z, A12], b.Prism[Z, A13], b.Prism[Z, A14], b.Prism[Z, A15], b.Prism[Z, A16], b.Prism[Z, A17], b.Prism[Z, A18], b.Prism[Z, A19], b.Prism[Z, A20]) = ( b.makePrism(self, case1), @@ -1032,10 +1118,12 @@ sealed trait EnumSchemas { self: Schema.type => case19: Case[A19, Z], case20: Case[A20, Z], case21: Case[A21, Z], - override val annotations: Chunk[Any] + annotations: Chunk[Any] = Chunk.empty ) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11], Prism[Z, A12], Prism[Z, A13], Prism[Z, A14], Prism[Z, A15], Prism[Z, A16], Prism[Z, A17], Prism[Z, A18], Prism[Z, A19], Prism[Z, A20], Prism[Z, A21]) + override def annotate(annotation: Any): Enum21[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors( b: AccessorBuilder ): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11], b.Prism[Z, A12], b.Prism[Z, A13], b.Prism[Z, A14], b.Prism[Z, A15], b.Prism[Z, A16], b.Prism[Z, A17], b.Prism[Z, A18], b.Prism[Z, A19], b.Prism[Z, A20], b.Prism[Z, A21]) = @@ -1111,10 +1199,12 @@ sealed trait EnumSchemas { self: Schema.type => case20: Case[A20, Z], case21: Case[A21, Z], case22: Case[A22, Z], - override val annotations: Chunk[Any] + annotations: Chunk[Any] = Chunk.empty ) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Prism[Z, A1], Prism[Z, A2], Prism[Z, A3], Prism[Z, A4], Prism[Z, A5], Prism[Z, A6], Prism[Z, A7], Prism[Z, A8], Prism[Z, A9], Prism[Z, A10], Prism[Z, A11], Prism[Z, A12], Prism[Z, A13], Prism[Z, A14], Prism[Z, A15], Prism[Z, A16], Prism[Z, A17], Prism[Z, A18], Prism[Z, A19], Prism[Z, A20], Prism[Z, A21], Prism[Z, A22]) + override def annotate(annotation: Any): Enum22[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors( b: AccessorBuilder ): (b.Prism[Z, A1], b.Prism[Z, A2], b.Prism[Z, A3], b.Prism[Z, A4], b.Prism[Z, A5], b.Prism[Z, A6], b.Prism[Z, A7], b.Prism[Z, A8], b.Prism[Z, A9], b.Prism[Z, A10], b.Prism[Z, A11], b.Prism[Z, A12], b.Prism[Z, A13], b.Prism[Z, A14], b.Prism[Z, A15], b.Prism[Z, A16], b.Prism[Z, A17], b.Prism[Z, A18], b.Prism[Z, A19], b.Prism[Z, A20], b.Prism[Z, A21], b.Prism[Z, A22]) = @@ -1169,9 +1259,11 @@ sealed trait EnumSchemas { self: Schema.type => case22.id -> case22.codec ) } - sealed case class EnumN[Z, C <: CaseSet.Aux[Z]](caseSet: C, override val annotations: Chunk[Any]) extends Enum[Z] { self => + sealed case class EnumN[Z, C <: CaseSet.Aux[Z]](caseSet: C, annotations: Chunk[Any] = Chunk.empty) extends Enum[Z] { self => override type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = caseSet.Accessors[Z, Lens, Prism, Traversal] + override def annotate(annotation: Any): EnumN[Z, C] = copy(annotations = annotations :+ annotation) + override def structure: ListMap[String, Schema[_]] = caseSet.toMap override def makeAccessors(b: AccessorBuilder): caseSet.Accessors[Z, b.Lens, b.Prism, b.Traversal] = caseSet.makeAccessors(self, b) @@ -1620,7 +1712,7 @@ sealed trait RecordSchemas { self: Schema.type => override def toString: String = s"Field($label,$schema)" } - sealed case class GenericRecord(fieldSet: FieldSet) extends Record[ListMap[String, _]] { self => + sealed case class GenericRecord(fieldSet: FieldSet, annotations: Chunk[Any] = Chunk.empty) extends Record[ListMap[String, _]] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = fieldSet.Accessors[ListMap[String, _], Lens, Prism, Traversal] @@ -1633,12 +1725,20 @@ sealed trait RecordSchemas { self: Schema.type => Right(ListMap(structure.map(_.label).zip(values): _*)) else Left(s"wrong number of values for $structure") + + /** + * Returns a new schema that with `annotation` + */ + override def annotate(annotation: Any): GenericRecord = copy(annotations = annotations :+ annotation) + } sealed case class CaseClass1[A, Z](override val annotations: Chunk[Any] = Chunk.empty, field: Field[A], construct: A => Z, extractField: Z => A) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = Lens[Z, A] + override def annotate(annotation: Any): CaseClass1[A, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): b.Lens[Z, A] = b.makeLens(self, field) override def structure: Chunk[Field[_]] = Chunk(field) @@ -1657,6 +1757,8 @@ sealed trait RecordSchemas { self: Schema.type => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2]) + override def annotate(annotation: Any): CaseClass2[A1, A2, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2]) = (b.makeLens(self, field1), b.makeLens(self, field2)) override def structure: Chunk[Field[_]] = Chunk(field1, field2) @@ -1675,6 +1777,8 @@ sealed trait RecordSchemas { self: Schema.type => sealed case class CaseClass3[A1, A2, A3, Z](override val annotations: Chunk[Any] = Chunk.empty, field1: Field[A1], field2: Field[A2], field3: Field[A3], construct: (A1, A2, A3) => Z, extractField1: Z => A1, extractField2: Z => A2, extractField3: Z => A3) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3]) + override def annotate(annotation: Any): CaseClass3[A1, A2, A3, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3)) @@ -1695,6 +1799,8 @@ sealed trait RecordSchemas { self: Schema.type => sealed case class CaseClass4[A1, A2, A3, A4, Z](override val annotations: Chunk[Any] = Chunk.empty, field1: Field[A1], field2: Field[A2], field3: Field[A3], field4: Field[A4], construct: (A1, A2, A3, A4) => Z, extractField1: Z => A1, extractField2: Z => A2, extractField3: Z => A3, extractField4: Z => A4) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4]) + override def annotate(annotation: Any): CaseClass4[A1, A2, A3, A4, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3), b.makeLens(self, field4)) @@ -1715,6 +1821,8 @@ sealed trait RecordSchemas { self: Schema.type => sealed case class CaseClass5[A1, A2, A3, A4, A5, Z](override val annotations: Chunk[Any] = Chunk.empty, field1: Field[A1], field2: Field[A2], field3: Field[A3], field4: Field[A4], field5: Field[A5], construct: (A1, A2, A3, A4, A5) => Z, extractField1: Z => A1, extractField2: Z => A2, extractField3: Z => A3, extractField4: Z => A4, extractField5: Z => A5) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5]) + override def annotate(annotation: Any): CaseClass5[A1, A2, A3, A4, A5, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3), b.makeLens(self, field4), b.makeLens(self, field5)) @@ -1749,6 +1857,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6]) + override def annotate(annotation: Any): CaseClass6[A1, A2, A3, A4, A5, A6, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3), b.makeLens(self, field4), b.makeLens(self, field5), b.makeLens(self, field6)) @@ -1786,6 +1896,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7]) + override def annotate(annotation: Any): CaseClass7[A1, A2, A3, A4, A5, A6, A7, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3), b.makeLens(self, field4), b.makeLens(self, field5), b.makeLens(self, field6), b.makeLens(self, field7)) @@ -1825,6 +1937,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8]) + override def annotate(annotation: Any): CaseClass8[A1, A2, A3, A4, A5, A6, A7, A8, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3), b.makeLens(self, field4), b.makeLens(self, field5), b.makeLens(self, field6), b.makeLens(self, field7), b.makeLens(self, field8)) @@ -1866,6 +1980,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9]) + override def annotate(annotation: Any): CaseClass9[A1, A2, A3, A4, A5, A6, A7, A8, A9, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3), b.makeLens(self, field4), b.makeLens(self, field5), b.makeLens(self, field6), b.makeLens(self, field7), b.makeLens(self, field8), b.makeLens(self, field9)) override def structure: Chunk[Field[_]] = @@ -1909,6 +2025,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10]) + override def annotate(annotation: Any): CaseClass10[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3), b.makeLens(self, field4), b.makeLens(self, field5), b.makeLens(self, field6), b.makeLens(self, field7), b.makeLens(self, field8), b.makeLens(self, field9), b.makeLens(self, field10)) @@ -1954,6 +2072,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11]) + override def annotate(annotation: Any): CaseClass11[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3), b.makeLens(self, field4), b.makeLens(self, field5), b.makeLens(self, field6), b.makeLens(self, field7), b.makeLens(self, field8), b.makeLens(self, field9), b.makeLens(self, field10), b.makeLens(self, field11)) @@ -2001,6 +2121,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11], Lens[Z, A12]) + override def annotate(annotation: Any): CaseClass12[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11], b.Lens[Z, A12]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3), b.makeLens(self, field4), b.makeLens(self, field5), b.makeLens(self, field6), b.makeLens(self, field7), b.makeLens(self, field8), b.makeLens(self, field9), b.makeLens(self, field10), b.makeLens(self, field11), b.makeLens(self, field12)) @@ -2050,6 +2172,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11], Lens[Z, A12], Lens[Z, A13]) + override def annotate(annotation: Any): CaseClass13[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11], b.Lens[Z, A12], b.Lens[Z, A13]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3), b.makeLens(self, field4), b.makeLens(self, field5), b.makeLens(self, field6), b.makeLens(self, field7), b.makeLens(self, field8), b.makeLens(self, field9), b.makeLens(self, field10), b.makeLens(self, field11), b.makeLens(self, field12), b.makeLens(self, field13)) @@ -2101,6 +2225,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11], Lens[Z, A12], Lens[Z, A13], Lens[Z, A14]) + override def annotate(annotation: Any): CaseClass14[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11], b.Lens[Z, A12], b.Lens[Z, A13], b.Lens[Z, A14]) = (b.makeLens(self, field1), b.makeLens(self, field2), b.makeLens(self, field3), b.makeLens(self, field4), b.makeLens(self, field5), b.makeLens(self, field6), b.makeLens(self, field7), b.makeLens(self, field8), b.makeLens(self, field9), b.makeLens(self, field10), b.makeLens(self, field11), b.makeLens(self, field12), b.makeLens(self, field13), b.makeLens(self, field14)) @@ -2172,6 +2298,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11], Lens[Z, A12], Lens[Z, A13], Lens[Z, A14], Lens[Z, A15]) + override def annotate(annotation: Any): CaseClass15[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11], b.Lens[Z, A12], b.Lens[Z, A13], b.Lens[Z, A14], b.Lens[Z, A15]) = ( b.makeLens(self, field1), @@ -2262,6 +2390,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11], Lens[Z, A12], Lens[Z, A13], Lens[Z, A14], Lens[Z, A15], Lens[Z, A16]) + override def annotate(annotation: Any): CaseClass16[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11], b.Lens[Z, A12], b.Lens[Z, A13], b.Lens[Z, A14], b.Lens[Z, A15], b.Lens[Z, A16]) = ( b.makeLens(self, field1), @@ -2356,6 +2486,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11], Lens[Z, A12], Lens[Z, A13], Lens[Z, A14], Lens[Z, A15], Lens[Z, A16], Lens[Z, A17]) + override def annotate(annotation: Any): CaseClass17[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11], b.Lens[Z, A12], b.Lens[Z, A13], b.Lens[Z, A14], b.Lens[Z, A15], b.Lens[Z, A16], b.Lens[Z, A17]) = ( b.makeLens(self, field1), @@ -2454,6 +2586,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11], Lens[Z, A12], Lens[Z, A13], Lens[Z, A14], Lens[Z, A15], Lens[Z, A16], Lens[Z, A17], Lens[Z, A18]) + override def annotate(annotation: Any): CaseClass18[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11], b.Lens[Z, A12], b.Lens[Z, A13], b.Lens[Z, A14], b.Lens[Z, A15], b.Lens[Z, A16], b.Lens[Z, A17], b.Lens[Z, A18]) = ( b.makeLens(self, field1), @@ -2556,6 +2690,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11], Lens[Z, A12], Lens[Z, A13], Lens[Z, A14], Lens[Z, A15], Lens[Z, A16], Lens[Z, A17], Lens[Z, A18], Lens[Z, A19]) + override def annotate(annotation: Any): CaseClass19[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11], b.Lens[Z, A12], b.Lens[Z, A13], b.Lens[Z, A14], b.Lens[Z, A15], b.Lens[Z, A16], b.Lens[Z, A17], b.Lens[Z, A18], b.Lens[Z, A19]) = ( b.makeLens(self, field1), @@ -2662,6 +2798,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11], Lens[Z, A12], Lens[Z, A13], Lens[Z, A14], Lens[Z, A15], Lens[Z, A16], Lens[Z, A17], Lens[Z, A18], Lens[Z, A19], Lens[Z, A20]) + override def annotate(annotation: Any): CaseClass20[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11], b.Lens[Z, A12], b.Lens[Z, A13], b.Lens[Z, A14], b.Lens[Z, A15], b.Lens[Z, A16], b.Lens[Z, A17], b.Lens[Z, A18], b.Lens[Z, A19], b.Lens[Z, A20]) = ( b.makeLens(self, field1), @@ -2772,6 +2910,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11], Lens[Z, A12], Lens[Z, A13], Lens[Z, A14], Lens[Z, A15], Lens[Z, A16], Lens[Z, A17], Lens[Z, A18], Lens[Z, A19], Lens[Z, A20], Lens[Z, A21]) + override def annotate(annotation: Any): CaseClass21[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11], b.Lens[Z, A12], b.Lens[Z, A13], b.Lens[Z, A14], b.Lens[Z, A15], b.Lens[Z, A16], b.Lens[Z, A17], b.Lens[Z, A18], b.Lens[Z, A19], b.Lens[Z, A20], b.Lens[Z, A21]) = ( b.makeLens(self, field1), @@ -2886,6 +3026,8 @@ sealed trait RecordSchemas { self: Schema.type => ) extends Record[Z] { self => type Accessors[Lens[_, _], Prism[_, _], Traversal[_, _]] = (Lens[Z, A1], Lens[Z, A2], Lens[Z, A3], Lens[Z, A4], Lens[Z, A5], Lens[Z, A6], Lens[Z, A7], Lens[Z, A8], Lens[Z, A9], Lens[Z, A10], Lens[Z, A11], Lens[Z, A12], Lens[Z, A13], Lens[Z, A14], Lens[Z, A15], Lens[Z, A16], Lens[Z, A17], Lens[Z, A18], Lens[Z, A19], Lens[Z, A20], Lens[Z, A21], Lens[Z, A22]) + override def annotate(annotation: Any): CaseClass22[A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16, A17, A18, A19, A20, A21, A22, Z] = copy(annotations = annotations :+ annotation) + override def makeAccessors(b: AccessorBuilder): (b.Lens[Z, A1], b.Lens[Z, A2], b.Lens[Z, A3], b.Lens[Z, A4], b.Lens[Z, A5], b.Lens[Z, A6], b.Lens[Z, A7], b.Lens[Z, A8], b.Lens[Z, A9], b.Lens[Z, A10], b.Lens[Z, A11], b.Lens[Z, A12], b.Lens[Z, A13], b.Lens[Z, A14], b.Lens[Z, A15], b.Lens[Z, A16], b.Lens[Z, A17], b.Lens[Z, A18], b.Lens[Z, A19], b.Lens[Z, A20], b.Lens[Z, A21], b.Lens[Z, A22]) = ( b.makeLens(self, field1), diff --git a/zio-schema/shared/src/main/scala/zio/schema/SchemaOrdering.scala b/zio-schema/shared/src/main/scala/zio/schema/SchemaOrdering.scala index 6fa7d6c3d..4b350a7e6 100644 --- a/zio-schema/shared/src/main/scala/zio/schema/SchemaOrdering.scala +++ b/zio-schema/shared/src/main/scala/zio/schema/SchemaOrdering.scala @@ -13,35 +13,35 @@ object SchemaOrdering { } private def compareBySchema[A](schema: Schema[A])(l: DynamicValue, r: DynamicValue): Int = (schema, l, r) match { - case (schema: Schema.Lazy[_], l, r) => compareBySchema(schema.schema)(l, r) - case (Schema.Primitive(UnitType), _, _) => 0 - case (Schema.Primitive(standardType), Primitive(lVal, lType), Primitive(rVal, rType)) + case (schema: Schema.Lazy[_], l, r) => compareBySchema(schema.schema)(l, r) + case (Schema.Primitive(UnitType, _), _, _) => 0 + case (Schema.Primitive(standardType, _), Primitive(lVal, lType), Primitive(rVal, rType)) if lType == rType && standardType == lType => lType.compare(lVal, rVal) - case (Schema.EitherSchema(leftSchema, _), LeftValue(lVal), LeftValue(rVal)) => + case (Schema.EitherSchema(leftSchema, _, _), LeftValue(lVal), LeftValue(rVal)) => compareBySchema(leftSchema)(lVal, rVal) - case (Schema.EitherSchema(_, rightSchema), RightValue(lVal), RightValue(rVal)) => + case (Schema.EitherSchema(_, rightSchema, _), RightValue(lVal), RightValue(rVal)) => compareBySchema(rightSchema)(lVal, rVal) - case (Schema.EitherSchema(_, _), LeftValue(_), RightValue(_)) => -1 - case (Schema.EitherSchema(_, _), RightValue(_), LeftValue(_)) => 1 - case (Schema.Optional(innerSchema), SomeValue(lVal), SomeValue(rVal)) => + case (Schema.EitherSchema(_, _, _), LeftValue(_), RightValue(_)) => -1 + case (Schema.EitherSchema(_, _, _), RightValue(_), LeftValue(_)) => 1 + case (Schema.Optional(innerSchema, _), SomeValue(lVal), SomeValue(rVal)) => compareBySchema(innerSchema)(lVal, rVal) - case (Schema.Optional(_), NoneValue, SomeValue(_)) => -1 - case (Schema.Optional(_), SomeValue(_), NoneValue) => 1 - case (Schema.Tuple(lSchema, rSchema), l: Tuple, r: Tuple) => { + case (Schema.Optional(_, _), NoneValue, SomeValue(_)) => -1 + case (Schema.Optional(_, _), SomeValue(_), NoneValue) => 1 + case (Schema.Tuple(lSchema, rSchema, _), l: Tuple, r: Tuple) => { val leftComparison = compareBySchema(lSchema)(l.left, r.left) if (leftComparison != 0) leftComparison else compareBySchema(rSchema)(l.right, r.right) } - case (Schema.Sequence(schema, _, _), Sequence(lVal), Sequence(rVal)) => + case (Schema.Sequence(schema, _, _, _), Sequence(lVal), Sequence(rVal)) => compareSequences(lVal, rVal, compareBySchema(schema)) - case (Schema.Fail(_), Error(lVal), Error(rVal)) => lVal.compareTo(rVal) - case (Schema.Transform(_, _, _), Transform(Error(lval)), Transform(Error(rVal))) => lval.compareTo(rVal) - case (Schema.Transform(_, _, _), Transform(Error(_)), Transform(_)) => -1 - case (Schema.Transform(_, _, _), Transform(_), Transform(Error(_))) => 1 - case (Schema.Transform(schemaA, _, _), Transform(lVal), Transform(rVal)) => + case (Schema.Fail(_, _), Error(lVal), Error(rVal)) => lVal.compareTo(rVal) + case (Schema.Transform(_, _, _, _), Transform(Error(lval)), Transform(Error(rVal))) => lval.compareTo(rVal) + case (Schema.Transform(_, _, _, _), Transform(Error(_)), Transform(_)) => -1 + case (Schema.Transform(_, _, _, _), Transform(_), Transform(Error(_))) => 1 + case (Schema.Transform(schemaA, _, _, _), Transform(lVal), Transform(rVal)) => compareBySchema(schemaA)(lVal, rVal) case (e: Schema.Enum[_], Enumeration((lField, lVal)), Enumeration((rField, rVal))) if lField == rField => compareBySchema(e.structure(lField))(lVal, rVal) diff --git a/zio-schema/shared/src/main/scala/zio/schema/ast/SchemaAst.scala b/zio-schema/shared/src/main/scala/zio/schema/ast/SchemaAst.scala index 66d84784a..22e6dee45 100644 --- a/zio-schema/shared/src/main/scala/zio/schema/ast/SchemaAst.scala +++ b/zio-schema/shared/src/main/scala/zio/schema/ast/SchemaAst.scala @@ -173,23 +173,23 @@ object SchemaAst { @tailrec def fromSchema[A](schema: Schema[A]): SchemaAst = schema match { - case Schema.Primitive(typ) => Value(typ, NodePath.root) - case Schema.Fail(message) => FailNode(message, NodePath.root) - case Schema.Optional(schema) => subtree(NodePath.root, Chunk.empty, schema, optional = true) - case Schema.EitherSchema(left, right) => + case Schema.Primitive(typ, _) => Value(typ, NodePath.root) + case Schema.Fail(message, _) => FailNode(message, NodePath.root) + case Schema.Optional(schema, _) => subtree(NodePath.root, Chunk.empty, schema, optional = true) + case Schema.EitherSchema(left, right, _) => NodeBuilder(NodePath.root, Chunk.empty) .addLabelledSubtree("left", left) .addLabelledSubtree("right", right) .buildSum() - case Schema.Tuple(left, right) => + case Schema.Tuple(left, right, _) => NodeBuilder(NodePath.root, Chunk.empty) .addLabelledSubtree("left", left) .addLabelledSubtree("right", right) .buildProduct() - case Schema.Sequence(schema, _, _) => + case Schema.Sequence(schema, _, _, _) => subtree(NodePath.root, Chunk.empty, schema, dimensions = 1) - case Schema.Transform(schema, _, _) => subtree(NodePath.root, Chunk.empty, schema) - case lzy @ Schema.Lazy(_) => fromSchema(lzy.schema) + case Schema.Transform(schema, _, _, _) => subtree(NodePath.root, Chunk.empty, schema) + case lzy @ Schema.Lazy(_) => fromSchema(lzy.schema) case s: Schema.Record[A] => s.structure .foldLeft(NodeBuilder(NodePath.root, Chunk(s.hashCode() -> NodePath.root))) { (node, field) => @@ -203,7 +203,7 @@ object SchemaAst { node.addLabelledSubtree(id, schema) } .buildSum() - case Schema.Meta(ast) => ast + case Schema.Meta(ast, _) => ast } private[schema] def subtree( @@ -221,22 +221,22 @@ object SchemaAst { } .getOrElse { schema match { - case Schema.Primitive(typ) => Value(typ, path, optional, dimensions) - case Schema.Optional(schema) => subtree(path, lineage, schema, optional = true, dimensions) - case Schema.EitherSchema(left, right) => + case Schema.Primitive(typ, _) => Value(typ, path, optional, dimensions) + case Schema.Optional(schema, _) => subtree(path, lineage, schema, optional = true, dimensions) + case Schema.EitherSchema(left, right, _) => NodeBuilder(path, lineage, optional, dimensions) .addLabelledSubtree("left", left) .addLabelledSubtree("right", right) .buildSum() - case Schema.Tuple(left, right) => + case Schema.Tuple(left, right, _) => NodeBuilder(path, lineage, optional, dimensions) .addLabelledSubtree("left", left) .addLabelledSubtree("right", right) .buildProduct() - case Schema.Sequence(schema, _, _) => + case Schema.Sequence(schema, _, _, _) => subtree(path, lineage, schema, optional, dimensions + 1) - case Schema.Transform(schema, _, _) => subtree(path, lineage, schema, optional, dimensions) - case lzy @ Schema.Lazy(_) => subtree(path, lineage, lzy.schema, optional, dimensions) + case Schema.Transform(schema, _, _, _) => subtree(path, lineage, schema, optional, dimensions) + case lzy @ Schema.Lazy(_) => subtree(path, lineage, lzy.schema, optional, dimensions) case s: Schema.Record[_] => s.structure .foldLeft(NodeBuilder(path, lineage :+ (s.hashCode() -> path), optional, dimensions)) { (node, field) => @@ -250,15 +250,15 @@ object SchemaAst { node.addLabelledSubtree(id, schema) } .buildSum() - case Schema.Fail(message) => FailNode(message, path) - case Schema.Meta(ast) => ast + case Schema.Fail(message, _) => FailNode(message, path) + case Schema.Meta(ast, _) => ast } } private[schema] def materialize(ast: SchemaAst, refs: Map[NodePath, SchemaAst] = Map.empty): Schema[_] = { val baseSchema = ast match { case SchemaAst.Value(typ, _, _, _) => - Schema.Primitive(typ) + Schema.Primitive(typ, Chunk.empty) case SchemaAst.FailNode(msg, _, _, _) => Schema.Fail(msg) case SchemaAst.Ref(refPath, _, _, _) => refs diff --git a/zio-schema/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala b/zio-schema/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala index ece9f04d7..a5fe3aed3 100644 --- a/zio-schema/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala +++ b/zio-schema/shared/src/test/scala/zio/schema/DeriveSchemaSpec.scala @@ -18,7 +18,7 @@ object DeriveSchemaSpec extends DefaultRunnableSpec { sealed case class UserId(id: String) @annotation1("foo") - sealed case class User(name: String, @annotation1("foo") @annotation2("bar") id: UserId) + sealed case class User(name: String, @annotation1("foo") @annotation2("bar") userId: UserId) sealed trait Status case class Ok(response: List[String]) extends Status @@ -71,7 +71,7 @@ object DeriveSchemaSpec extends DefaultRunnableSpec { val derived: Schema[UserId] = Schema[UserId] val expected: Schema[UserId] = Schema.CaseClass1( - annotations = Chunk.empty, + annotations = Chunk(annotation1("bar")), field = Schema.Field("id", Schema.Primitive(StandardType.StringType)), UserId.apply, (uid: UserId) => uid.id @@ -89,13 +89,13 @@ object DeriveSchemaSpec extends DefaultRunnableSpec { val derived: Schema[User] = Schema[User] val expected: Schema[User] = Schema.CaseClass2( - annotations = Chunk.empty, + annotations = Chunk(annotation1("foo")), field1 = Schema.Field("name", Schema.Primitive(StandardType.StringType)), field2 = Schema.Field( - "id", + "userId", Schema.CaseClass1( - annotations = Chunk.empty, - field = Schema.Field("id", Schema.Primitive(StandardType.StringType)), + annotations = Chunk(annotation1("bar")), + field = Schema.Field("id", Schema.Primitive(StandardType.StringType, Chunk.empty)), construct = UserId.apply, extractField = (uid: UserId) => uid.id ), @@ -103,7 +103,7 @@ object DeriveSchemaSpec extends DefaultRunnableSpec { ), User.apply, (u: User) => u.name, - (u: User) => u.id + (u: User) => u.userId ) assert(derived)(hasSameSchema(expected)) }, @@ -114,8 +114,8 @@ object DeriveSchemaSpec extends DefaultRunnableSpec { Schema.Case[AnnotatedSumType1, AnnotatedSumType]( id = "AnnotatedSumType1", codec = Schema.CaseClass1( - annotations = Chunk.empty, - field = Schema.Field[Int]("value", Schema.Primitive(StandardType.IntType), Chunk.empty), + annotations = Chunk(annotation2("bar")), + field = Schema.Field[Int]("value", Schema.Primitive(StandardType.IntType, Chunk.empty), Chunk.empty), construct = AnnotatedSumType1.apply, extractField = (a: AnnotatedSumType1) => a.value ), @@ -125,8 +125,8 @@ object DeriveSchemaSpec extends DefaultRunnableSpec { Schema.Case[AnnotatedSumType2, AnnotatedSumType]( id = "AnnotatedSumType2", codec = Schema.CaseClass1( - annotations = Chunk.empty, - field = Schema.Field[Int]("value", Schema.Primitive(StandardType.IntType), Chunk.empty), + annotations = Chunk(annotation3("baz")), + field = Schema.Field[Int]("value", Schema.Primitive(StandardType.IntType, Chunk.empty), Chunk.empty), construct = AnnotatedSumType2.apply, extractField = (a: AnnotatedSumType2) => a.value ), diff --git a/zio-schema/shared/src/test/scala/zio/schema/DiffSpec.scala b/zio-schema/shared/src/test/scala/zio/schema/DiffSpec.scala index b9658395d..50924c17e 100644 --- a/zio-schema/shared/src/test/scala/zio/schema/DiffSpec.scala +++ b/zio-schema/shared/src/test/scala/zio/schema/DiffSpec.scala @@ -849,7 +849,7 @@ object DiffSpec extends DefaultRunnableSpec { test("different") { val f = (i: Int) => Right(i.toString()) val g = (s: String) => scala.util.Try(s.toInt).toEither.left.map(_.toString()) - implicit val schema = Schema.Transform[Int, String](Schema[Int], f, g) + implicit val schema = Schema.Transform[Int, String](Schema[Int], f, g, Chunk.empty) val diff = schema.diff("4", "6") assertTrue(diff == Diff.Number(-2)) && assertTrue(diff.patch("4") == Right("6")) && diff --git a/zio-schema/shared/src/test/scala/zio/schema/DynamicValueGen.scala b/zio-schema/shared/src/test/scala/zio/schema/DynamicValueGen.scala index 4e49d6f2c..592efde40 100644 --- a/zio-schema/shared/src/test/scala/zio/schema/DynamicValueGen.scala +++ b/zio-schema/shared/src/test/scala/zio/schema/DynamicValueGen.scala @@ -47,7 +47,7 @@ object DynamicValueGen { //scalafmt: { maxColumn = 400 } def anyDynamicValueOfSchema[A](schema: Schema[A]): Gen[Random with Sized, DynamicValue] = schema match { - case Schema.Primitive(standardType) => anyPrimitiveDynamicValue(standardType) + case Schema.Primitive(standardType, _) => anyPrimitiveDynamicValue(standardType) case s: Schema.Record[A] => anyDynamicValueWithStructure(s.structure) case Schema.Enum1(case1, _) => anyDynamicValueOfEnum(Chunk(case1)) case Schema.Enum2(case1, case2, _) => anyDynamicValueOfEnum(Chunk(case1, case2)) @@ -72,15 +72,15 @@ object DynamicValueGen { case Schema.Enum21(case1, case2, case3, case4, case5, case6, case7, case8, case9, case10, case11, case12, case13, case14, case15, case16, case17, case18, case19, case20, case21, _) => anyDynamicValueOfEnum(Chunk(case1, case2, case3, case4, case5, case6, case7, case8, case9, case10, case11, case12, case13, case14, case15, case16, case17, case18, case19, case20, case21)) case Schema.Enum22(case1, case2, case3, case4, case5, case6, case7, case8, case9, case10, case11, case12, case13, case14, case15, case16, case17, case18, case19, case20, case21, case22, _) => anyDynamicValueOfEnum(Chunk(case1, case2, case3, case4, case5, case6, case7, case8, case9, case10, case11, case12, case13, case14, case15, case16, case17, case18, case19, case20, case21, case22)) case Schema.EnumN(cases, _) => anyDynamicValueOfEnum(Chunk.fromIterable(cases.toSeq)) - case Schema.Sequence(schema, _, _) => Gen.chunkOfBounded(0, 2)(anyDynamicValueOfSchema(schema)).map(DynamicValue.Sequence(_)) - case Schema.Optional(schema) => Gen.oneOf(anyDynamicSomeValueOfSchema(schema), Gen.const(DynamicValue.NoneValue)) - case Schema.Tuple(left, right) => anyDynamicTupleValue(left, right) - case Schema.EitherSchema(left, right) => + case Schema.Sequence(schema, _, _, _) => Gen.chunkOfBounded(0, 2)(anyDynamicValueOfSchema(schema)).map(DynamicValue.Sequence(_)) + case Schema.Optional(schema, _) => Gen.oneOf(anyDynamicSomeValueOfSchema(schema), Gen.const(DynamicValue.NoneValue)) + case Schema.Tuple(left, right, _) => anyDynamicTupleValue(left, right) + case Schema.EitherSchema(left, right, _) => Gen.oneOf(anyDynamicLeftValueOfSchema(left), anyDynamicRightValueOfSchema(right)) - case Schema.Transform(schema, _, _) => anyDynamicValueOfSchema(schema).map(DynamicValue.Transform(_)) - case Schema.Fail(message) => Gen.const(DynamicValue.Error(message)) - case l @ Schema.Lazy(_) => anyDynamicValueOfSchema(l.schema) - case Schema.Meta(meta) => anyDynamicValueOfSchema(meta.toSchema) + case Schema.Transform(schema, _, _, _) => anyDynamicValueOfSchema(schema).map(DynamicValue.Transform(_)) + case Schema.Fail(message, _) => Gen.const(DynamicValue.Error(message)) + case l @ Schema.Lazy(_) => anyDynamicValueOfSchema(l.schema) + case Schema.Meta(meta, _) => anyDynamicValueOfSchema(meta.toSchema) } //scalafmt: { maxColumn = 120 } diff --git a/zio-schema/shared/src/test/scala/zio/schema/DynamicValueSpec.scala b/zio-schema/shared/src/test/scala/zio/schema/DynamicValueSpec.scala index b9f58f996..f62b8737c 100644 --- a/zio-schema/shared/src/test/scala/zio/schema/DynamicValueSpec.scala +++ b/zio-schema/shared/src/test/scala/zio/schema/DynamicValueSpec.scala @@ -75,7 +75,7 @@ object DynamicValueSpec extends DefaultRunnableSpec { val primitiveTests: List[ZSpec[Sized with Random with TestConfig, Nothing]] = schemasAndGens.map { case SchemaTest(name, standardType, gen) => testM(s"round-trips $name") { - dynamicValueLaw(gen, Primitive(standardType)) + dynamicValueLaw(gen, Primitive(standardType, Chunk.empty)) } } diff --git a/zio-schema/shared/src/test/scala/zio/schema/OrderingSpec.scala b/zio-schema/shared/src/test/scala/zio/schema/OrderingSpec.scala index d32483125..a6430fd3d 100644 --- a/zio-schema/shared/src/test/scala/zio/schema/OrderingSpec.scala +++ b/zio-schema/shared/src/test/scala/zio/schema/OrderingSpec.scala @@ -47,7 +47,7 @@ object OrderingSpec extends DefaultRunnableSpec { standardType: StandardType[A] ): URIO[R with Random with TestConfig, TestResult] = check(Gen.listOfN(2)(gen)) { lst => - val schema = Primitive(standardType) + val schema = Primitive(standardType, Chunk.empty) val schemaOrdering = schema.ordering val l = lst(0) val r = lst(1) @@ -170,7 +170,7 @@ object OrderingSpec extends DefaultRunnableSpec { Right(a) }, { a: A => Right(a) - }), small, large) + }, Chunk.empty), small, large) def genOrderedPairDecodeTransform[A](schema: Schema[A]): Gen[Random with Sized, SchemaAndPair[DynamicValue]] = for { @@ -181,7 +181,7 @@ object OrderingSpec extends DefaultRunnableSpec { smallEncoded = encode(small).toOption.get smallEncodedOrError = if (error) DynamicValue.SomeValue(smallEncoded) else smallEncoded largeEncoded = encode(large).toOption.get - } yield (Schema.Transform(schema, encode, decode), smallEncodedOrError, largeEncoded) + } yield (Schema.Transform(schema, encode, decode, Chunk.empty), smallEncodedOrError, largeEncoded) def genAnyOrderedPairRecord: Gen[Random with Sized, SchemaAndPair[_]] = for { diff --git a/zio-schema/shared/src/test/scala/zio/schema/SchemaAssertions.scala b/zio-schema/shared/src/test/scala/zio/schema/SchemaAssertions.scala index db71978aa..fa04ca221 100644 --- a/zio-schema/shared/src/test/scala/zio/schema/SchemaAssertions.scala +++ b/zio-schema/shared/src/test/scala/zio/schema/SchemaAssertions.scala @@ -29,29 +29,32 @@ object SchemaAssertions { Assertion.assertion("hasSameAst")(param(expected))(actual => equalsAst(expected, actual)) private def equalsAst(expected: Schema[_], actual: Schema[_], depth: Int = 0): Boolean = (expected, actual) match { - case (Schema.Primitive(StandardType.Duration(_)), Schema.Primitive(StandardType.Duration(_))) => true - case (Schema.Primitive(StandardType.Instant(_)), Schema.Primitive(StandardType.Instant(_))) => true - case (Schema.Primitive(StandardType.LocalDate(_)), Schema.Primitive(StandardType.LocalDate(_))) => true - case (Schema.Primitive(StandardType.LocalTime(_)), Schema.Primitive(StandardType.LocalTime(_))) => true - case (Schema.Primitive(StandardType.LocalDateTime(_)), Schema.Primitive(StandardType.LocalDateTime(_))) => true - case (Schema.Primitive(StandardType.ZonedDateTime(_)), Schema.Primitive(StandardType.ZonedDateTime(_))) => true - case (Schema.Primitive(StandardType.OffsetTime(_)), Schema.Primitive(StandardType.OffsetTime(_))) => true - case (Schema.Primitive(StandardType.OffsetDateTime(_)), Schema.Primitive(StandardType.OffsetDateTime(_))) => true - case (Schema.Primitive(tpe1), Schema.Primitive(tpe2)) => tpe1 == tpe2 - case (Schema.Optional(expected), Schema.Optional(actual)) => equalsAst(expected, actual, depth) - case (Schema.Tuple(expectedLeft, expectedRight), Schema.Tuple(actualLeft, actualRight)) => + case (Schema.Primitive(StandardType.Duration(_), _), Schema.Primitive(StandardType.Duration(_), _)) => true + case (Schema.Primitive(StandardType.Instant(_), _), Schema.Primitive(StandardType.Instant(_), _)) => true + case (Schema.Primitive(StandardType.LocalDate(_), _), Schema.Primitive(StandardType.LocalDate(_), _)) => true + case (Schema.Primitive(StandardType.LocalTime(_), _), Schema.Primitive(StandardType.LocalTime(_), _)) => true + case (Schema.Primitive(StandardType.LocalDateTime(_), _), Schema.Primitive(StandardType.LocalDateTime(_), _)) => + true + case (Schema.Primitive(StandardType.ZonedDateTime(_), _), Schema.Primitive(StandardType.ZonedDateTime(_), _)) => + true + case (Schema.Primitive(StandardType.OffsetTime(_), _), Schema.Primitive(StandardType.OffsetTime(_), _)) => true + case (Schema.Primitive(StandardType.OffsetDateTime(_), _), Schema.Primitive(StandardType.OffsetDateTime(_), _)) => + true + case (Schema.Primitive(tpe1, _), Schema.Primitive(tpe2, _)) => tpe1 == tpe2 + case (Schema.Optional(expected, _), Schema.Optional(actual, _)) => equalsAst(expected, actual, depth) + case (Schema.Tuple(expectedLeft, expectedRight, _), Schema.Tuple(actualLeft, actualRight, _)) => equalsAst(expectedLeft, actualLeft, depth) && equalsAst(expectedRight, actualRight, depth) - case (Schema.Tuple(expectedLeft, expectedRight), Schema.GenericRecord(structure)) => + case (Schema.Tuple(expectedLeft, expectedRight, _), Schema.GenericRecord(structure, _)) => structure.toChunk.size == 2 && structure.toChunk.find(_.label == "left").exists(f => equalsAst(expectedLeft, f.schema, depth)) && structure.toChunk.find(_.label == "right").exists(f => equalsAst(expectedRight, f.schema, depth)) - case (Schema.EitherSchema(expectedLeft, expectedRight), Schema.EitherSchema(actualLeft, actualRight)) => + case (Schema.EitherSchema(expectedLeft, expectedRight, _), Schema.EitherSchema(actualLeft, actualRight, _)) => equalsAst(expectedLeft, actualLeft, depth) && equalsAst(expectedRight, actualRight, depth) - case (Schema.EitherSchema(expectedLeft, expectedRight), right: Schema.Enum[_]) => + case (Schema.EitherSchema(expectedLeft, expectedRight, _), right: Schema.Enum[_]) => right.structure.size == 2 && right.structure.get("left").exists(actualLeft => equalsAst(expectedLeft, actualLeft, depth)) && right.structure.get("right").exists(actualRight => equalsAst(expectedRight, actualRight, depth)) - case (Schema.Sequence(expected, _, _), Schema.Sequence(actual, _, _)) => equalsAst(expected, actual, depth) + case (Schema.Sequence(expected, _, _, _), Schema.Sequence(actual, _, _, _)) => equalsAst(expected, actual, depth) case (expected: Schema.Record[_], actual: Schema.Record[_]) => expected.structure.zipAll(actual.structure).forall { case (Some(Schema.Field(expectedLabel, expectedSchema, _)), Some(Schema.Field(actualLabel, actualSchema, _))) => @@ -64,9 +67,9 @@ object SchemaAssertions { actualId == expectedId && equalsAst(expectedSchema, actualSchema, depth) case _ => false } - case (expected, Schema.Transform(actualSchema, _, _)) => + case (expected, Schema.Transform(actualSchema, _, _, _)) => equalsAst(expected, actualSchema, depth) - case (Schema.Transform(expected, _, _), actual) => + case (Schema.Transform(expected, _, _, _), actual) => equalsAst(expected, actual, depth) case (expected: Schema.Lazy[_], actual) => if (depth > 10) true else equalsAst(expected.schema, actual, depth + 1) case (expected, actual: Schema.Lazy[_]) => if (depth > 10) true else equalsAst(expected, actual.schema, depth + 1) @@ -75,25 +78,30 @@ object SchemaAssertions { private def equalsSchema[A](left: Schema[A], right: Schema[A]): Boolean = (left: Schema[_], right: Schema[_]) match { - case (Schema.Transform(codec1, _, _), Schema.Transform(codec2, _, _)) => - equalsSchema(codec1, codec2) - case (Schema.GenericRecord(structure1), Schema.GenericRecord(structure2)) => + case (Schema.Transform(codec1, _, _, a1), Schema.Transform(codec2, _, _, a2)) => + equalsSchema(codec1, codec2) && equalsAnnotations(a1, a2) + case (Schema.GenericRecord(structure1, a1), Schema.GenericRecord(structure2, a2)) => hasSameFields(structure1.toChunk, structure2.toChunk) && structure1.toChunk.forall { case Schema.Field(label, schema, _) => val left: Schema[Any] = schema.asInstanceOf[Schema[Any]] val right: Schema[Any] = structure2.toChunk.find(_.label == label).asInstanceOf[Schema[Any]] equalsSchema(left, right) - } + } && equalsAnnotations(a1, a2) case (left: Schema.Record[_], right: Schema.Record[_]) => - hasSameStructure(left.asInstanceOf[Schema.Record[A]], right.asInstanceOf[Schema.Record[A]]) - case (Schema.Sequence(element1, _, _), Schema.Sequence(element2, _, _)) => equalsSchema(element1, element2) - case (Schema.Primitive(standardType1), Schema.Primitive(standardType2)) => - standardType1 == standardType2 - case (Schema.Tuple(left1, right1), Schema.Tuple(left2, right2)) => - equalsSchema(left1, left2) && equalsSchema(right1, right2) - case (Schema.Optional(codec1), Schema.Optional(codec2)) => equalsSchema(codec1, codec2) - case (Schema.Enum1(l, lA), Schema.Enum1(r, rA)) => equalsCase(l, r) && lA.equals(rA) + hasSameStructure(left.asInstanceOf[Schema.Record[A]], right.asInstanceOf[Schema.Record[A]]) && equalsAnnotations( + left.annotations, + right.annotations + ) + case (Schema.Sequence(element1, _, _, a1), Schema.Sequence(element2, _, _, a2)) => + equalsSchema(element1, element2) && equalsAnnotations(a1, a2) + case (Schema.Primitive(standardType1, a1), Schema.Primitive(standardType2, a2)) => + standardType1 == standardType2 && equalsAnnotations(a1, a2) + case (Schema.Tuple(left1, right1, a1), Schema.Tuple(left2, right2, a2)) => + equalsSchema(left1, left2) && equalsSchema(right1, right2) && equalsAnnotations(a1, a2) + case (Schema.Optional(codec1, a1), Schema.Optional(codec2, a2)) => + equalsSchema(codec1, codec2) && equalsAnnotations(a1, a2) + case (Schema.Enum1(l, lA), Schema.Enum1(r, rA)) => equalsCase(l, r) && lA.equals(rA) case (Schema.Enum2(l1, l2, lA), Schema.Enum2(r1, r2, rA)) => hasSameCases(Seq(l1, l2), Seq(r1, r2)) && equalsAnnotations(lA, rA) case (Schema.Enum3(l1, l2, l3, lA), Schema.Enum3(r1, r2, r3, rA)) => diff --git a/zio-schema/shared/src/test/scala/zio/schema/SchemaAstSpec.scala b/zio-schema/shared/src/test/scala/zio/schema/SchemaAstSpec.scala index 0970cccdd..6e326e924 100644 --- a/zio-schema/shared/src/test/scala/zio/schema/SchemaAstSpec.scala +++ b/zio-schema/shared/src/test/scala/zio/schema/SchemaAstSpec.scala @@ -12,7 +12,7 @@ object SchemaAstSpec extends DefaultRunnableSpec { suite("from schema")( testM("primitive") { check(SchemaGen.anyPrimitive) { - case s @ Schema.Primitive(typ) => + case s @ Schema.Primitive(typ, _) => assertTrue(SchemaAst.fromSchema(s) == SchemaAst.Value(typ)) } } @@ -20,7 +20,7 @@ object SchemaAstSpec extends DefaultRunnableSpec { suite("optional")( testM("primitive") { check(SchemaGen.anyPrimitive) { - case s @ Schema.Primitive(typ) => + case s @ Schema.Primitive(typ, _) => assertTrue(SchemaAst.fromSchema(s.optional) == SchemaAst.Value(typ, optional = true)) } } @@ -28,7 +28,7 @@ object SchemaAstSpec extends DefaultRunnableSpec { suite("sequence")( testM("primitive") { check(SchemaGen.anyPrimitive) { - case s @ Schema.Primitive(typ) => + case s @ Schema.Primitive(typ, _) => assertTrue(SchemaAst.fromSchema(Schema.chunk(s)) == SchemaAst.Value(typ, dimensions = 1)) } } diff --git a/zio-schema/shared/src/test/scala/zio/schema/SchemaGen.scala b/zio-schema/shared/src/test/scala/zio/schema/SchemaGen.scala index 2aaaf99ef..0e72dee67 100644 --- a/zio-schema/shared/src/test/scala/zio/schema/SchemaGen.scala +++ b/zio-schema/shared/src/test/scala/zio/schema/SchemaGen.scala @@ -43,13 +43,13 @@ object SchemaGen { Gen.setOfBounded(1, 8)(anyLabel.map(_ -> schema)).map(ListMap.empty ++ _) val anyPrimitive: Gen[Random, Schema.Primitive[_]] = - StandardTypeGen.anyStandardType.map(Schema.Primitive(_)) + StandardTypeGen.anyStandardType.map(Schema.Primitive(_, Chunk.empty)) type PrimitiveAndGen[A] = (Schema.Primitive[A], Gen[Random with Sized, A]) val anyPrimitiveAndGen: Gen[Random, PrimitiveAndGen[_]] = StandardTypeGen.anyStandardTypeAndGen.map { - case (standardType, gen) => Schema.Primitive(standardType) -> gen + case (standardType, gen) => Schema.Primitive(standardType, Chunk.empty) -> gen } type PrimitiveAndValue[A] = (Schema.Primitive[A], A) @@ -231,7 +231,12 @@ object SchemaGen { // TODO: Add some random Left values. private def transformSequence[A](schema: Schema[Chunk[A]]): SequenceTransform[A] = - Schema.Transform[Chunk[A], List[A]](schema, chunk => Right(chunk.toList), list => Right(Chunk.fromIterable(list))) + Schema.Transform[Chunk[A], List[A]]( + schema, + chunk => Right(chunk.toList), + list => Right(Chunk.fromIterable(list)), + Chunk.empty + ) type SequenceTransformAndValue[A] = (SequenceTransform[A], List[A]) @@ -258,7 +263,12 @@ object SchemaGen { // TODO: Dynamically generate a case class. def transformRecord[A](schema: Schema[ListMap[String, _]]): RecordTransform[A] = - Schema.Transform[ListMap[String, _], A](schema, _ => Left("Not implemented."), _ => Left("Not implemented.")) + Schema.Transform[ListMap[String, _], A]( + schema, + _ => Left("Not implemented."), + _ => Left("Not implemented."), + Chunk.empty + ) type RecordTransformAndValue[A] = (RecordTransform[A], A) @@ -285,7 +295,7 @@ object SchemaGen { // TODO: Dynamically generate a sealed trait and case/value classes. def transformEnumeration[A](schema: Schema[Any]): EnumerationTransform[_] = - Schema.Transform[Any, A](schema, _ => Left("Not implemented."), _ => Left("Not implemented.")) + Schema.Transform[Any, A](schema, _ => Left("Not implemented."), _ => Left("Not implemented."), Chunk.empty) type EnumerationTransformAndValue[A] = (EnumerationTransform[A], A) @@ -479,8 +489,8 @@ object SchemaGen { anyTree(depth - 1).map(Schema.list(_)), // Nested optional cause some issues. Ignore them for now: See https://github.com/zio/zio-schema/issues/68 anyTree(depth - 1).map { - case s @ Schema.Optional(_) => s - case s => Schema.option(s) + case s @ Schema.Optional(_, _) => s + case s => Schema.option(s) }, anyTree(depth - 1).zip(anyTree(depth - 1)).map { case (l, r) => Schema.either(l, r) }, anyTree(depth - 1).zip(anyTree(depth - 1)).map { case (l, r) => Schema.tuple2(l, r) },