@zio.dev/zio-blocks 0.0.24 → 0.0.26
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/index.md +11 -11
- package/package.json +1 -1
- package/reference/codec.md +7 -7
- package/reference/docs.md +1 -1
- package/reference/media-type.md +2 -2
- package/reference/schema-expr.md +2 -2
- package/reference/type-class-derivation.md +49 -12
|
@@ -52,7 +52,7 @@ Since `SchemaExpr` is a sealed trait, you cannot add new cases to it. Instead, w
|
|
|
52
52
|
This guide builds on [Part 1: Expressions](./query-dsl-reified-optics.md) and [Part 2: SQL Generation](./query-dsl-sql.md). You should be comfortable building `SchemaExpr` values and translating them to SQL.
|
|
53
53
|
|
|
54
54
|
```scala
|
|
55
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
55
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.26"
|
|
56
56
|
```
|
|
57
57
|
|
|
58
58
|
```scala
|
|
@@ -57,7 +57,7 @@ In this guide, we solve both problems: bridge extensions eliminate `.toExpr`, an
|
|
|
57
57
|
This guide builds on [Part 1: Expressions](./query-dsl-reified-optics.md), [Part 2: SQL Generation](./query-dsl-sql.md), and [Part 3: Extending the Expression Language](./query-dsl-extending.md).
|
|
58
58
|
|
|
59
59
|
```scala
|
|
60
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
60
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.26"
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
## Domain Setup
|
|
@@ -43,7 +43,7 @@ In this guide, we'll solve this by using ZIO Blocks' `SchemaExpr` and reified op
|
|
|
43
43
|
Add the ZIO Blocks Schema dependency:
|
|
44
44
|
|
|
45
45
|
```scala
|
|
46
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
46
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.26"
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
```scala
|
package/guides/query-dsl-sql.md
CHANGED
|
@@ -43,7 +43,7 @@ Since `SchemaExpr` is a sealed trait, we can write a single interpreter that tra
|
|
|
43
43
|
This guide builds on [Part 1: Expressions](./query-dsl-reified-optics.md). You should be comfortable building `SchemaExpr` values with optic operators (`===`, `>`, `&&`, etc.).
|
|
44
44
|
|
|
45
45
|
```scala
|
|
46
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
46
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.26"
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
```scala
|
package/index.md
CHANGED
|
@@ -81,14 +81,14 @@ val thriftCodec = Schema[Person].derive(ThriftFormat) // Thrift
|
|
|
81
81
|
### Installation
|
|
82
82
|
|
|
83
83
|
```scala
|
|
84
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
84
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.26"
|
|
85
85
|
|
|
86
86
|
// Optional format modules:
|
|
87
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.
|
|
88
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.
|
|
89
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.
|
|
90
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.
|
|
91
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.
|
|
87
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.26"
|
|
88
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.26"
|
|
89
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.26"
|
|
90
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.26"
|
|
91
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.26"
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
### Example: Optics
|
|
@@ -143,7 +143,7 @@ Chunk is designed for:
|
|
|
143
143
|
### Installation
|
|
144
144
|
|
|
145
145
|
```scala
|
|
146
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-chunk" % "0.0.
|
|
146
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-chunk" % "0.0.26"
|
|
147
147
|
```
|
|
148
148
|
|
|
149
149
|
### Example
|
|
@@ -231,7 +231,7 @@ Scope.global.scoped { scope =>
|
|
|
231
231
|
### Installation
|
|
232
232
|
|
|
233
233
|
```scala
|
|
234
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.
|
|
234
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.26"
|
|
235
235
|
```
|
|
236
236
|
|
|
237
237
|
### Example: Basic Resource Management
|
|
@@ -334,7 +334,7 @@ Generating documentation, README files, or any Markdown content programmatically
|
|
|
334
334
|
### Installation
|
|
335
335
|
|
|
336
336
|
```scala
|
|
337
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.
|
|
337
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.26"
|
|
338
338
|
```
|
|
339
339
|
|
|
340
340
|
### Example
|
|
@@ -418,7 +418,7 @@ Compile-time type identity with rich metadata. TypeId captures comprehensive inf
|
|
|
418
418
|
### Installation
|
|
419
419
|
|
|
420
420
|
```scala
|
|
421
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-typeid" % "0.0.
|
|
421
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-typeid" % "0.0.26"
|
|
422
422
|
```
|
|
423
423
|
|
|
424
424
|
### Example
|
|
@@ -461,7 +461,7 @@ A type-indexed heterogeneous collection that stores values by their types with c
|
|
|
461
461
|
### Installation
|
|
462
462
|
|
|
463
463
|
```scala
|
|
464
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-context" % "0.0.
|
|
464
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-context" % "0.0.26"
|
|
465
465
|
```
|
|
466
466
|
|
|
467
467
|
### Example
|
package/package.json
CHANGED
package/reference/codec.md
CHANGED
|
@@ -48,23 +48,23 @@ val result: Either[SchemaError, Person] = Person.codec.decode(bytes)
|
|
|
48
48
|
To include the base schema module with JSON support, add the following dependency to your `build.sbt`:
|
|
49
49
|
|
|
50
50
|
```scala
|
|
51
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
51
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.26"
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
Additional format modules are separate artifacts:
|
|
55
55
|
|
|
56
56
|
```scala
|
|
57
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.
|
|
58
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.
|
|
59
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.
|
|
60
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.
|
|
61
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.
|
|
57
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.26"
|
|
58
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.26"
|
|
59
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.26"
|
|
60
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.26"
|
|
61
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.26"
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
For cross-platform projects (Scala.js):
|
|
65
65
|
|
|
66
66
|
```scala
|
|
67
|
-
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.
|
|
67
|
+
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.26"
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
Supported Scala versions: 2.13.x and 3.x.
|
package/reference/docs.md
CHANGED
|
@@ -10,7 +10,7 @@ Complete API reference for the zio-blocks-docs module - a zero-dependency GitHub
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
12
12
|
```scala
|
|
13
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.
|
|
13
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.26"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Core Types
|
package/reference/media-type.md
CHANGED
|
@@ -75,13 +75,13 @@ textAny.matches(html) // true
|
|
|
75
75
|
Add the following to your `build.sbt`:
|
|
76
76
|
|
|
77
77
|
```scala
|
|
78
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-mediatype" % "0.0.
|
|
78
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-mediatype" % "0.0.26"
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
For cross-platform projects (Scala.js):
|
|
82
82
|
|
|
83
83
|
```scala
|
|
84
|
-
libraryDependencies += "dev.zio" %%% "zio-blocks-mediatype" % "0.0.
|
|
84
|
+
libraryDependencies += "dev.zio" %%% "zio-blocks-mediatype" % "0.0.26"
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
Supported Scala versions: 2.13.x and 3.x.
|
package/reference/schema-expr.md
CHANGED
|
@@ -70,13 +70,13 @@ val result: Either[OpticCheck, Seq[Boolean]] = combined.eval(alice)
|
|
|
70
70
|
## Installation
|
|
71
71
|
|
|
72
72
|
```scala
|
|
73
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
73
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.26"
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
For cross-platform (Scala.js):
|
|
77
77
|
|
|
78
78
|
```scala
|
|
79
|
-
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.
|
|
79
|
+
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.26"
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -1451,7 +1451,7 @@ Now we can use the derived `Gen[Person]` instance to generate random `Person` va
|
|
|
1451
1451
|
|
|
1452
1452
|
```scala
|
|
1453
1453
|
val random = new Random(42) // Seeded for reproducible output
|
|
1454
|
-
// random: Random = scala.util.Random@
|
|
1454
|
+
// random: Random = scala.util.Random@559ce90
|
|
1455
1455
|
|
|
1456
1456
|
Person.gen.generate(random)
|
|
1457
1457
|
// res14: Person = Person(name = "p", age = -1360544799)
|
|
@@ -1599,12 +1599,13 @@ val tc: TC[A] = schema.deriving(deriver)
|
|
|
1599
1599
|
.derive // finalize the derivation
|
|
1600
1600
|
```
|
|
1601
1601
|
|
|
1602
|
-
The `DerivationBuilder` offers
|
|
1602
|
+
The `DerivationBuilder` offers three overloaded `instance` methods for providing custom type class instances:
|
|
1603
1603
|
|
|
1604
1604
|
```scala
|
|
1605
1605
|
final case class DerivationBuilder[TC[_], A](...) {
|
|
1606
1606
|
def instance[B](optic: Optic[A, B], instance: => TC[B]): DerivationBuilder[TC, A]
|
|
1607
|
-
def instance[B](typeId: TypeId[B],
|
|
1607
|
+
def instance[B](typeId: TypeId[B], instance: => TC[B]): DerivationBuilder[TC, A]
|
|
1608
|
+
def instance[P, B](typeId: TypeId[P], termName: String, instance: => TC[B]): DerivationBuilder[TC, A]
|
|
1608
1609
|
}
|
|
1609
1610
|
```
|
|
1610
1611
|
|
|
@@ -1696,15 +1697,38 @@ personShow.show(Person("Alice", 30))
|
|
|
1696
1697
|
// res32: String = "Person(name = \"Alice\", age = #30)"
|
|
1697
1698
|
```
|
|
1698
1699
|
|
|
1700
|
+
### Overriding by TypeId and Term Name
|
|
1701
|
+
|
|
1702
|
+
The third overload takes a `TypeId[P]` identifying the **parent** record or variant and a `termName` string identifying a field or case within it. This provides medium precision between optic-based (exact path) and type-based (all occurrences) overrides, and is useful when you want to override a specific field across all locations where the parent type appears without having to enumerate each path with an optic:
|
|
1703
|
+
|
|
1704
|
+
```scala
|
|
1705
|
+
val customAgeShow: Show[Int] = new Show[Int] {
|
|
1706
|
+
def show(value: Int): String = s"age=$value"
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
val personShow: Show[Person] = Person.schema
|
|
1710
|
+
.deriving(DeriveShow)
|
|
1711
|
+
.instance(Person.schema.reflect.typeId, "age", customAgeShow)
|
|
1712
|
+
.derive
|
|
1713
|
+
```
|
|
1714
|
+
|
|
1715
|
+
The `typeId` refers to the parent record/variant type (here `Person`), not the field type. If no term with the given name exists in the parent type, the override is silently ignored.
|
|
1716
|
+
|
|
1717
|
+
```scala
|
|
1718
|
+
personShow.show(Person("Alice", 30))
|
|
1719
|
+
// res33: String = "Person(name = \"Alice\", age = age=30)"
|
|
1720
|
+
```
|
|
1721
|
+
|
|
1699
1722
|
### Resolution Order
|
|
1700
1723
|
|
|
1701
1724
|
When the derivation engine encounters a schema node, it resolves the type class instance using the following priority order:
|
|
1702
1725
|
|
|
1703
1726
|
1. **Optic-based override** (most precise): If an instance override was registered using an optic that matches the current path in the schema tree, that instance is used.
|
|
1704
|
-
2. **TypeId-
|
|
1705
|
-
3. **
|
|
1727
|
+
2. **TypeId + term-name override** (medium precision): If no optic-based match is found, it checks for an override registered by parent type ID and term name.
|
|
1728
|
+
3. **TypeId-based override** (more general): If no term-name match is found, it checks for an instance override registered by type ID.
|
|
1729
|
+
4. **Automatic derivation** (default): If no override is found, the deriver's method (e.g., `derivePrimitive`, `deriveRecord`) is called to automatically derive the instance.
|
|
1706
1730
|
|
|
1707
|
-
This means you can set a global override by type and then selectively refine specific fields using optics:
|
|
1731
|
+
This means you can set a global override by type and then selectively refine specific fields using optics or term names:
|
|
1708
1732
|
|
|
1709
1733
|
```scala
|
|
1710
1734
|
val companyShow: Show[Company] = Company.schema
|
|
@@ -1722,7 +1746,7 @@ In this example, all `String` fields use single quotes, except for the CEO's nam
|
|
|
1722
1746
|
|
|
1723
1747
|
```scala
|
|
1724
1748
|
companyShow.show(Company(Person("Alice", 30), "tech"))
|
|
1725
|
-
//
|
|
1749
|
+
// res34: String = "Company(ceo = Person(name = ALICE, age = 30), industry = 'tech')"
|
|
1726
1750
|
```
|
|
1727
1751
|
|
|
1728
1752
|
### Chaining Multiple Overrides
|
|
@@ -1743,7 +1767,7 @@ val personShow: Show[Person] = Person.schema
|
|
|
1743
1767
|
|
|
1744
1768
|
```scala
|
|
1745
1769
|
personShow.show(Person("Alice", 30))
|
|
1746
|
-
//
|
|
1770
|
+
// res35: String = "Person(name = <<Alice>>, age = age=30)"
|
|
1747
1771
|
```
|
|
1748
1772
|
|
|
1749
1773
|
## Custom Modifiers
|
|
@@ -1756,12 +1780,13 @@ While modifiers can be attached to schemas directly using Scala annotations (e.g
|
|
|
1756
1780
|
- You need different modifiers for different derivation contexts (e.g., one JSON codec with renamed fields, another without)
|
|
1757
1781
|
- You want to keep the schema clean and push format-specific concerns into the derivation layer
|
|
1758
1782
|
|
|
1759
|
-
The `DerivationBuilder` offers
|
|
1783
|
+
The `DerivationBuilder` offers three overloaded `modifier` methods:
|
|
1760
1784
|
|
|
1761
1785
|
```scala
|
|
1762
1786
|
final case class DerivationBuilder[TC[_], A](...) {
|
|
1763
|
-
def modifier[B](typeId: TypeId[B],
|
|
1764
|
-
def modifier[B](optic: Optic[A, B], modifier: Modifier)
|
|
1787
|
+
def modifier[B](typeId: TypeId[B], modifier: Modifier.Reflect): DerivationBuilder[TC, A]
|
|
1788
|
+
def modifier[B](optic: Optic[A, B], modifier: Modifier): DerivationBuilder[TC, A]
|
|
1789
|
+
def modifier[B](typeId: TypeId[B], termName: String, modifier: Modifier.Term): DerivationBuilder[TC, A]
|
|
1765
1790
|
}
|
|
1766
1791
|
```
|
|
1767
1792
|
|
|
@@ -1823,7 +1848,7 @@ val user = User(1L, "Alice", "alice@example.com", 95.5)
|
|
|
1823
1848
|
// internalScore = 95.5
|
|
1824
1849
|
// )
|
|
1825
1850
|
new String(jsonCodec.encode(user), "UTF-8")
|
|
1826
|
-
//
|
|
1851
|
+
// res36: String = "{\"id\":1,\"full_name\":\"Alice\",\"email\":\"alice@example.com\"}"
|
|
1827
1852
|
```
|
|
1828
1853
|
|
|
1829
1854
|
### Adding Modifiers by TypeId
|
|
@@ -1838,6 +1863,18 @@ val jsonCodec: JsonBinaryCodec[User] = User.schema
|
|
|
1838
1863
|
.derive
|
|
1839
1864
|
```
|
|
1840
1865
|
|
|
1866
|
+
### Adding Modifiers by TypeId and Term Name
|
|
1867
|
+
|
|
1868
|
+
The `modifier` method with `TypeId` and `termName` allows you to add a `Modifier.Term` to a specific field or case identified by name inside a parent type identified by its `TypeId`. This is useful when you want to target a specific term without constructing an optic for it. The `typeId` refers to the parent record/variant type that owns the term. If no term with the given name exists in the parent type, the modifier is silently ignored:
|
|
1869
|
+
|
|
1870
|
+
```scala
|
|
1871
|
+
val jsonCodec: JsonBinaryCodec[User] = User.schema
|
|
1872
|
+
.deriving(JsonBinaryCodecDeriver)
|
|
1873
|
+
.modifier(User.schema.reflect.typeId, "name", Modifier.rename("full_name"))
|
|
1874
|
+
.modifier(User.schema.reflect.typeId, "internalScore", Modifier.transient())
|
|
1875
|
+
.derive
|
|
1876
|
+
```
|
|
1877
|
+
|
|
1841
1878
|
## Derivation Process In-Depth
|
|
1842
1879
|
|
|
1843
1880
|
Until now, we learned how to implement the `Deriver` methods for different schema patterns. But we haven't yet discussed how the overall derivation process works. In this section, we will go through the main steps of derivation in detail.
|