@zio.dev/zio-blocks 0.0.29 → 0.0.31
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/compile-time-resource-safety-with-scope.md +997 -0
- package/guides/query-dsl-extending.md +1 -1
- package/guides/query-dsl-fluent-builder.md +203 -203
- package/guides/query-dsl-reified-optics.md +1 -1
- package/guides/query-dsl-sql.md +1 -1
- package/guides/zio-schema-migration.md +8 -8
- package/index.md +20 -14
- package/package.json +1 -1
- package/reference/codec.md +17 -17
- package/reference/context.md +49 -1
- package/reference/docs.md +1 -1
- package/reference/dynamic-schema.md +39 -42
- package/reference/formats.md +5 -11
- package/reference/json-schema.md +2 -2
- package/reference/json.md +34 -43
- package/reference/media-type.md +2 -2
- package/reference/modifier.md +4 -4
- package/reference/resource-management/defer-handle.md +246 -0
- package/reference/resource-management/finalization.md +286 -0
- package/reference/resource-management/finalizer.md +167 -0
- package/reference/{resource-management-di → resource-management}/index.md +3 -8
- package/reference/{resource-management-di → resource-management}/resource.md +532 -50
- package/reference/resource-management/scope.md +3026 -0
- package/reference/resource-management/unscoped.md +125 -0
- package/reference/{resource-management-di → resource-management}/wire.md +122 -28
- package/reference/schema-error.md +0 -1
- package/reference/schema-evolution/as.md +4 -4
- package/reference/schema-evolution/into.md +2 -2
- package/reference/schema-expr.md +2 -2
- package/reference/schema.md +9 -4
- package/reference/streams.md +989 -0
- package/reference/type-class-derivation.md +14 -15
- package/ringbuffer.md +1 -1
- package/sidebars.js +9 -4
- package/undocumented-report.md +1 -1
- package/reference/resource-management-di/scope.md +0 -1423
|
@@ -15,7 +15,7 @@ Consider a typical application with 50 domain types that needs 4 type classes (J
|
|
|
15
15
|
|
|
16
16
|
Each instance requires understanding both the type's structure and the type class's semantics, then correctly implementing encoding, decoding, or whatever operation is required. This quickly becomes unmanageable as the codebase grows.
|
|
17
17
|
|
|
18
|
-
Assume we have a simple `
|
|
18
|
+
Assume we have a simple `JsonTC` type class for JSON serialization and deserialization:
|
|
19
19
|
|
|
20
20
|
```scala
|
|
21
21
|
import zio.blocks.schema.json._
|
|
@@ -28,7 +28,7 @@ case class ParseError(details: String)
|
|
|
28
28
|
case class DecodeError(details: String, path: String)
|
|
29
29
|
extends JsonError(s"Decode Error at '$path': $details")
|
|
30
30
|
|
|
31
|
-
trait
|
|
31
|
+
trait JsonTC[A] {
|
|
32
32
|
def encode(a: A): Json
|
|
33
33
|
def decode(j: Json): Either[JsonError, A]
|
|
34
34
|
}
|
|
@@ -40,8 +40,8 @@ A single manual codec for a simple type like `Person` looks like the following c
|
|
|
40
40
|
case class Person(name: String, age: Int)
|
|
41
41
|
|
|
42
42
|
object Person {
|
|
43
|
-
implicit val personCodec:
|
|
44
|
-
new
|
|
43
|
+
implicit val personCodec: JsonTC[Person] =
|
|
44
|
+
new JsonTC[Person] {
|
|
45
45
|
def encode(c: Person): Json = Json.obj(
|
|
46
46
|
"name" -> Json.str(c.name),
|
|
47
47
|
"age" -> Json.number(c.age)
|
|
@@ -132,11 +132,11 @@ case class Schema[A](reflect: Reflect.Bound[A]) {
|
|
|
132
132
|
}
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
It takes a `Deriver[TC]` as a parameter and returns a type class instance of type `TC[A]`. For example, in the following code snippet, we derive a `
|
|
135
|
+
It takes a `Deriver[TC]` as a parameter and returns a type class instance of type `TC[A]`. For example, in the following code snippet, we derive a `JsonCodec[Person]` instance for the `Person` case class using the `JsonCodecDeriver`:
|
|
136
136
|
|
|
137
137
|
```scala
|
|
138
138
|
import zio.blocks.schema._
|
|
139
|
-
import zio.blocks.schema.json.
|
|
139
|
+
import zio.blocks.schema.json.JsonCodecDeriver
|
|
140
140
|
|
|
141
141
|
case class Person(name: String, age: Int)
|
|
142
142
|
|
|
@@ -144,8 +144,7 @@ object Person {
|
|
|
144
144
|
implicit val schema: Schema[Person] = Schema.derived[Person]
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
val jsonCodec:
|
|
148
|
-
Person.schema.derive(JsonBinaryCodecDeriver)
|
|
147
|
+
val jsonCodec: JsonCodec[Person] = Person.schema.derive(JsonCodecDeriver)
|
|
149
148
|
|
|
150
149
|
val result: Either[SchemaError, Person] =
|
|
151
150
|
jsonCodec.decode(
|
|
@@ -1456,7 +1455,7 @@ Now we can use the derived `Gen[Person]` instance to generate random `Person` va
|
|
|
1456
1455
|
|
|
1457
1456
|
```scala
|
|
1458
1457
|
val random = new Random(42) // Seeded for reproducible output
|
|
1459
|
-
// random: Random = scala.util.Random@
|
|
1458
|
+
// random: Random = scala.util.Random@76e55e4e
|
|
1460
1459
|
|
|
1461
1460
|
Person.gen.generate(random)
|
|
1462
1461
|
// res14: Person = Person(name = "p", age = -1360544799)
|
|
@@ -1831,8 +1830,8 @@ object User extends CompanionOptics[User] {
|
|
|
1831
1830
|
Now we can derive a JSON codec with custom modifiers, renaming fields and marking one as transient, without changing the schema itself:
|
|
1832
1831
|
|
|
1833
1832
|
```scala
|
|
1834
|
-
val jsonCodec:
|
|
1835
|
-
.deriving(
|
|
1833
|
+
val jsonCodec: JsonCodec[User] = User.schema
|
|
1834
|
+
.deriving(JsonCodecDeriver)
|
|
1836
1835
|
.modifier(User.name, Modifier.rename("full_name"))
|
|
1837
1836
|
.modifier(User.email, Modifier.alias("mail"))
|
|
1838
1837
|
.modifier(User.internalScore, Modifier.transient())
|
|
@@ -1861,8 +1860,8 @@ new String(jsonCodec.encode(user), "UTF-8")
|
|
|
1861
1860
|
The `modifier` method with `TypeId` allows you to add a `Modifier.Reflect` to all schema nodes of a given type. This is useful for attaching format-specific configuration metadata to all occurrences of a type:
|
|
1862
1861
|
|
|
1863
1862
|
```scala
|
|
1864
|
-
val jsonCodec:
|
|
1865
|
-
.deriving(
|
|
1863
|
+
val jsonCodec: JsonCodec[User] = User.schema
|
|
1864
|
+
.deriving(JsonCodecDeriver)
|
|
1866
1865
|
.modifier(TypeId.of[User], Modifier.config("json", "camelCase"))
|
|
1867
1866
|
.modifier(User.internalScore, Modifier.transient())
|
|
1868
1867
|
.derive
|
|
@@ -1873,8 +1872,8 @@ val jsonCodec: JsonBinaryCodec[User] = User.schema
|
|
|
1873
1872
|
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:
|
|
1874
1873
|
|
|
1875
1874
|
```scala
|
|
1876
|
-
val jsonCodec:
|
|
1877
|
-
.deriving(
|
|
1875
|
+
val jsonCodec: JsonCodec[User] = User.schema
|
|
1876
|
+
.deriving(JsonCodecDeriver)
|
|
1878
1877
|
.modifier(User.schema.reflect.typeId, "name", Modifier.rename("full_name"))
|
|
1879
1878
|
.modifier(User.schema.reflect.typeId, "internalScore", Modifier.transient())
|
|
1880
1879
|
.derive
|
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.31"
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
---
|
package/sidebars.js
CHANGED
|
@@ -42,11 +42,15 @@ const sidebars = {
|
|
|
42
42
|
{
|
|
43
43
|
type: "category",
|
|
44
44
|
label: "Resource Management & DI",
|
|
45
|
-
link: { type: "doc", id: "reference/resource-management
|
|
45
|
+
link: { type: "doc", id: "reference/resource-management/index" },
|
|
46
46
|
items: [
|
|
47
|
-
"reference/resource-management
|
|
48
|
-
"reference/resource-management
|
|
49
|
-
"reference/resource-management
|
|
47
|
+
"reference/resource-management/scope",
|
|
48
|
+
"reference/resource-management/resource",
|
|
49
|
+
"reference/resource-management/wire",
|
|
50
|
+
"reference/resource-management/unscoped",
|
|
51
|
+
"reference/resource-management/defer-handle",
|
|
52
|
+
"reference/resource-management/finalizer",
|
|
53
|
+
"reference/resource-management/finalization",
|
|
50
54
|
]
|
|
51
55
|
},
|
|
52
56
|
"reference/combinators",
|
|
@@ -66,6 +70,7 @@ const sidebars = {
|
|
|
66
70
|
type: "category",
|
|
67
71
|
label: "Guides",
|
|
68
72
|
items: [
|
|
73
|
+
"guides/compile-time-resource-safety-with-scope",
|
|
69
74
|
"guides/zio-schema-migration",
|
|
70
75
|
"guides/query-dsl-reified-optics",
|
|
71
76
|
"guides/query-dsl-sql",
|
package/undocumented-report.md
CHANGED
|
@@ -59,7 +59,7 @@ These are core public API types that users interact with directly. Each needs a
|
|
|
59
59
|
**schema module — JSON subsystem:**
|
|
60
60
|
- [ ] **`Keyable`** — Type class for JSON key support. Referenced in 5 files. **Scope: new section in json.md**. Source: `schema/shared/src/main/scala/zio/blocks/schema/json/Keyable.scala`
|
|
61
61
|
- [ ] **`NameMapper`** (`CamelCase`, `KebabCase`, `PascalCase`) — Public field name transformations. **Scope: new section in json.md**. Source: `schema/shared/src/main/scala/zio/blocks/schema/json/NameMapper.scala`
|
|
62
|
-
- [ ] **`
|
|
62
|
+
- [ ] **`JsonCodecError`** — Custom exception for JSON codec errors. Referenced in 7 files. **Scope: brief section in json.md**. Source: `schema/shared/src/main/scala/zio/blocks/schema/json/JsonCodecError.scala`
|
|
63
63
|
|
|
64
64
|
**typeid module:**
|
|
65
65
|
- [ ] **`TypeRepr`** — Central type representation (24 subtypes: ThisType, TypeLambda, Singleton, Repeated, etc.). Referenced across 4-8 files each. **Scope: new section in typeid.md**. Source: `typeid/shared/src/main/scala/zio/blocks/typeid/TypeRepr.scala`
|