From 54ad98f07f9c2bc758606ad4ccb287fb19107241 Mon Sep 17 00:00:00 2001 From: Dan Harris <1327726+thinkharderdev@users.noreply.github.com> Date: Tue, 29 Mar 2022 19:12:43 -0400 Subject: [PATCH] Support for ZIO2-RC3 (#230) * Upgrade to ZIO2 RC2 * Update to ZIO2 RC3 * Upgrade zio-json snapshot version for ZIO2-RC3 * Fix string encoding compilation error * Try to get timeouts sorted --- project/BuildHelper.scala | 8 ++++---- .../src/test/scala/zio/schema/SchemaGen.scala | 8 ++++---- .../scala/zio/schema/codec/JsonCodec.scala | 18 +++++++++--------- .../scala/zio/schema/codec/JsonCodecSpec.scala | 2 +- .../zio/schema/codec/ThriftCodecSpec.scala | 2 +- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/project/BuildHelper.scala b/project/BuildHelper.scala index 2f63be133..0b85e50a9 100644 --- a/project/BuildHelper.scala +++ b/project/BuildHelper.scala @@ -26,10 +26,10 @@ object BuildHelper { val Scala213: String = versions("2.13") val ScalaDotty: String = "3.1.0" //versions.getOrElse("3.0", versions("3.1")) - val zioVersion = "2.0.0-RC1" - val zioJsonVersion = "0.3.0-RC1-1" - val zioPreludeVersion = "1.0.0-RC9" - val zioOpticsVersion = "0.2.0-RC1" + val zioVersion = "2.0.0-RC3" + val zioJsonVersion = "0.3.0-RC4" + val zioPreludeVersion = "1.0.0-RC10" + val zioOpticsVersion = "0.2.0-RC2" val silencerVersion = "1.7.8" private val testDeps = Seq( diff --git a/tests/shared/src/test/scala/zio/schema/SchemaGen.scala b/tests/shared/src/test/scala/zio/schema/SchemaGen.scala index 11f79da76..3ce4f160a 100644 --- a/tests/shared/src/test/scala/zio/schema/SchemaGen.scala +++ b/tests/shared/src/test/scala/zio/schema/SchemaGen.scala @@ -14,7 +14,7 @@ object SchemaGen { def anyStructure( schemaGen: Gen[Random with Sized, Schema[_]] ): Gen[Random with Sized, Seq[Schema.Field[_]]] = - Gen.setOfBounded(1, 8)(anyLabel).flatMap { keySet => + Gen.setOfBounded(1, 3)(anyLabel).flatMap { keySet => Gen.setOfN(keySet.size)(schemaGen).map { schemas => keySet .zip(schemas) @@ -27,7 +27,7 @@ object SchemaGen { def anyStructure[A](schema: Schema[A]): Gen[Random with Sized, Seq[Schema.Field[A]]] = Gen - .setOfBounded(1, 8)( + .setOfBounded(1, 3)( anyLabel.map(Schema.Field(_, schema)) ) .map(_.toSeq) @@ -36,13 +36,13 @@ object SchemaGen { schemaGen: Gen[Random with Sized, Schema[_]] ): Gen[Random with Sized, ListMap[String, Schema[_]]] = Gen - .setOfBounded(1, 8)( + .setOfBounded(1, 3)( anyLabel.zip(schemaGen) ) .map(ListMap.empty ++ _) def anyEnumeration[A](schema: Schema[A]): Gen[Random with Sized, ListMap[String, Schema[A]]] = - Gen.setOfBounded(1, 8)(anyLabel.map(_ -> schema)).map(ListMap.empty ++ _) + Gen.setOfBounded(1, 3)(anyLabel.map(_ -> schema)).map(ListMap.empty ++ _) val anyPrimitive: Gen[Random, Schema.Primitive[_]] = StandardTypeGen.anyStandardType.map(Schema.Primitive(_, Chunk.empty)) 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 c284a8222..0d7eb2f16 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 @@ -58,7 +58,7 @@ object JsonCodec extends Codec { case StandardType.LongType => ZJsonCodec.long case StandardType.FloatType => ZJsonCodec.float case StandardType.DoubleType => ZJsonCodec.double - case StandardType.BinaryType => ZJsonCodec.chunk(ZJsonCodec.byte) + case StandardType.BinaryType => ZJsonCodec.chunk(ZJsonCodec.byte.encoder, ZJsonCodec.byte.decoder) case StandardType.CharType => ZJsonCodec.char case StandardType.BigIntegerType => ZJsonCodec.bigInteger case StandardType.BigDecimalType => ZJsonCodec.bigDecimal @@ -100,10 +100,10 @@ object JsonCodec extends Codec { //scalafmt: { maxColumn = 400, optIn.configStyleArguments = false } private[codec] def schemaEncoder[A](schema: Schema[A]): JsonEncoder[A] = schema match { - case Schema.Primitive(standardType, _) => primitiveCodec(standardType) + case Schema.Primitive(standardType, _) => primitiveCodec(standardType).encoder case Schema.Sequence(schema, _, g, _, _) => JsonEncoder.chunk(schemaEncoder(schema)).contramap(g) case Schema.MapSchema(ks, vs, _) => - JsonEncoder.chunk(schemaEncoder(ks).both(schemaEncoder(vs))).contramap(m => Chunk.fromIterable(m)) + JsonEncoder.chunk(schemaEncoder(ks).zip(schemaEncoder(vs))).contramap(m => Chunk.fromIterable(m)) case Schema.SetSchema(s, _) => JsonEncoder.chunk(schemaEncoder(s)).contramap(m => Chunk.fromIterable(m)) case Schema.Transform(c, _, g, _, _) => transformEncoder(c, g) @@ -217,13 +217,13 @@ object JsonCodec extends Codec { val indent_ = bump(indent) pad(indent_, out) // schema - string.unsafeEncode(JsonFieldEncoder.string.unsafeEncodeField("schema"), indent_, out) + string.encoder.unsafeEncode(JsonFieldEncoder.string.unsafeEncodeField("schema"), indent_, out) if (indent.isEmpty) out.write(':') else out.write(" : ") astEncoder.unsafeEncode(schema, indent_, out) out.write(',') // value - string.unsafeEncode(JsonFieldEncoder.string.unsafeEncodeField("value"), indent_, out) + string.encoder.unsafeEncode(JsonFieldEncoder.string.unsafeEncodeField("value"), indent_, out) if (indent.isEmpty) out.write(':') else out.write(" : ") schemaEncoder(schema).unsafeEncode(value._1, indent_, out) @@ -248,7 +248,7 @@ object JsonCodec extends Codec { out.write('{') val indent_ = bump(indent) pad(indent_, out) - string.unsafeEncode(JsonFieldEncoder.string.unsafeEncodeField(case_.id), indent_, out) + string.encoder.unsafeEncode(JsonFieldEncoder.string.unsafeEncodeField(case_.id), indent_, out) if (indent.isEmpty) out.write(':') else out.write(" : ") schemaEncoder(case_.codec.asInstanceOf[Schema[Any]]).unsafeEncode(case_.unsafeDeconstruct(value), indent, out) @@ -278,7 +278,7 @@ object JsonCodec extends Codec { if (indent.isDefined) JsonEncoder.pad(indent_, out) } - string.unsafeEncode(JsonFieldEncoder.string.unsafeEncodeField(k), indent_, out) + string.encoder.unsafeEncode(JsonFieldEncoder.string.unsafeEncodeField(k), indent_, out) if (indent.isEmpty) out.write(':') else out.write(" : ") enc.unsafeEncode(value(k), indent_, out) @@ -300,7 +300,7 @@ object JsonCodec extends Codec { //scalafmt: { maxColumn = 400, optIn.configStyleArguments = false } private[codec] def schemaDecoder[A](schema: Schema[A]): JsonDecoder[A] = schema match { - case Schema.Primitive(standardType, _) => primitiveCodec(standardType) + case Schema.Primitive(standardType, _) => primitiveCodec(standardType).decoder 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) @@ -510,7 +510,7 @@ object JsonCodec extends Codec { JsonEncoder.pad(indent_, out) } - string.unsafeEncode(JsonFieldEncoder.string.unsafeEncodeField(key), indent_, out) + string.encoder.unsafeEncode(JsonFieldEncoder.string.unsafeEncodeField(key), indent_, out) if (indent.isEmpty) out.write(':') else out.write(" : ") enc.unsafeEncode(ext(a), indent_, out) diff --git a/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala b/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala index ade00e4bb..fe1be4b25 100644 --- a/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala +++ b/zio-schema-json/shared/src/test/scala/zio/schema/codec/JsonCodecSpec.scala @@ -758,7 +758,7 @@ object JsonCodecSpec extends DefaultRunnableSpec { implicit keyEncoder: JsonEncoder[K], valueEncoder: JsonEncoder[V] ): JsonEncoder[Map[K, V]] = - JsonEncoder.chunk(keyEncoder.both(valueEncoder)).contramap[Map[K, V]](m => Chunk.fromIterable(m)) + JsonEncoder.chunk(keyEncoder.zip(valueEncoder)).contramap[Map[K, V]](m => Chunk.fromIterable(m)) private def jsonEncoded[A](value: A)(implicit enc: JsonEncoder[A]): Chunk[Byte] = JsonCodec.Encoder.charSequenceToByteChunk(enc.encodeJson(value, None)) diff --git a/zio-schema-thrift/shared/src/test/scala/zio/schema/codec/ThriftCodecSpec.scala b/zio-schema-thrift/shared/src/test/scala/zio/schema/codec/ThriftCodecSpec.scala index f328ef423..7df84a8f5 100644 --- a/zio-schema-thrift/shared/src/test/scala/zio/schema/codec/ThriftCodecSpec.scala +++ b/zio-schema-thrift/shared/src/test/scala/zio/schema/codec/ThriftCodecSpec.scala @@ -829,7 +829,7 @@ object ThriftCodecSpec extends DefaultRunnableSpec { ) ) - def writeManually(f: TBinaryProtocol => Unit): Task[String] = Task { + def writeManually(f: TBinaryProtocol => Unit): Task[String] = Task.attempt { val writeRecord = new ChunkTransport.Write() f(new TBinaryProtocol(writeRecord)) toHex(writeRecord.chunk)