@zio.dev/zio-blocks 0.0.30 → 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/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 +8 -8
- package/index.md +12 -12
- 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 +3 -3
- 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/resource.md +2 -2
- package/reference/resource-management/scope.md +1 -1
- package/reference/resource-management/wire.md +50 -2
- 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/type-class-derivation.md +14 -15
- package/ringbuffer.md +1 -1
- package/undocumented-report.md +1 -1
|
@@ -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.31"
|
|
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.31"
|
|
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.31"
|
|
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.31"
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
```scala
|
|
@@ -38,13 +38,13 @@ libraryDependencies += "dev.zio" %% "zio-schema-avro" % "1.x.x"
|
|
|
38
38
|
**After (ZIO Blocks Schema):**
|
|
39
39
|
|
|
40
40
|
```scala
|
|
41
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
41
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.31"
|
|
42
42
|
// Optional codec modules:
|
|
43
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.
|
|
44
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.
|
|
45
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.
|
|
46
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.
|
|
47
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.
|
|
43
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.31"
|
|
44
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.31"
|
|
45
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.31"
|
|
46
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.31"
|
|
47
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.31"
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
Key points:
|
|
@@ -536,7 +536,7 @@ val protoCodec: BinaryCodec[Person] = ProtobufCodec.protobufCodec(Person.schema)
|
|
|
536
536
|
// ZIO Blocks Schema — all codecs via schema.derive(Format); return type inferred
|
|
537
537
|
import zio.blocks.schema._
|
|
538
538
|
import zio.blocks.schema.json.JsonFormat
|
|
539
|
-
val jsonCodec = Person.schema.derive(JsonFormat) // inferred:
|
|
539
|
+
val jsonCodec = Person.schema.derive(JsonFormat) // inferred: JsonCodec[Person]
|
|
540
540
|
|
|
541
541
|
import zio.blocks.schema.avro.AvroFormat
|
|
542
542
|
val avroCodec = Person.schema.derive(AvroFormat)
|
|
@@ -593,7 +593,7 @@ val codec = JsonCodec.jsonCodec(Person.schema) // returns zio.json.JsonCodec
|
|
|
593
593
|
|
|
594
594
|
// ZIO Blocks Schema — built into zio-blocks-schema; no extra dependency
|
|
595
595
|
import zio.blocks.schema.json.JsonFormat
|
|
596
|
-
val codec = Person.schema.derive(JsonFormat) // returns
|
|
596
|
+
val codec = Person.schema.derive(JsonFormat) // returns JsonCodec[Person]
|
|
597
597
|
```
|
|
598
598
|
|
|
599
599
|
### Streaming Codecs
|
package/index.md
CHANGED
|
@@ -82,14 +82,14 @@ val thriftCodec = Schema[Person].derive(ThriftFormat) // Thrift
|
|
|
82
82
|
### Installation
|
|
83
83
|
|
|
84
84
|
```scala
|
|
85
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
85
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.31"
|
|
86
86
|
|
|
87
87
|
// Optional format modules:
|
|
88
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.
|
|
89
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.
|
|
90
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.
|
|
91
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.
|
|
92
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.
|
|
88
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.31"
|
|
89
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.31"
|
|
90
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.31"
|
|
91
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.31"
|
|
92
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.31"
|
|
93
93
|
```
|
|
94
94
|
|
|
95
95
|
### Example: Optics
|
|
@@ -144,7 +144,7 @@ Chunk is designed for:
|
|
|
144
144
|
### Installation
|
|
145
145
|
|
|
146
146
|
```scala
|
|
147
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-chunk" % "0.0.
|
|
147
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-chunk" % "0.0.31"
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
### Example
|
|
@@ -233,7 +233,7 @@ Scope.global.scoped { scope =>
|
|
|
233
233
|
### Installation
|
|
234
234
|
|
|
235
235
|
```scala
|
|
236
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.
|
|
236
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.31"
|
|
237
237
|
```
|
|
238
238
|
|
|
239
239
|
### Example: Basic Resource Management
|
|
@@ -342,7 +342,7 @@ Generating documentation, README files, or any Markdown content programmatically
|
|
|
342
342
|
### Installation
|
|
343
343
|
|
|
344
344
|
```scala
|
|
345
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.
|
|
345
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.31"
|
|
346
346
|
```
|
|
347
347
|
|
|
348
348
|
### Example
|
|
@@ -426,7 +426,7 @@ Compile-time type identity with rich metadata. TypeId captures comprehensive inf
|
|
|
426
426
|
### Installation
|
|
427
427
|
|
|
428
428
|
```scala
|
|
429
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-typeid" % "0.0.
|
|
429
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-typeid" % "0.0.31"
|
|
430
430
|
```
|
|
431
431
|
|
|
432
432
|
### Example
|
|
@@ -469,7 +469,7 @@ A type-indexed heterogeneous collection that stores values by their types with c
|
|
|
469
469
|
### Installation
|
|
470
470
|
|
|
471
471
|
```scala
|
|
472
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-context" % "0.0.
|
|
472
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-context" % "0.0.31"
|
|
473
473
|
```
|
|
474
474
|
|
|
475
475
|
### Example
|
|
@@ -521,7 +521,7 @@ Standard `java.util.concurrent` queues use node allocation (`ConcurrentLinkedQue
|
|
|
521
521
|
### Installation
|
|
522
522
|
|
|
523
523
|
```scala
|
|
524
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-ringbuffer" % "0.0.
|
|
524
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-ringbuffer" % "0.0.31"
|
|
525
525
|
```
|
|
526
526
|
|
|
527
527
|
### Example
|
package/package.json
CHANGED
package/reference/codec.md
CHANGED
|
@@ -19,7 +19,7 @@ abstract class Codec[DecodeInput, EncodeOutput, Value] {
|
|
|
19
19
|
- **`encode`** writes the encoded form of `value` into `output`. The output parameter is typically a mutable buffer (`ByteBuffer`, `CharBuffer`) that the caller provides.
|
|
20
20
|
- **`decode`** reads from `input` and returns either a `SchemaError` describing the failure or the decoded value.
|
|
21
21
|
|
|
22
|
-
End users rarely interact with `Codec` directly. Instead, they work with format-specific subclasses like `
|
|
22
|
+
End users rarely interact with `Codec` directly. Instead, they work with format-specific subclasses like `JsonCodec[A]` or `ToonBinaryCodec[A]`, which add convenience methods for common input/output types.
|
|
23
23
|
|
|
24
24
|
Given a `Schema[A]`, you can derive a codec for any supported format by calling `Schema[A].derive(format)`, which uses the `Deriver` associated with that format to generate the appropriate codec instance. For example, to derive a JSON codec:
|
|
25
25
|
|
|
@@ -33,7 +33,7 @@ object Person {
|
|
|
33
33
|
// Derive a schema for Person (required for codec derivation)
|
|
34
34
|
implicit val schema: Schema[Person] = Schema.derived
|
|
35
35
|
// Derive a JSON codec from the schema
|
|
36
|
-
implicit val codec:
|
|
36
|
+
implicit val codec: JsonCodec[Person] = schema.derive(JsonFormat)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Encode
|
|
@@ -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.31"
|
|
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.31"
|
|
58
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.31"
|
|
59
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.31"
|
|
60
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.31"
|
|
61
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.31"
|
|
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.31"
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -76,7 +76,7 @@ The codec system in ZIO Blocks is organized as a layered hierarchy:
|
|
|
76
76
|
```
|
|
77
77
|
Codec[DecodeInput, EncodeOutput, Value]
|
|
78
78
|
├── BinaryCodec[A] = Codec[ByteBuffer, ByteBuffer, A] (ByteBuffer ↔ A)
|
|
79
|
-
│ ├──
|
|
79
|
+
│ ├── JsonCodec[A]
|
|
80
80
|
│ ├── AvroBinaryCodec[A]
|
|
81
81
|
│ ├── ToonBinaryCodec[A]
|
|
82
82
|
│ ├── ThriftBinaryCodec[A]
|
|
@@ -116,7 +116,7 @@ object Person {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
// Pass a Format object to get a codec for that format
|
|
119
|
-
val jsonCodec:
|
|
119
|
+
val jsonCodec: JsonCodec[Person] = Schema[Person].derive(JsonFormat)
|
|
120
120
|
```
|
|
121
121
|
|
|
122
122
|
This works with any format:
|
|
@@ -151,12 +151,12 @@ object Person extends CompanionOptics[Person] {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
// Override the codec for the "name" field
|
|
154
|
-
val customNameCodec = new
|
|
154
|
+
val customNameCodec = new JsonCodec[String] {
|
|
155
155
|
def decodeValue(in: JsonReader): String = in.readString()
|
|
156
156
|
def encodeValue(x: String, out: JsonWriter): Unit = out.writeVal(x.toUpperCase)
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
val codec:
|
|
159
|
+
val codec: JsonCodec[Person] = Schema[Person]
|
|
160
160
|
.deriving(JsonFormat.deriver)
|
|
161
161
|
.instance(Person.name, customNameCodec)
|
|
162
162
|
.derive
|
|
@@ -207,11 +207,11 @@ Passing a `Deriver` directly is useful when working with custom or configured de
|
|
|
207
207
|
|
|
208
208
|
## Convenience Methods on Format-Specific Codecs
|
|
209
209
|
|
|
210
|
-
While the base `Codec` class defines only `encode(value, output)` and `decode(input)`, format-specific subclasses like `
|
|
210
|
+
While the base `Codec` class defines only `encode(value, output)` and `decode(input)`, format-specific subclasses like `JsonCodec` and `ToonBinaryCodec` add convenience overloads for common I/O types.
|
|
211
211
|
|
|
212
|
-
###
|
|
212
|
+
### JsonCodec Convenience Methods
|
|
213
213
|
|
|
214
|
-
`
|
|
214
|
+
`JsonCodec[A]` provides the following overloads beyond the base `ByteBuffer` API:
|
|
215
215
|
|
|
216
216
|
```scala
|
|
217
217
|
import zio.blocks.schema._
|
|
@@ -307,7 +307,7 @@ object Person {
|
|
|
307
307
|
implicit val schema: Schema[Person] = Schema.derived
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
val customDeriver =
|
|
310
|
+
val customDeriver = JsonCodecDeriver
|
|
311
311
|
.withFieldNameMapper(NameMapper.SnakeCase)
|
|
312
312
|
.withTransientNone(true)
|
|
313
313
|
.withRejectExtraFields(true)
|
package/reference/context.md
CHANGED
|
@@ -116,7 +116,7 @@ val config = ctx.get[Config] // Compile-time proof it exists
|
|
|
116
116
|
Add the ZIO Blocks Context module to your `build.sbt`:
|
|
117
117
|
|
|
118
118
|
```scala
|
|
119
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-context" % "0.0.
|
|
119
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-context" % "0.0.31"
|
|
120
120
|
```
|
|
121
121
|
|
|
122
122
|
## Construction
|
|
@@ -525,6 +525,22 @@ cd zio-blocks
|
|
|
525
525
|
**Context construction: creating contexts with apply, empty.add, and inspecting size/isEmpty/nonEmpty**
|
|
526
526
|
|
|
527
527
|
```scala title="schema-examples/src/main/scala/context/ContextConstructionExample.scala"
|
|
528
|
+
/*
|
|
529
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
530
|
+
*
|
|
531
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
532
|
+
* you may not use this file except in compliance with the License.
|
|
533
|
+
* You may obtain a copy of the License at
|
|
534
|
+
*
|
|
535
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
536
|
+
*
|
|
537
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
538
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
539
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
540
|
+
* See the License for the specific language governing permissions and
|
|
541
|
+
* limitations under the License.
|
|
542
|
+
*/
|
|
543
|
+
|
|
528
544
|
package context
|
|
529
545
|
|
|
530
546
|
import zio.blocks.context._
|
|
@@ -586,6 +602,22 @@ sbt "schema-examples/runMain context.ContextConstructionExample"
|
|
|
586
602
|
**Context retrieval: using get, supertype lookups, and getOption for safe access**
|
|
587
603
|
|
|
588
604
|
```scala title="schema-examples/src/main/scala/context/ContextRetrievalExample.scala"
|
|
605
|
+
/*
|
|
606
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
607
|
+
*
|
|
608
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
609
|
+
* you may not use this file except in compliance with the License.
|
|
610
|
+
* You may obtain a copy of the License at
|
|
611
|
+
*
|
|
612
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
613
|
+
*
|
|
614
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
615
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
616
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
617
|
+
* See the License for the specific language governing permissions and
|
|
618
|
+
* limitations under the License.
|
|
619
|
+
*/
|
|
620
|
+
|
|
589
621
|
package context
|
|
590
622
|
|
|
591
623
|
import zio.blocks.context._
|
|
@@ -655,6 +687,22 @@ sbt "schema-examples/runMain context.ContextRetrievalExample"
|
|
|
655
687
|
**Context modification: adding values, updating existing ones, merging contexts, and pruning types**
|
|
656
688
|
|
|
657
689
|
```scala title="schema-examples/src/main/scala/context/ContextModificationExample.scala"
|
|
690
|
+
/*
|
|
691
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
692
|
+
*
|
|
693
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
694
|
+
* you may not use this file except in compliance with the License.
|
|
695
|
+
* You may obtain a copy of the License at
|
|
696
|
+
*
|
|
697
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
698
|
+
*
|
|
699
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
700
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
701
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
702
|
+
* See the License for the specific language governing permissions and
|
|
703
|
+
* limitations under the License.
|
|
704
|
+
*/
|
|
705
|
+
|
|
658
706
|
package context
|
|
659
707
|
|
|
660
708
|
import zio.blocks.context._
|
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.31"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Core Types
|
|
@@ -83,7 +83,7 @@ dynamic
|
|
|
83
83
|
// value = Primitive(
|
|
84
84
|
// primitiveType = String(None),
|
|
85
85
|
// typeId = String,
|
|
86
|
-
// primitiveBinding = zio.blocks.schema.binding.NoBinding$$anon$1@
|
|
86
|
+
// primitiveBinding = zio.blocks.schema.binding.NoBinding$$anon$1@53d6fe60,
|
|
87
87
|
// doc = Doc(blocks = IndexedSeq(), metadata = Map()),
|
|
88
88
|
// modifiers = List(),
|
|
89
89
|
// storedDefaultValue = None,
|
|
@@ -97,7 +97,7 @@ dynamic
|
|
|
97
97
|
// value = Primitive(
|
|
98
98
|
// primitiveType = Int(None),
|
|
99
99
|
// typeId = Int,
|
|
100
|
-
// primitiveBinding = zio.blocks.schema.binding.NoBinding$$anon$1@
|
|
100
|
+
// primitiveBinding = zio.blocks.schema.binding.NoBinding$$anon$1@53d6fe60,
|
|
101
101
|
// doc = Doc(blocks = IndexedSeq(), metadata = Map()),
|
|
102
102
|
// modifiers = List(),
|
|
103
103
|
// storedDefaultValue = None,
|
|
@@ -115,7 +115,7 @@ dynamic
|
|
|
115
115
|
// value = Primitive(
|
|
116
116
|
// primitiveType = String(None),
|
|
117
117
|
// typeId = String,
|
|
118
|
-
// primitiveBinding = zio.blocks.schema.binding.NoBinding$$anon$1@
|
|
118
|
+
// primitiveBinding = zio.blocks.schema.binding.NoBinding$$anon$1@53d6fe60,
|
|
119
119
|
// doc = Doc(blocks = IndexedSeq(), metadata = Map()),
|
|
120
120
|
// modifiers = List(),
|
|
121
121
|
// storedDefaultValue = None,
|
package/reference/formats.md
CHANGED
|
@@ -34,10 +34,10 @@ abstract class BinaryFormat[...](...) extends Format { ... }
|
|
|
34
34
|
abstract class TextFormat[...](...) extends Format { ... }
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
For example, the `JsonFormat` is a `BinaryFormat` that represents a JSON binary format, where the input for decoding is `ByteBuffer` and the output for encoding is also `ByteBuffer`, the MIME type is `application/json`, and the deriver for generating codecs from schemas is `
|
|
37
|
+
For example, the `JsonFormat` is a `BinaryFormat` that represents a JSON binary format, where the input for decoding is `ByteBuffer` and the output for encoding is also `ByteBuffer`, the MIME type is `application/json`, and the deriver for generating codecs from schemas is `JsonCodecDeriver`:
|
|
38
38
|
|
|
39
39
|
```scala
|
|
40
|
-
object JsonFormat extends BinaryFormat("application/json",
|
|
40
|
+
object JsonFormat extends BinaryFormat("application/json", JsonCodecDeriver)
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
## Built-in Formats
|
|
@@ -46,7 +46,7 @@ Here's a summary of the formats currently supported by ZIO Blocks. Each format p
|
|
|
46
46
|
|
|
47
47
|
| Format Object | Codec Type | MIME Type | Module |
|
|
48
48
|
|---------------------|-----------------------------|-----------------------|---------------------------------|
|
|
49
|
-
| `JsonFormat` | `
|
|
49
|
+
| `JsonFormat` | `JsonCodec[A]` | `application/json` | `zio-blocks-schema` |
|
|
50
50
|
| `ToonFormat` | `ToonBinaryCodec[A]` | `text/toon` | `zio-blocks-schema-toon` |
|
|
51
51
|
| `MessagePackFormat` | `MessagePackBinaryCodec[A]` | `application/msgpack` | `zio-blocks-schema-messagepack` |
|
|
52
52
|
| `AvroFormat` | `AvroBinaryCodec[A]` | `application/avro` | `zio-blocks-schema-avro` |
|
|
@@ -120,15 +120,9 @@ object Person {
|
|
|
120
120
|
implicit val schema: Schema[Person] = Schema.derived
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
// Using JsonEncoder/JsonDecoder
|
|
124
|
-
val jsonEncoder = JsonEncoder[Person]
|
|
125
|
-
val jsonDecoder = JsonDecoder[Person]
|
|
126
|
-
|
|
127
123
|
val person = Person("Alice", 30)
|
|
128
|
-
val
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
val decoded: Either[SchemaError, Person] = jsonDecoder.decode(json)
|
|
124
|
+
val bytes: Array[Byte] = person.toJsonBytes
|
|
125
|
+
val decoded: Either[SchemaError, Person] = bytes.fromJson[Person]
|
|
132
126
|
```
|
|
133
127
|
|
|
134
128
|
## Avro Format
|
package/reference/json-schema.md
CHANGED
|
@@ -51,9 +51,9 @@ jsonSchema.conforms(valid) // true
|
|
|
51
51
|
jsonSchema.conforms(invalid) // false
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
### Through
|
|
54
|
+
### Through JsonCodec
|
|
55
55
|
|
|
56
|
-
For more control, derive through `
|
|
56
|
+
For more control, derive through `JsonCodec`:
|
|
57
57
|
|
|
58
58
|
```scala
|
|
59
59
|
import zio.blocks.schema._
|
package/reference/json.md
CHANGED
|
@@ -531,69 +531,62 @@ val normalized = json.normalize
|
|
|
531
531
|
|
|
532
532
|
## Encoding and Decoding
|
|
533
533
|
|
|
534
|
-
###
|
|
535
|
-
|
|
536
|
-
ZIO Blocks provides `JsonEncoder` and `JsonDecoder` type classes for converting between Scala types and `Json`:
|
|
534
|
+
### Built-in Codecs
|
|
537
535
|
|
|
538
536
|
```scala
|
|
539
|
-
import zio.blocks.schema.
|
|
537
|
+
import zio.blocks.schema.Schema
|
|
540
538
|
|
|
541
|
-
//
|
|
542
|
-
|
|
543
|
-
|
|
539
|
+
// Primitives
|
|
540
|
+
Schema[String].jsonCodec
|
|
541
|
+
Schema[Int].jsonCodec
|
|
542
|
+
Schema[Long].jsonCodec
|
|
543
|
+
Schema[Double].jsonCodec
|
|
544
|
+
Schema[Boolean].jsonCodec
|
|
545
|
+
Schema[BigDecimal].jsonCodec
|
|
544
546
|
|
|
545
|
-
//
|
|
546
|
-
|
|
547
|
-
|
|
547
|
+
// Collections
|
|
548
|
+
Schema[List[Int]].jsonCodec
|
|
549
|
+
Schema[Vector[String]].jsonCodec
|
|
550
|
+
Schema[Map[String, Int]].jsonCodec
|
|
551
|
+
Schema[Option[String]].jsonCodec
|
|
552
|
+
|
|
553
|
+
// Java time/util types
|
|
554
|
+
Schema[java.time.Instant].jsonCodec
|
|
555
|
+
Schema[java.time.LocalDate].jsonCodec
|
|
556
|
+
Schema[java.time.ZonedDateTime].jsonCodec
|
|
557
|
+
Schema[java.util.UUID].jsonCodec
|
|
548
558
|
```
|
|
549
559
|
|
|
550
|
-
###
|
|
560
|
+
### Encoding/Decoding of Primitives
|
|
551
561
|
|
|
552
562
|
```scala
|
|
553
|
-
import zio.blocks.schema.
|
|
554
|
-
|
|
555
|
-
// Primitives
|
|
556
|
-
JsonEncoder[String]
|
|
557
|
-
JsonEncoder[Int]
|
|
558
|
-
JsonEncoder[Long]
|
|
559
|
-
JsonEncoder[Double]
|
|
560
|
-
JsonEncoder[Boolean]
|
|
561
|
-
JsonEncoder[BigDecimal]
|
|
563
|
+
import zio.blocks.schema._
|
|
562
564
|
|
|
563
|
-
//
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
JsonEncoder[Map[String, Int]]
|
|
567
|
-
JsonEncoder[Option[String]]
|
|
565
|
+
// Encode Scala values to Json
|
|
566
|
+
val intJson = 42.toJson // Json.Number(42)
|
|
567
|
+
val strJson = "hello".toJson // Json.String("hello")
|
|
568
568
|
|
|
569
|
-
//
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
JsonEncoder[java.time.ZonedDateTime]
|
|
573
|
-
JsonEncoder[java.util.UUID]
|
|
569
|
+
// Decode Json to Scala values
|
|
570
|
+
val intResult = intJson.as[Int] // Right(42)
|
|
571
|
+
val strResult = strJson.as[String] // Right("hello")
|
|
574
572
|
```
|
|
575
573
|
|
|
576
|
-
###
|
|
574
|
+
### Encoding/Decoding of Case Classes
|
|
577
575
|
|
|
578
576
|
For complex types, use Schema-based derivation:
|
|
579
577
|
|
|
580
578
|
```scala
|
|
581
|
-
import zio.blocks.schema.
|
|
582
|
-
import zio.blocks.schema.json.{Json, JsonEncoder, JsonDecoder}
|
|
579
|
+
import zio.blocks.schema._
|
|
583
580
|
|
|
584
581
|
case class Person(name: String, age: Int)
|
|
585
582
|
|
|
586
583
|
object Person {
|
|
587
584
|
implicit val schema: Schema[Person] = Schema.derived
|
|
588
|
-
|
|
589
|
-
// Derived from schema (lower priority)
|
|
590
|
-
implicit val encoder: JsonEncoder[Person] = JsonEncoder.fromSchema
|
|
591
|
-
implicit val decoder: JsonDecoder[Person] = JsonDecoder.fromSchema
|
|
592
585
|
}
|
|
593
586
|
|
|
594
587
|
val person = Person("Alice", 30)
|
|
595
|
-
val json =
|
|
596
|
-
val decoded =
|
|
588
|
+
val json = person.toJson
|
|
589
|
+
val decoded = json.as[Person]
|
|
597
590
|
```
|
|
598
591
|
|
|
599
592
|
### Extension Syntax
|
|
@@ -631,14 +624,12 @@ These extension methods provide a more ergonomic API compared to explicitly crea
|
|
|
631
624
|
### Using the `as` Method
|
|
632
625
|
|
|
633
626
|
```scala
|
|
634
|
-
import zio.blocks.schema.
|
|
635
|
-
import zio.blocks.schema.json.
|
|
636
|
-
import zio.blocks.schema.{Schema, SchemaError}
|
|
627
|
+
import zio.blocks.schema._
|
|
628
|
+
import zio.blocks.schema.json._
|
|
637
629
|
|
|
638
630
|
case class Person(name: String, age: Int)
|
|
639
631
|
object Person {
|
|
640
632
|
implicit val schema: Schema[Person] = Schema.derived
|
|
641
|
-
implicit val decoder: JsonDecoder[Person] = JsonDecoder.fromSchema
|
|
642
633
|
}
|
|
643
634
|
|
|
644
635
|
val json = Json.parseUnsafe("""{"name": "Alice", "age": 30}""")
|
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.31"
|
|
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.31"
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
Supported Scala versions: 2.13.x and 3.x.
|
package/reference/modifier.md
CHANGED
|
@@ -38,9 +38,9 @@ object User extends CompanionOptics[User] {
|
|
|
38
38
|
.derived[User]
|
|
39
39
|
.modifier(Modifier.config("db.table-name", "users"))
|
|
40
40
|
|
|
41
|
-
implicit val jsonCodec:
|
|
41
|
+
implicit val jsonCodec: JsonCodec[User] =
|
|
42
42
|
schema
|
|
43
|
-
.deriving(
|
|
43
|
+
.deriving(JsonCodecDeriver)
|
|
44
44
|
.modifier(User.name, Modifier.rename("username"))
|
|
45
45
|
.modifier(User.cache, Modifier.transient())
|
|
46
46
|
.derive
|
|
@@ -86,9 +86,9 @@ object User extends CompanionOptics[User] {
|
|
|
86
86
|
implicit val schema: Schema[User] =
|
|
87
87
|
Schema.derived[User]
|
|
88
88
|
|
|
89
|
-
implicit val jsonCodec:
|
|
89
|
+
implicit val jsonCodec: JsonCodec[User] =
|
|
90
90
|
schema
|
|
91
|
-
.derive(
|
|
91
|
+
.derive(JsonCodecDeriver)
|
|
92
92
|
}
|
|
93
93
|
```
|
|
94
94
|
|
|
@@ -36,13 +36,13 @@ Without Resources, managing complex initialization and cleanup is tedious and er
|
|
|
36
36
|
Add the ZIO Blocks Scope module to your `build.sbt`:
|
|
37
37
|
|
|
38
38
|
```scala
|
|
39
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.
|
|
39
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.31"
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
For cross-platform (Scala.js):
|
|
43
43
|
|
|
44
44
|
```scala
|
|
45
|
-
libraryDependencies += "dev.zio" %%% "zio-blocks-scope" % "0.0.
|
|
45
|
+
libraryDependencies += "dev.zio" %%% "zio-blocks-scope" % "0.0.31"
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -55,7 +55,7 @@ If you've used `try/finally`, `Using`, or ZIO's `Scope`, this is the same proble
|
|
|
55
55
|
Add the following dependency to your `build.sbt`:
|
|
56
56
|
|
|
57
57
|
```scala
|
|
58
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.
|
|
58
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.31"
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
Supported Scala versions: **2.13.x** and **3.x**.
|
|
@@ -92,13 +92,13 @@ Scope.global.scoped { scope =>
|
|
|
92
92
|
Add the following dependency to your `build.sbt`:
|
|
93
93
|
|
|
94
94
|
```scala
|
|
95
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.
|
|
95
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.31"
|
|
96
96
|
```
|
|
97
97
|
|
|
98
98
|
For cross-platform (Scala.js):
|
|
99
99
|
|
|
100
100
|
```scala
|
|
101
|
-
libraryDependencies += "dev.zio" %%% "zio-blocks-scope" % "0.0.
|
|
101
|
+
libraryDependencies += "dev.zio" %%% "zio-blocks-scope" % "0.0.31"
|
|
102
102
|
```
|
|
103
103
|
|
|
104
104
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -535,6 +535,22 @@ cd zio-blocks
|
|
|
535
535
|
Basic wire construction demonstrates how to create and use `Wire` for dependency injection. View the example source code:
|
|
536
536
|
|
|
537
537
|
```scala title="scope-examples/src/main/scala/wire/WireBasicExample.scala"
|
|
538
|
+
/*
|
|
539
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
540
|
+
*
|
|
541
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
542
|
+
* you may not use this file except in compliance with the License.
|
|
543
|
+
* You may obtain a copy of the License at
|
|
544
|
+
*
|
|
545
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
546
|
+
*
|
|
547
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
548
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
549
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
550
|
+
* See the License for the specific language governing permissions and
|
|
551
|
+
* limitations under the License.
|
|
552
|
+
*/
|
|
553
|
+
|
|
538
554
|
package wire
|
|
539
555
|
|
|
540
556
|
import zio.blocks.scope._
|
|
@@ -638,6 +654,22 @@ sbt "scope-examples/runMain wire.wireBasicExample"
|
|
|
638
654
|
Comparing shared vs unique semantics shows how shared wires reuse the same instance across dependents, while unique wires create fresh instances. View the example:
|
|
639
655
|
|
|
640
656
|
```scala title="scope-examples/src/main/scala/wire/WireSharedUniqueExample.scala"
|
|
657
|
+
/*
|
|
658
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
659
|
+
*
|
|
660
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
661
|
+
* you may not use this file except in compliance with the License.
|
|
662
|
+
* You may obtain a copy of the License at
|
|
663
|
+
*
|
|
664
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
665
|
+
*
|
|
666
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
667
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
668
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
669
|
+
* See the License for the specific language governing permissions and
|
|
670
|
+
* limitations under the License.
|
|
671
|
+
*/
|
|
672
|
+
|
|
641
673
|
package wire
|
|
642
674
|
|
|
643
675
|
import zio.blocks.scope._
|
|
@@ -743,6 +775,22 @@ sbt "scope-examples/runMain wire.wireSharedUniqueExample"
|
|
|
743
775
|
Manual wire construction demonstrates how to use `fromFunction` for custom construction logic. View the example:
|
|
744
776
|
|
|
745
777
|
```scala title="scope-examples/src/main/scala/wire/WireFromFunctionExample.scala"
|
|
778
|
+
/*
|
|
779
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
780
|
+
*
|
|
781
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
782
|
+
* you may not use this file except in compliance with the License.
|
|
783
|
+
* You may obtain a copy of the License at
|
|
784
|
+
*
|
|
785
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
786
|
+
*
|
|
787
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
788
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
789
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
790
|
+
* See the License for the specific language governing permissions and
|
|
791
|
+
* limitations under the License.
|
|
792
|
+
*/
|
|
793
|
+
|
|
746
794
|
package wire
|
|
747
795
|
|
|
748
796
|
import zio.blocks.scope._
|
|
@@ -539,7 +539,6 @@ Path annotation (`atField`, `atIndex`, `atKey`, `atCase`) builds a [`DynamicOpti
|
|
|
539
539
|
```scala
|
|
540
540
|
import zio.blocks.schema.{DynamicOptic, DynamicValue, Schema, SchemaError}
|
|
541
541
|
|
|
542
|
-
implicit val intSchema: Schema[Int] = Schema[Int]
|
|
543
542
|
val data = DynamicValue.Sequence(DynamicValue.int(1), DynamicValue.int(2))
|
|
544
543
|
val optic = DynamicOptic.root.at(10)
|
|
545
544
|
|
|
@@ -39,13 +39,13 @@ The bidirectional data flow looks like this:
|
|
|
39
39
|
`As` is part of `zio-blocks-schema`:
|
|
40
40
|
|
|
41
41
|
```scala
|
|
42
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
42
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.31"
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
For Scala.js and Scala Native, use `%%%`:
|
|
46
46
|
|
|
47
47
|
```scala
|
|
48
|
-
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.
|
|
48
|
+
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.31"
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -240,7 +240,7 @@ trait As[A, B] {
|
|
|
240
240
|
|
|
241
241
|
```scala
|
|
242
242
|
val revAs: As[LongBox, IntBox] = boxAs.reverse
|
|
243
|
-
// revAs: As[LongBox, IntBox] = zio.blocks.schema.As$$anon$1@
|
|
243
|
+
// revAs: As[LongBox, IntBox] = zio.blocks.schema.As$$anon$1@70332401
|
|
244
244
|
|
|
245
245
|
revAs.into(LongBox(5L))
|
|
246
246
|
// res11: Either[SchemaError, IntBox] = Right(IntBox(5))
|
|
@@ -302,7 +302,7 @@ We import `As.reverseInto` and use it to obtain the reverse `Into[Int, String]`:
|
|
|
302
302
|
import As.reverseInto
|
|
303
303
|
|
|
304
304
|
val intToStr: Into[Int, String] = reverseInto[String, Int]
|
|
305
|
-
// intToStr: Into[Int, String] = zio.blocks.schema.AsLowPriorityImplicits$$Lambda$
|
|
305
|
+
// intToStr: Into[Int, String] = zio.blocks.schema.AsLowPriorityImplicits$$Lambda$17467/0x00007f7456961130@3a9535e3
|
|
306
306
|
intToStr.into(42)
|
|
307
307
|
// res14: Either[SchemaError, String] = Right("42")
|
|
308
308
|
```
|
|
@@ -69,13 +69,13 @@ Compare this to a manual implementation:
|
|
|
69
69
|
`Into` is part of the `zio-blocks-schema` module:
|
|
70
70
|
|
|
71
71
|
```scala
|
|
72
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
72
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.31"
|
|
73
73
|
```
|
|
74
74
|
|
|
75
75
|
For Scala.js:
|
|
76
76
|
|
|
77
77
|
```scala
|
|
78
|
-
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.
|
|
78
|
+
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.31"
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
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.31"
|
|
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.31"
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
Supported Scala versions: 2.13.x and 3.x.
|
package/reference/schema.md
CHANGED
|
@@ -173,8 +173,6 @@ ZIO Blocks provides specialized `Option` schemas optimized for primitive types.
|
|
|
173
173
|
```scala
|
|
174
174
|
import zio.blocks.schema.Schema
|
|
175
175
|
|
|
176
|
-
import zio.blocks.schema.Schema
|
|
177
|
-
|
|
178
176
|
// Specialized primitive options (no boxing overhead)
|
|
179
177
|
Schema[Option[Boolean]] // Also: Byte, Short, Int, Long, Float, Double, Char, Unit
|
|
180
178
|
```
|
|
@@ -193,12 +191,19 @@ Schema[Option[A]] // Generic option for reference types
|
|
|
193
191
|
ZIO Blocks also provides polymorphic schemas for standard Scala collections. You can summon schemas for collections of any element type `A` (and key/value types `K`/`V` for maps):
|
|
194
192
|
|
|
195
193
|
```scala
|
|
194
|
+
import zio.blocks.schema.Schema
|
|
195
|
+
|
|
196
|
+
// Built-in Scala collections
|
|
196
197
|
Schema[List[A]] // Immutable singly-linked list
|
|
197
198
|
Schema[Vector[A]] // Immutable indexed sequence (efficient random access)
|
|
198
199
|
Schema[Set[A]] // Immutable set (unique elements)
|
|
199
200
|
Schema[Seq[A]] // General immutable sequence
|
|
200
201
|
Schema[IndexedSeq[A]] // Indexed sequence
|
|
201
202
|
Schema[Map[K, V]] // Immutable key-value mapping
|
|
203
|
+
|
|
204
|
+
// ZIO Blocks collections (the chunk module)
|
|
205
|
+
Schema[zio.blocks.chunk.Chunk[A]] // Chunk sequence
|
|
206
|
+
Schema[zio.blocks.chunk.ChunkMap[K, V]] // ChunkMap key-value mapping
|
|
202
207
|
```
|
|
203
208
|
|
|
204
209
|
To learn how to create custom collection schemas, check out the [`Sequence`](./reflect.md#3-sequence) and [`Map`](./reflect.md#4-map) nodes on the documentation of [`Reflect`](./reflect.md) data type.
|
|
@@ -358,13 +363,13 @@ In the following example, we derive a JSON codec for the `Person` case class usi
|
|
|
358
363
|
|
|
359
364
|
```scala
|
|
360
365
|
import zio.blocks.schema.Schema
|
|
361
|
-
import zio.blocks.schema.json.{JsonFormat,
|
|
366
|
+
import zio.blocks.schema.json.{JsonFormat, JsonCodec}
|
|
362
367
|
|
|
363
368
|
case class Person(name: String, age: Int)
|
|
364
369
|
|
|
365
370
|
object Person {
|
|
366
371
|
implicit val schema: Schema[Person] = Schema.derived
|
|
367
|
-
val codec:
|
|
372
|
+
val codec: JsonCodec[Person] = schema.derive(JsonFormat)
|
|
368
373
|
}
|
|
369
374
|
|
|
370
375
|
val person = Person("John", 42)
|
|
@@ -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/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`
|