@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
|
@@ -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.33"
|
|
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.33"
|
|
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.33"
|
|
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.33"
|
|
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.33"
|
|
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.33"
|
|
44
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.33"
|
|
45
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.33"
|
|
46
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.33"
|
|
47
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.33"
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
Key points:
|
package/index.md
CHANGED
|
@@ -5,7 +5,7 @@ title: "ZIO Blocks"
|
|
|
5
5
|
|
|
6
6
|
**Modular, zero-dependency building blocks for modern Scala applications.**
|
|
7
7
|
|
|
8
|
-
[](https://github.com/zio/zio/wiki/Project-Stages)  [](https://github.com/zio/zio/wiki/Project-Stages)  [](https://github.com/zio/zio-blocks)
|
|
9
9
|
|
|
10
10
|
## What Is ZIO Blocks?
|
|
11
11
|
|
|
@@ -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.33"
|
|
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.33"
|
|
89
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.33"
|
|
90
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.33"
|
|
91
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.33"
|
|
92
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.33"
|
|
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.33"
|
|
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.33"
|
|
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.33"
|
|
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.33"
|
|
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.33"
|
|
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.33"
|
|
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 `JsonCodec[A]` or `
|
|
22
|
+
End users rarely interact with `Codec` directly. Instead, they work with format-specific subclasses like `JsonCodec[A]` or `ToonCodec[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
|
|
|
@@ -32,8 +32,8 @@ case class Person(name: String, age: Int)
|
|
|
32
32
|
object Person {
|
|
33
33
|
// Derive a schema for Person (required for codec derivation)
|
|
34
34
|
implicit val schema: Schema[Person] = Schema.derived
|
|
35
|
-
// Derive a JSON codec from the schema
|
|
36
|
-
|
|
35
|
+
// Derive a JSON codec from the schema
|
|
36
|
+
val codec: JsonCodec[Person] = schema.derive(JsonFormat)
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Encode
|
|
@@ -48,23 +48,26 @@ 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.33"
|
|
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-
|
|
59
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-
|
|
60
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-
|
|
61
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-
|
|
57
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.33"
|
|
58
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.33"
|
|
59
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-csv" % "0.0.33"
|
|
60
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.33"
|
|
61
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.33"
|
|
62
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.33"
|
|
63
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-xml" % "0.0.33"
|
|
64
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-yaml" % "0.0.33"
|
|
62
65
|
```
|
|
63
66
|
|
|
64
67
|
For cross-platform projects (Scala.js):
|
|
65
68
|
|
|
66
69
|
```scala
|
|
67
|
-
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.
|
|
70
|
+
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.33"
|
|
68
71
|
```
|
|
69
72
|
|
|
70
73
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -76,12 +79,15 @@ The codec system in ZIO Blocks is organized as a layered hierarchy:
|
|
|
76
79
|
```
|
|
77
80
|
Codec[DecodeInput, EncodeOutput, Value]
|
|
78
81
|
├── BinaryCodec[A] = Codec[ByteBuffer, ByteBuffer, A] (ByteBuffer ↔ A)
|
|
82
|
+
│ ├── AvroCodec[A]
|
|
79
83
|
│ ├── JsonCodec[A]
|
|
80
|
-
│ ├──
|
|
81
|
-
│ ├──
|
|
82
|
-
│ ├──
|
|
83
|
-
│
|
|
84
|
+
│ ├── MessagePackCodec[A]
|
|
85
|
+
│ ├── ThriftCodec[A]
|
|
86
|
+
│ ├── ToonCodec[A]
|
|
87
|
+
│ ├── XmlCodec[A]
|
|
88
|
+
│ └── YamlCodec[A]
|
|
84
89
|
└── TextCodec[A] = Codec[CharBuffer, CharBuffer, A] (CharBuffer ↔ A)
|
|
90
|
+
└── CsvCodec[A]
|
|
85
91
|
```
|
|
86
92
|
|
|
87
93
|
1. **`BinaryCodec[A]`** fixes both the input and output to `ByteBuffer` and is the base class for all codecs that operate on binary data:
|
|
@@ -207,7 +213,7 @@ Passing a `Deriver` directly is useful when working with custom or configured de
|
|
|
207
213
|
|
|
208
214
|
## Convenience Methods on Format-Specific Codecs
|
|
209
215
|
|
|
210
|
-
While the base `Codec` class defines only `encode(value, output)` and `decode(input)`, format-specific subclasses like `JsonCodec` and `
|
|
216
|
+
While the base `Codec` class defines only `encode(value, output)` and `decode(input)`, format-specific subclasses like `JsonCodec` and `ToonCodec` add convenience overloads for common I/O types.
|
|
211
217
|
|
|
212
218
|
### JsonCodec Convenience Methods
|
|
213
219
|
|
|
@@ -244,9 +250,9 @@ val is = new ByteArrayInputStream(os.toByteArray)
|
|
|
244
250
|
val fromStream: Either[SchemaError, Person] = codec.decode(is)
|
|
245
251
|
```
|
|
246
252
|
|
|
247
|
-
###
|
|
253
|
+
### ToonCodec Convenience Methods
|
|
248
254
|
|
|
249
|
-
`
|
|
255
|
+
`ToonCodec[A]` provides the same set of overloads:
|
|
250
256
|
|
|
251
257
|
```scala
|
|
252
258
|
import zio.blocks.schema._
|
|
@@ -348,7 +354,7 @@ object Person {
|
|
|
348
354
|
implicit val schema: Schema[Person] = Schema.derived
|
|
349
355
|
}
|
|
350
356
|
|
|
351
|
-
val customDeriver =
|
|
357
|
+
val customDeriver = ToonCodecDeriver
|
|
352
358
|
.withFieldNameMapper(NameMapper.SnakeCase)
|
|
353
359
|
.withArrayFormat(ArrayFormat.Tabular)
|
|
354
360
|
.withDiscriminatorKind(DiscriminatorKind.Field("type"))
|
|
@@ -365,11 +371,13 @@ import zio.blocks.schema._
|
|
|
365
371
|
import zio.blocks.schema.json._
|
|
366
372
|
|
|
367
373
|
case class Address(street: String, city: String)
|
|
368
|
-
case class Person(name: String, address: Address)
|
|
369
374
|
|
|
370
375
|
object Address {
|
|
371
376
|
implicit val schema: Schema[Address] = Schema.derived
|
|
372
377
|
}
|
|
378
|
+
|
|
379
|
+
case class Person(name: String, address: Address)
|
|
380
|
+
|
|
373
381
|
object Person {
|
|
374
382
|
implicit val schema: Schema[Person] = Schema.derived
|
|
375
383
|
}
|
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.33"
|
|
120
120
|
```
|
|
121
121
|
|
|
122
122
|
## Construction
|
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.33"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Core Types
|
|
@@ -77,13 +77,13 @@ We can inspect the schema's structure by printing it:
|
|
|
77
77
|
dynamic
|
|
78
78
|
// res1: DynamicSchema = DynamicSchema(
|
|
79
79
|
// Record(
|
|
80
|
-
// fields =
|
|
80
|
+
// fields = IndexedSeq(
|
|
81
81
|
// Term(
|
|
82
82
|
// name = "name",
|
|
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@5ca5d848,
|
|
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@5ca5d848,
|
|
101
101
|
// doc = Doc(blocks = IndexedSeq(), metadata = Map()),
|
|
102
102
|
// modifiers = List(),
|
|
103
103
|
// storedDefaultValue = None,
|
|
@@ -109,13 +109,13 @@ dynamic
|
|
|
109
109
|
// Term(
|
|
110
110
|
// name = "address",
|
|
111
111
|
// value = Record(
|
|
112
|
-
// fields =
|
|
112
|
+
// fields = IndexedSeq(
|
|
113
113
|
// Term(
|
|
114
114
|
// name = "street",
|
|
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@5ca5d848,
|
|
119
119
|
// doc = Doc(blocks = IndexedSeq(), metadata = Map()),
|
|
120
120
|
// modifiers = List(),
|
|
121
121
|
// storedDefaultValue = None,
|
|
@@ -232,7 +232,7 @@ dynSchema.check(valid)
|
|
|
232
232
|
dynSchema.check(missing)
|
|
233
233
|
// res8: Option[SchemaError] = Some(
|
|
234
234
|
// SchemaError(
|
|
235
|
-
// List(MissingField(source = DynamicOptic(
|
|
235
|
+
// List(MissingField(source = DynamicOptic(IndexedSeq()), fieldName = "y"))
|
|
236
236
|
// )
|
|
237
237
|
// )
|
|
238
238
|
dynSchema.check(wrongType)
|
|
@@ -240,7 +240,7 @@ dynSchema.check(wrongType)
|
|
|
240
240
|
// SchemaError(
|
|
241
241
|
// List(
|
|
242
242
|
// ExpectationMismatch(
|
|
243
|
-
// source = DynamicOptic(
|
|
243
|
+
// source = DynamicOptic(IndexedSeq(Field("y"))),
|
|
244
244
|
// expectation = "Expected Int, got String"
|
|
245
245
|
// )
|
|
246
246
|
// )
|
package/reference/formats.md
CHANGED
|
@@ -44,13 +44,17 @@ object JsonFormat extends BinaryFormat("application/json", JsonCodecDeriver)
|
|
|
44
44
|
|
|
45
45
|
Here's a summary of the formats currently supported by ZIO Blocks. Each format provides a `BinaryFormat` object that can be passed to `derive`:
|
|
46
46
|
|
|
47
|
-
| Format Object | Codec Type
|
|
48
|
-
|
|
49
|
-
| `JsonFormat` | `JsonCodec[A]`
|
|
50
|
-
| `
|
|
51
|
-
| `
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
47
|
+
| Format Object | Codec Type | MIME Type | Module |
|
|
48
|
+
|---------------------|-----------------------|-----------------------|---------------------------------|
|
|
49
|
+
| `JsonFormat` | `JsonCodec[A]` | `application/json` | `zio-blocks-schema` |
|
|
50
|
+
| `AvroFormat` | `AvroCodec[A]` | `application/avro` | `zio-blocks-schema-avro` |
|
|
51
|
+
| `BsonFormat` | `BsonCodec[A]` | `application/bson` | `zio-blocks-schema-bson` |
|
|
52
|
+
| `CsvFormat` | `CsvCodec[A]` | `text/csv` | `zio-blocks-schema-csv` |
|
|
53
|
+
| `MessagePackFormat` | `MessagePackCodec[A]` | `application/msgpack` | `zio-blocks-schema-messagepack` |
|
|
54
|
+
| `ThriftFormat` | `ThriftCodec[A]` | `application/thrift` | `zio-blocks-schema-thrift` |
|
|
55
|
+
| `ToonFormat` | `ToonCodec[A]` | `text/toon` | `zio-blocks-schema-toon` |
|
|
56
|
+
| `XmlFormat` | `XmlCodec[A]` | `application/xml` | `zio-blocks-schema-xml` |
|
|
57
|
+
| `YamlFormat` | `YamlCodec[A]` | `application/yaml` | `zio-blocks-schema-yaml` |
|
|
54
58
|
|
|
55
59
|
## Defining a Custom Format
|
|
56
60
|
|
|
@@ -162,7 +166,7 @@ val decoded: Either[SchemaError, Person] = codec.decode(bytes)
|
|
|
162
166
|
|
|
163
167
|
### Avro Schema Generation
|
|
164
168
|
|
|
165
|
-
Each `
|
|
169
|
+
Each `AvroCodec` exposes an `avroSchema` property containing the Apache Avro schema:
|
|
166
170
|
|
|
167
171
|
```scala
|
|
168
172
|
import zio.blocks.schema._
|
|
@@ -308,7 +312,7 @@ orders[2]{id,total}:
|
|
|
308
312
|
|
|
309
313
|
### Configuration Options
|
|
310
314
|
|
|
311
|
-
The `
|
|
315
|
+
The `ToonCodecDeriver` provides extensive configuration:
|
|
312
316
|
|
|
313
317
|
```scala
|
|
314
318
|
import zio.blocks.schema._
|
|
@@ -320,7 +324,7 @@ object Person {
|
|
|
320
324
|
}
|
|
321
325
|
|
|
322
326
|
// Custom deriver with snake_case field names
|
|
323
|
-
val customDeriver =
|
|
327
|
+
val customDeriver = ToonCodecDeriver
|
|
324
328
|
.withFieldNameMapper(NameMapper.SnakeCase)
|
|
325
329
|
.withArrayFormat(ArrayFormat.Tabular)
|
|
326
330
|
.withDiscriminatorKind(DiscriminatorKind.Field("type"))
|
|
@@ -362,7 +366,7 @@ val keyCodec = Schema[Shape].derive(ToonFormat)
|
|
|
362
366
|
// radius: 5
|
|
363
367
|
|
|
364
368
|
// Field discriminator
|
|
365
|
-
val fieldDeriver =
|
|
369
|
+
val fieldDeriver = ToonCodecDeriver
|
|
366
370
|
.withDiscriminatorKind(DiscriminatorKind.Field("type"))
|
|
367
371
|
val fieldCodec = Schema[Shape].derive(fieldDeriver)
|
|
368
372
|
// type: Circle
|
package/reference/json-patch.md
CHANGED
|
@@ -386,7 +386,7 @@ modeJson.patch(modePatch, PatchMode.Strict)
|
|
|
386
386
|
// SchemaError(
|
|
387
387
|
// List(
|
|
388
388
|
// ExpectationMismatch(
|
|
389
|
-
// source = DynamicOptic(
|
|
389
|
+
// source = DynamicOptic(IndexedSeq()),
|
|
390
390
|
// expectation = "Key 'a' already exists in object"
|
|
391
391
|
// )
|
|
392
392
|
// )
|
|
@@ -723,7 +723,7 @@ fieldPatch.apply(doc)
|
|
|
723
723
|
// res40: Either[SchemaError, Json] = Left(
|
|
724
724
|
// SchemaError(
|
|
725
725
|
// List(
|
|
726
|
-
// MissingField(source = DynamicOptic(
|
|
726
|
+
// MissingField(source = DynamicOptic(IndexedSeq()), fieldName = "updatedAt")
|
|
727
727
|
// )
|
|
728
728
|
// )
|
|
729
729
|
// )
|
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.33"
|
|
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.33"
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -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.33"
|
|
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.33"
|
|
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.33"
|
|
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.33"
|
|
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.33"
|
|
102
102
|
```
|
|
103
103
|
|
|
104
104
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -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.33"
|
|
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.33"
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -89,7 +89,7 @@ manualAs.from(Long.MaxValue)
|
|
|
89
89
|
// SchemaError(
|
|
90
90
|
// List(
|
|
91
91
|
// ConversionFailed(
|
|
92
|
-
// source = DynamicOptic(
|
|
92
|
+
// source = DynamicOptic(IndexedSeq()),
|
|
93
93
|
// details = "overflow",
|
|
94
94
|
// cause = None
|
|
95
95
|
// )
|
|
@@ -213,7 +213,7 @@ boxAs.from(LongBox(Long.MaxValue))
|
|
|
213
213
|
// SchemaError(
|
|
214
214
|
// List(
|
|
215
215
|
// ConversionFailed(
|
|
216
|
-
// source = DynamicOptic(
|
|
216
|
+
// source = DynamicOptic(IndexedSeq()),
|
|
217
217
|
// details = "Value 9223372036854775807 is out of range for Int [-2147483648, 2147483647]",
|
|
218
218
|
// cause = None
|
|
219
219
|
// )
|
|
@@ -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@6145661b
|
|
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$17549/0x00007faac29bf110@e1a6316
|
|
306
306
|
intToStr.into(42)
|
|
307
307
|
// res14: Either[SchemaError, String] = Right("42")
|
|
308
308
|
```
|
|
@@ -387,7 +387,7 @@ numericAs.from(LongModel(Long.MaxValue))
|
|
|
387
387
|
// SchemaError(
|
|
388
388
|
// List(
|
|
389
389
|
// ConversionFailed(
|
|
390
|
-
// source = DynamicOptic(
|
|
390
|
+
// source = DynamicOptic(IndexedSeq()),
|
|
391
391
|
// details = "Value 9223372036854775807 is out of range for Int [-2147483648, 2147483647]",
|
|
392
392
|
// cause = None
|
|
393
393
|
// )
|
|
@@ -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.33"
|
|
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.33"
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -241,7 +241,7 @@ Into[Long, Int].into(Long.MaxValue)
|
|
|
241
241
|
// SchemaError(
|
|
242
242
|
// List(
|
|
243
243
|
// ConversionFailed(
|
|
244
|
-
// source = DynamicOptic(
|
|
244
|
+
// source = DynamicOptic(IndexedSeq()),
|
|
245
245
|
// details = "Value 9223372036854775807 is out of range for Int [-2147483648, 2147483647]",
|
|
246
246
|
// cause = None
|
|
247
247
|
// )
|
|
@@ -253,7 +253,7 @@ Into[Double, Int].into(3.14)
|
|
|
253
253
|
// SchemaError(
|
|
254
254
|
// List(
|
|
255
255
|
// ConversionFailed(
|
|
256
|
-
// source = DynamicOptic(
|
|
256
|
+
// source = DynamicOptic(IndexedSeq()),
|
|
257
257
|
// details = "Value 3.14 cannot be precisely converted to Int",
|
|
258
258
|
// cause = None
|
|
259
259
|
// )
|
|
@@ -399,7 +399,7 @@ conv.into(Raw(Long.MaxValue))
|
|
|
399
399
|
// SchemaError(
|
|
400
400
|
// List(
|
|
401
401
|
// ConversionFailed(
|
|
402
|
-
// source = DynamicOptic(
|
|
402
|
+
// source = DynamicOptic(IndexedSeq()),
|
|
403
403
|
// details = "Value 9223372036854775807 is out of range for Int [-2147483648, 2147483647]",
|
|
404
404
|
// cause = None
|
|
405
405
|
// )
|
|
@@ -623,7 +623,7 @@ validate.into(PersonRaw("Bob", 200))
|
|
|
623
623
|
// SchemaError(
|
|
624
624
|
// List(
|
|
625
625
|
// ConversionFailed(
|
|
626
|
-
// source = DynamicOptic(
|
|
626
|
+
// source = DynamicOptic(IndexedSeq()),
|
|
627
627
|
// details = "Validation failed for field 'age': NonEmptyChunk(200 did not satisfy between(0, 150))",
|
|
628
628
|
// cause = None
|
|
629
629
|
// )
|
|
@@ -854,7 +854,7 @@ result
|
|
|
854
854
|
// SchemaError(
|
|
855
855
|
// List(
|
|
856
856
|
// ExpectationMismatch(
|
|
857
|
-
// source = DynamicOptic(
|
|
857
|
+
// source = DynamicOptic(IndexedSeq()),
|
|
858
858
|
// expectation = "Expected a record"
|
|
859
859
|
// )
|
|
860
860
|
// )
|
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.33"
|
|
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.33"
|
|
80
80
|
```
|
|
81
81
|
|
|
82
82
|
Supported Scala versions: 2.13.x and 3.x.
|
package/reference/schema.md
CHANGED
|
@@ -588,7 +588,7 @@ ZIO Blocks provides the `transform` method for creating schemas for wrapper type
|
|
|
588
588
|
|
|
589
589
|
```scala
|
|
590
590
|
final case class Schema[A](reflect: Reflect.Bound[A]) {
|
|
591
|
-
def transform[B](to: A => B, from: B => A): Schema[B] = ???
|
|
591
|
+
def transform[B](to: A => B, from: B => A)(implicit typeId: TypeId[B]): Schema[B] = ???
|
|
592
592
|
}
|
|
593
593
|
```
|
|
594
594
|
|