@zio.dev/zio-blocks 0.0.1 → 0.0.21
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/index.md +143 -15
- package/package.json +5 -2
- package/reference/binding.md +8 -14
- package/reference/chunk.md +36 -36
- package/reference/docs.md +2 -2
- package/reference/dynamic-value.md +34 -34
- package/reference/formats.md +16 -16
- package/reference/json-schema.md +20 -20
- package/reference/json.md +47 -47
- package/reference/optics.md +51 -37
- package/reference/reflect.md +3 -3
- package/reference/registers.md +7 -7
- package/reference/schema.md +18 -18
- package/reference/syntax.md +16 -16
- package/scope.md +481 -161
- package/reference/modifier.md +0 -276
- package/reference/reflect-transform.md +0 -387
- package/reference/type-class-derivation-internals.md +0 -632
package/reference/syntax.md
CHANGED
|
@@ -9,7 +9,7 @@ ZIO Blocks provides convenient extension methods on any value that has a `Schema
|
|
|
9
9
|
|
|
10
10
|
To use the extension syntax, import the schema package:
|
|
11
11
|
|
|
12
|
-
```scala
|
|
12
|
+
```scala
|
|
13
13
|
import zio.blocks.schema._
|
|
14
14
|
```
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ This brings the extension methods into scope for any type with an implicit `Sche
|
|
|
17
17
|
|
|
18
18
|
## Quick Example
|
|
19
19
|
|
|
20
|
-
```scala
|
|
20
|
+
```scala
|
|
21
21
|
import zio.blocks.schema._
|
|
22
22
|
|
|
23
23
|
case class Person(name: String, age: Int)
|
|
@@ -51,7 +51,7 @@ val result = alice.applyPatch(patch) // Person("Bob", 30)
|
|
|
51
51
|
|
|
52
52
|
Converts a value to a `Json` AST (abstract syntax tree):
|
|
53
53
|
|
|
54
|
-
```scala
|
|
54
|
+
```scala
|
|
55
55
|
import zio.blocks.schema._
|
|
56
56
|
|
|
57
57
|
case class Point(x: Int, y: Int)
|
|
@@ -72,7 +72,7 @@ json.get("y").as[Int] // Right(20)
|
|
|
72
72
|
|
|
73
73
|
Converts a value directly to a JSON string:
|
|
74
74
|
|
|
75
|
-
```scala
|
|
75
|
+
```scala
|
|
76
76
|
import zio.blocks.schema._
|
|
77
77
|
|
|
78
78
|
case class User(name: String, email: String)
|
|
@@ -89,7 +89,7 @@ val jsonStr = user.toJsonString
|
|
|
89
89
|
|
|
90
90
|
Converts a value to a UTF-8 encoded byte array. This is useful for efficient serialization when working with binary protocols or network I/O:
|
|
91
91
|
|
|
92
|
-
```scala
|
|
92
|
+
```scala
|
|
93
93
|
import zio.blocks.schema._
|
|
94
94
|
|
|
95
95
|
case class Message(id: Long, content: String)
|
|
@@ -110,7 +110,7 @@ val bytes: Array[Byte] = msg.toJsonBytes
|
|
|
110
110
|
|
|
111
111
|
Parses a JSON string into a typed value:
|
|
112
112
|
|
|
113
|
-
```scala
|
|
113
|
+
```scala
|
|
114
114
|
import zio.blocks.schema._
|
|
115
115
|
|
|
116
116
|
case class Config(host: String, port: Int)
|
|
@@ -132,7 +132,7 @@ val error = invalid.fromJson[Config]
|
|
|
132
132
|
|
|
133
133
|
Parses a UTF-8 byte array into a typed value:
|
|
134
134
|
|
|
135
|
-
```scala
|
|
135
|
+
```scala
|
|
136
136
|
import zio.blocks.schema._
|
|
137
137
|
import java.nio.charset.StandardCharsets
|
|
138
138
|
|
|
@@ -154,7 +154,7 @@ val result: Either[SchemaError, Event] = jsonBytes.fromJson[Event]
|
|
|
154
154
|
|
|
155
155
|
Converts a value to a human-readable string representation using `DynamicValue`:
|
|
156
156
|
|
|
157
|
-
```scala
|
|
157
|
+
```scala
|
|
158
158
|
import zio.blocks.schema._
|
|
159
159
|
|
|
160
160
|
case class Address(street: String, city: String, zip: String)
|
|
@@ -177,7 +177,7 @@ ZIO Blocks includes a powerful patching system for computing and applying differ
|
|
|
177
177
|
|
|
178
178
|
Computes the difference between two values, returning a `Patch`:
|
|
179
179
|
|
|
180
|
-
```scala
|
|
180
|
+
```scala
|
|
181
181
|
import zio.blocks.schema._
|
|
182
182
|
|
|
183
183
|
case class Product(name: String, price: Double, stock: Int)
|
|
@@ -196,7 +196,7 @@ patch.isEmpty // false
|
|
|
196
196
|
|
|
197
197
|
An identical comparison produces an empty patch:
|
|
198
198
|
|
|
199
|
-
```scala
|
|
199
|
+
```scala
|
|
200
200
|
import zio.blocks.schema._
|
|
201
201
|
|
|
202
202
|
case class Item(id: Int, name: String)
|
|
@@ -213,7 +213,7 @@ samePatch.isEmpty // true
|
|
|
213
213
|
|
|
214
214
|
Applies a patch to a value, returning the modified value. Uses lenient mode by default, which means operations that can't be applied are silently skipped:
|
|
215
215
|
|
|
216
|
-
```scala
|
|
216
|
+
```scala
|
|
217
217
|
import zio.blocks.schema._
|
|
218
218
|
|
|
219
219
|
case class Counter(name: String, value: Int)
|
|
@@ -233,7 +233,7 @@ val result = counter.applyPatch(patch)
|
|
|
233
233
|
|
|
234
234
|
Applies a patch strictly, returning an `Either` that contains an error if any operation fails:
|
|
235
235
|
|
|
236
|
-
```scala
|
|
236
|
+
```scala
|
|
237
237
|
import zio.blocks.schema._
|
|
238
238
|
import zio.blocks.schema.patch.Patch
|
|
239
239
|
|
|
@@ -258,7 +258,7 @@ val emptyResult = record.applyPatchStrict(Patch.empty[Record])
|
|
|
258
258
|
|
|
259
259
|
### JSON Roundtrip
|
|
260
260
|
|
|
261
|
-
```scala
|
|
261
|
+
```scala
|
|
262
262
|
import zio.blocks.schema._
|
|
263
263
|
|
|
264
264
|
case class Order(id: Long, items: List[String], total: BigDecimal)
|
|
@@ -281,7 +281,7 @@ val decoded2 = jsonBytes.fromJson[Order]
|
|
|
281
281
|
|
|
282
282
|
### Patch Roundtrip
|
|
283
283
|
|
|
284
|
-
```scala
|
|
284
|
+
```scala
|
|
285
285
|
import zio.blocks.schema._
|
|
286
286
|
|
|
287
287
|
case class Settings(theme: String, fontSize: Int, notifications: Boolean)
|
|
@@ -306,7 +306,7 @@ assert(result == customized)
|
|
|
306
306
|
|
|
307
307
|
The JSON encoding handles special characters, Unicode, and escape sequences correctly:
|
|
308
308
|
|
|
309
|
-
```scala
|
|
309
|
+
```scala
|
|
310
310
|
import zio.blocks.schema._
|
|
311
311
|
|
|
312
312
|
case class Text(content: String)
|
|
@@ -329,7 +329,7 @@ val decoded2 = json2.fromJson[Text]
|
|
|
329
329
|
|
|
330
330
|
### Empty and Null Values
|
|
331
331
|
|
|
332
|
-
```scala
|
|
332
|
+
```scala
|
|
333
333
|
import zio.blocks.schema._
|
|
334
334
|
|
|
335
335
|
case class Profile(name: String, bio: Option[String])
|