@zio.dev/zio-blocks 0.0.31 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/guides/query-dsl-extending.md +1 -1
- package/guides/query-dsl-fluent-builder.md +1 -1
- package/guides/query-dsl-reified-optics.md +1 -1
- package/guides/query-dsl-sql.md +1 -1
- package/guides/zio-schema-migration.md +6 -6
- package/index.md +13 -13
- package/package.json +1 -1
- package/reference/codec.md +27 -19
- package/reference/context.md +1 -1
- package/reference/docs.md +1 -1
- package/reference/dynamic-schema.md +7 -7
- package/reference/formats.md +15 -11
- package/reference/json-patch.md +2 -2
- package/reference/media-type.md +2 -2
- package/reference/resource-management/resource.md +2 -2
- package/reference/resource-management/scope.md +1 -1
- package/reference/resource-management/wire.md +2 -2
- package/reference/schema-evolution/as.md +7 -7
- package/reference/schema-evolution/into.md +7 -7
- package/reference/schema-expr.md +2 -2
- package/reference/schema.md +1 -1
- package/reference/type-class-derivation.md +1 -1
- package/reference/typeid.md +2936 -583
- package/reference/xml.md +25 -188
- package/ringbuffer.md +1 -1
- package/superpowers/plans/2026-03-19-docs-critique-subagent.md +407 -0
- package/superpowers/specs/2026-03-19-docs-critique-subagent-design.md +222 -0
- package/undocumented-report.md +5 -5
package/reference/xml.md
CHANGED
|
@@ -466,7 +466,7 @@ val xml = XmlReader.read("""
|
|
|
466
466
|
</book>
|
|
467
467
|
</books>
|
|
468
468
|
</library>
|
|
469
|
-
""")
|
|
469
|
+
""")
|
|
470
470
|
|
|
471
471
|
// Navigate to child elements
|
|
472
472
|
val books = xml.select.get("library").get("books")
|
|
@@ -478,9 +478,16 @@ val firstBook = books.get("book")(0)
|
|
|
478
478
|
Extract text content from the first book:
|
|
479
479
|
|
|
480
480
|
```scala
|
|
481
|
-
val title: Either[
|
|
482
|
-
// title: Either[
|
|
483
|
-
//
|
|
481
|
+
val title: Either[SchemaError, String] = firstBook.get("title").text
|
|
482
|
+
// title: Either[SchemaError, String] = Left(
|
|
483
|
+
// SchemaError(
|
|
484
|
+
// List(
|
|
485
|
+
// Message(
|
|
486
|
+
// source = DynamicOptic(IndexedSeq()),
|
|
487
|
+
// details = "Expected single value but got 0"
|
|
488
|
+
// )
|
|
489
|
+
// )
|
|
490
|
+
// )
|
|
484
491
|
// )
|
|
485
492
|
```
|
|
486
493
|
|
|
@@ -534,19 +541,19 @@ import zio.blocks.schema.xml._
|
|
|
534
541
|
val selection: XmlSelection = ???
|
|
535
542
|
|
|
536
543
|
// Get single value (fails if not exactly one)
|
|
537
|
-
val one: Either[
|
|
544
|
+
val one: Either[SchemaError, Xml] = selection.one
|
|
538
545
|
|
|
539
546
|
// Get any value (first of many)
|
|
540
|
-
val any: Either[
|
|
547
|
+
val any: Either[SchemaError, Xml] = selection.any
|
|
541
548
|
|
|
542
549
|
// Get all values as a single XML element
|
|
543
|
-
val all: Either[
|
|
550
|
+
val all: Either[SchemaError, Xml] = selection.all
|
|
544
551
|
|
|
545
552
|
// Convert to chunk
|
|
546
553
|
val chunk = selection.toChunk
|
|
547
554
|
|
|
548
555
|
// Extract text content
|
|
549
|
-
val text: Either[
|
|
556
|
+
val text: Either[SchemaError, String] = selection.text
|
|
550
557
|
val allText: String = selection.textContent
|
|
551
558
|
```
|
|
552
559
|
|
|
@@ -635,7 +642,7 @@ val xml: Xml = ???
|
|
|
635
642
|
val patch = XmlPatch.setAttribute(p".person", "active", "true")
|
|
636
643
|
|
|
637
644
|
// Apply the patch
|
|
638
|
-
val result: Either[
|
|
645
|
+
val result: Either[SchemaError, Xml] = patch(xml)
|
|
639
646
|
```
|
|
640
647
|
|
|
641
648
|
### Composing Patches
|
|
@@ -657,175 +664,6 @@ val patch2 = XmlPatch.add(
|
|
|
657
664
|
val combined = patch1 ++ patch2
|
|
658
665
|
```
|
|
659
666
|
|
|
660
|
-
## XmlEncoder and XmlDecoder
|
|
661
|
-
|
|
662
|
-
For more fine-grained control over XML serialization, use the separate `XmlEncoder` and `XmlDecoder` traits:
|
|
663
|
-
|
|
664
|
-
### XmlEncoder
|
|
665
|
-
|
|
666
|
-
`XmlEncoder[A]` provides type-safe XML encoding:
|
|
667
|
-
|
|
668
|
-
```scala
|
|
669
|
-
import zio.blocks.schema._
|
|
670
|
-
import zio.blocks.schema.xml._
|
|
671
|
-
|
|
672
|
-
// Automatic derivation from Schema
|
|
673
|
-
case class Person(name: String, age: Int)
|
|
674
|
-
object Person {
|
|
675
|
-
implicit val schema: Schema[Person] = Schema.derived
|
|
676
|
-
implicit val encoder: XmlEncoder[Person] = XmlEncoder.fromSchema
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
val person = Person("Alice", 30)
|
|
680
|
-
val xml: Xml = XmlEncoder[Person].encode(person)
|
|
681
|
-
```
|
|
682
|
-
|
|
683
|
-
#### Creating custom encoders
|
|
684
|
-
|
|
685
|
-
Create custom encoders from functions or using contravariance:
|
|
686
|
-
|
|
687
|
-
```scala
|
|
688
|
-
import zio.blocks.schema.xml._
|
|
689
|
-
|
|
690
|
-
// Create from a function
|
|
691
|
-
val customEncoder: XmlEncoder[Int] = XmlEncoder.instance(n =>
|
|
692
|
-
Xml.Element("number", Xml.Text(n.toString))
|
|
693
|
-
)
|
|
694
|
-
|
|
695
|
-
// Map with contravariance - encode a wrapper type
|
|
696
|
-
case class UserId(value: Int)
|
|
697
|
-
|
|
698
|
-
val userIdEncoder: XmlEncoder[UserId] =
|
|
699
|
-
customEncoder.contramap[UserId](_.value)
|
|
700
|
-
```
|
|
701
|
-
|
|
702
|
-
#### Using implicit resolution
|
|
703
|
-
|
|
704
|
-
Leverage implicit resolution for automatic encoder derivation:
|
|
705
|
-
|
|
706
|
-
```scala
|
|
707
|
-
import zio.blocks.schema._
|
|
708
|
-
import zio.blocks.schema.xml._
|
|
709
|
-
|
|
710
|
-
case class Product(id: String, price: Double)
|
|
711
|
-
object Product {
|
|
712
|
-
implicit val schema: Schema[Product] = Schema.derived
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
// No explicit encoder needed - derives automatically
|
|
716
|
-
def encodeProduct[A](value: A)(implicit encoder: XmlEncoder[A]): Xml =
|
|
717
|
-
encoder.encode(value)
|
|
718
|
-
|
|
719
|
-
val result = encodeProduct(Product("item-1", 99.99))
|
|
720
|
-
```
|
|
721
|
-
|
|
722
|
-
### XmlDecoder
|
|
723
|
-
|
|
724
|
-
`XmlDecoder[A]` provides type-safe XML decoding with error handling:
|
|
725
|
-
|
|
726
|
-
```scala
|
|
727
|
-
import zio.blocks.schema._
|
|
728
|
-
import zio.blocks.schema.xml._
|
|
729
|
-
|
|
730
|
-
// Automatic derivation from Schema
|
|
731
|
-
case class Person(name: String, age: Int)
|
|
732
|
-
object Person {
|
|
733
|
-
implicit val schema: Schema[Person] = Schema.derived
|
|
734
|
-
implicit val decoder: XmlDecoder[Person] = XmlDecoder.fromSchema
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
val xml = Xml.Element("Person",
|
|
738
|
-
Xml.Element("name", Xml.Text("Alice")),
|
|
739
|
-
Xml.Element("age", Xml.Text("30"))
|
|
740
|
-
)
|
|
741
|
-
```
|
|
742
|
-
|
|
743
|
-
Decode the XML:
|
|
744
|
-
|
|
745
|
-
```scala
|
|
746
|
-
val result: Either[XmlError, Person] = XmlDecoder[Person].decode(xml)
|
|
747
|
-
// result: Either[XmlError, Person] = Right(Person(name = "Alice", age = 30))
|
|
748
|
-
```
|
|
749
|
-
|
|
750
|
-
#### Creating custom decoders
|
|
751
|
-
|
|
752
|
-
Create custom decoders from functions or using covariance:
|
|
753
|
-
|
|
754
|
-
```scala
|
|
755
|
-
import zio.blocks.schema.xml._
|
|
756
|
-
import zio.blocks.chunk.Chunk
|
|
757
|
-
|
|
758
|
-
// Create from a function
|
|
759
|
-
val numberDecoder: XmlDecoder[Int] = XmlDecoder.instance { xml =>
|
|
760
|
-
xml match {
|
|
761
|
-
case Xml.Element(_, _, Chunk(Xml.Text(text), _*)) =>
|
|
762
|
-
text.toIntOption.toRight(XmlError("Invalid number"))
|
|
763
|
-
case _ => Left(XmlError("Expected number element"))
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
// Map for covariance - decode to a wrapper type
|
|
768
|
-
case class UserId(value: Int)
|
|
769
|
-
|
|
770
|
-
val userIdDecoder: XmlDecoder[UserId] =
|
|
771
|
-
numberDecoder.map(UserId(_))
|
|
772
|
-
```
|
|
773
|
-
|
|
774
|
-
#### Error handling with decoders
|
|
775
|
-
|
|
776
|
-
Handle decoding errors gracefully with fallback strategies:
|
|
777
|
-
|
|
778
|
-
```scala
|
|
779
|
-
import zio.blocks.schema._
|
|
780
|
-
import zio.blocks.schema.xml._
|
|
781
|
-
|
|
782
|
-
case class Person(name: String, age: Int)
|
|
783
|
-
object Person {
|
|
784
|
-
implicit val schema: Schema[Person] = Schema.derived
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
def decodeWithFallback[A](
|
|
788
|
-
xml: Xml,
|
|
789
|
-
fallback: A
|
|
790
|
-
)(implicit decoder: XmlDecoder[A]): A = {
|
|
791
|
-
decoder.decode(xml).getOrElse(fallback)
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
val invalidXml = Xml.Element("Empty")
|
|
795
|
-
val defaultPerson = Person("Unknown", 0)
|
|
796
|
-
val result = decodeWithFallback(invalidXml, defaultPerson)
|
|
797
|
-
// Person("Unknown", 0)
|
|
798
|
-
```
|
|
799
|
-
|
|
800
|
-
#### Combining encoders and decoders
|
|
801
|
-
|
|
802
|
-
Round-trip values by encoding and decoding:
|
|
803
|
-
|
|
804
|
-
```scala
|
|
805
|
-
import zio.blocks.schema._
|
|
806
|
-
import zio.blocks.schema.xml._
|
|
807
|
-
import zio.blocks.schema.xml.syntax._
|
|
808
|
-
|
|
809
|
-
case class Message(id: String, text: String)
|
|
810
|
-
object Message {
|
|
811
|
-
implicit val schema: Schema[Message] = Schema.derived
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
// Round-trip: encode then decode
|
|
815
|
-
val message = Message("msg-1", "Hello")
|
|
816
|
-
val encoded: Xml = message.toXml
|
|
817
|
-
```
|
|
818
|
-
|
|
819
|
-
Decode the encoded value:
|
|
820
|
-
|
|
821
|
-
```scala
|
|
822
|
-
val result: Either[XmlError, Message] =
|
|
823
|
-
implicitly[XmlDecoder[Message]].decode(encoded)
|
|
824
|
-
// result: Either[XmlError, Message] = Right(
|
|
825
|
-
// Message(id = "msg-1", text = "Hello")
|
|
826
|
-
// )
|
|
827
|
-
```
|
|
828
|
-
|
|
829
667
|
## Extension Syntax
|
|
830
668
|
|
|
831
669
|
When a `Schema` is in scope, use convenient extension methods:
|
|
@@ -942,9 +780,9 @@ All standard ZIO Blocks Schema types are supported:
|
|
|
942
780
|
- Options (`Option[A]`)
|
|
943
781
|
- Wrappers (newtypes)
|
|
944
782
|
|
|
945
|
-
##
|
|
783
|
+
## XmlCodec
|
|
946
784
|
|
|
947
|
-
`
|
|
785
|
+
`XmlCodec[A]` is the low-level codec interface that bridges Schema definitions with XML serialization. While usually derived automatically, you can work with it directly:
|
|
948
786
|
|
|
949
787
|
```scala
|
|
950
788
|
import zio.blocks.schema._
|
|
@@ -956,18 +794,17 @@ object Person {
|
|
|
956
794
|
}
|
|
957
795
|
|
|
958
796
|
// Get the underlying binary codec
|
|
959
|
-
val codec:
|
|
960
|
-
Schema[Person].derive(XmlBinaryCodecDeriver)
|
|
797
|
+
val codec: XmlCodec[Person] = Schema[Person].derive(XmlCodecDeriver)
|
|
961
798
|
|
|
962
799
|
// Encode to Xml directly
|
|
963
800
|
val person = Person("Alice", 30)
|
|
964
801
|
val xml: Xml = codec.encodeValue(person)
|
|
965
802
|
|
|
966
803
|
// Decode from Xml directly
|
|
967
|
-
val decoded:
|
|
804
|
+
val decoded: Person = codec.decodeValue(xml)
|
|
968
805
|
```
|
|
969
806
|
|
|
970
|
-
**
|
|
807
|
+
**XmlCodec supports all Schema types:**
|
|
971
808
|
- Primitives (Int, String, Boolean, etc.)
|
|
972
809
|
- Java time types (Instant, LocalDate, Duration, etc.)
|
|
973
810
|
- Records (case classes with field-level configuration)
|
|
@@ -978,7 +815,7 @@ val decoded: Either[XmlError, Person] = codec.decodeValue(xml)
|
|
|
978
815
|
|
|
979
816
|
## Error Handling
|
|
980
817
|
|
|
981
|
-
All decoding operations return `Either[SchemaError, A]` or `Either[
|
|
818
|
+
All decoding operations return `Either[SchemaError, A]` or `Either[SchemaError, A]`. The `SchemaError` type provides detailed error information:
|
|
982
819
|
|
|
983
820
|
```scala
|
|
984
821
|
import zio.blocks.schema._
|
|
@@ -1003,12 +840,12 @@ result match {
|
|
|
1003
840
|
}
|
|
1004
841
|
```
|
|
1005
842
|
|
|
1006
|
-
`
|
|
843
|
+
`SchemaError` provides detailed error information for debugging:
|
|
1007
844
|
|
|
1008
845
|
```scala
|
|
1009
846
|
import zio.blocks.schema.xml._
|
|
1010
847
|
|
|
1011
|
-
val error =
|
|
848
|
+
val error = SchemaError("Parse failed")
|
|
1012
849
|
|
|
1013
850
|
// Error message
|
|
1014
851
|
val message: String = error.getMessage
|
|
@@ -1134,7 +971,7 @@ val xmlString = """
|
|
|
1134
971
|
</library>
|
|
1135
972
|
"""
|
|
1136
973
|
|
|
1137
|
-
val xml = XmlReader.read(xmlString)
|
|
974
|
+
val xml = XmlReader.read(xmlString)
|
|
1138
975
|
|
|
1139
976
|
// Find all books
|
|
1140
977
|
val books = xml.select.get("library").get("books").get("book")
|
package/ringbuffer.md
CHANGED
|
@@ -25,7 +25,7 @@ All variants expose `offer` (returns `false` if full) and `take` (returns `null`
|
|
|
25
25
|
## Installation
|
|
26
26
|
|
|
27
27
|
```scala
|
|
28
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-ringbuffer" % "0.0.
|
|
28
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-ringbuffer" % "0.0.33"
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
---
|