@zio.dev/zio-blocks 0.0.28 → 0.0.29
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 +62 -16
- package/package.json +1 -1
- package/path-interpolator.md +70 -9
- package/reference/allows.md +96 -0
- package/reference/codec.md +8 -8
- package/reference/combinators.md +345 -0
- package/reference/context.md +639 -67
- package/reference/docs.md +1 -1
- package/reference/http-model.md +1716 -0
- package/reference/json-differ.md +320 -0
- package/reference/json-patch.md +1 -1
- package/reference/media-type.md +2 -2
- package/reference/resource-management-di/index.md +49 -0
- package/reference/resource-management-di/resource.md +1125 -0
- package/{scope.md → reference/resource-management-di/scope.md} +1 -1
- package/reference/resource-management-di/wire.md +832 -0
- 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/type-class-derivation.md +31 -31
- package/ringbuffer.md +249 -0
- package/sidebars.js +14 -2
|
@@ -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.29"
|
|
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.29"
|
|
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.29"
|
|
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.29"
|
|
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.29"
|
|
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.29"
|
|
44
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.29"
|
|
45
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.29"
|
|
46
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.29"
|
|
47
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.29"
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
Key points:
|
package/index.md
CHANGED
|
@@ -24,6 +24,7 @@ The philosophy is simple: **use what you need, nothing more**. Each block is ind
|
|
|
24
24
|
| **TypeId** | Compile-time type identity with rich metadata | ✅ Available |
|
|
25
25
|
| **Context** | Type-indexed heterogeneous collections | ✅ Available |
|
|
26
26
|
| **MediaType** | Type-safe IANA media types with 2,600+ predefined types | ✅ Available |
|
|
27
|
+
| **Ring Buffer** | High-performance bounded ring buffers (SPSC, MPSC, SPMC, MPMC) | ✅ Available |
|
|
27
28
|
| **Streams** | Pull-based streaming primitives | 🚧 In Development |
|
|
28
29
|
|
|
29
30
|
## Core Principles
|
|
@@ -81,14 +82,14 @@ val thriftCodec = Schema[Person].derive(ThriftFormat) // Thrift
|
|
|
81
82
|
### Installation
|
|
82
83
|
|
|
83
84
|
```scala
|
|
84
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
85
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.29"
|
|
85
86
|
|
|
86
87
|
// Optional format modules:
|
|
87
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.
|
|
88
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.
|
|
89
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.
|
|
90
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.
|
|
91
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.
|
|
88
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.29"
|
|
89
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.29"
|
|
90
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.29"
|
|
91
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.29"
|
|
92
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.29"
|
|
92
93
|
```
|
|
93
94
|
|
|
94
95
|
### Example: Optics
|
|
@@ -143,7 +144,7 @@ Chunk is designed for:
|
|
|
143
144
|
### Installation
|
|
144
145
|
|
|
145
146
|
```scala
|
|
146
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-chunk" % "0.0.
|
|
147
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-chunk" % "0.0.29"
|
|
147
148
|
```
|
|
148
149
|
|
|
149
150
|
### Example
|
|
@@ -232,7 +233,7 @@ Scope.global.scoped { scope =>
|
|
|
232
233
|
### Installation
|
|
233
234
|
|
|
234
235
|
```scala
|
|
235
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.
|
|
236
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.29"
|
|
236
237
|
```
|
|
237
238
|
|
|
238
239
|
### Example: Basic Resource Management
|
|
@@ -335,7 +336,7 @@ Generating documentation, README files, or any Markdown content programmatically
|
|
|
335
336
|
### Installation
|
|
336
337
|
|
|
337
338
|
```scala
|
|
338
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.
|
|
339
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.29"
|
|
339
340
|
```
|
|
340
341
|
|
|
341
342
|
### Example
|
|
@@ -419,7 +420,7 @@ Compile-time type identity with rich metadata. TypeId captures comprehensive inf
|
|
|
419
420
|
### Installation
|
|
420
421
|
|
|
421
422
|
```scala
|
|
422
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-typeid" % "0.0.
|
|
423
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-typeid" % "0.0.29"
|
|
423
424
|
```
|
|
424
425
|
|
|
425
426
|
### Example
|
|
@@ -462,7 +463,7 @@ A type-indexed heterogeneous collection that stores values by their types with c
|
|
|
462
463
|
### Installation
|
|
463
464
|
|
|
464
465
|
```scala
|
|
465
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-context" % "0.0.
|
|
466
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-context" % "0.0.29"
|
|
466
467
|
```
|
|
467
468
|
|
|
468
469
|
### Example
|
|
@@ -494,6 +495,47 @@ val merged: Context[Config & Metrics] = ctx1 ++ ctx2
|
|
|
494
495
|
|
|
495
496
|
---
|
|
496
497
|
|
|
498
|
+
## Ring Buffer
|
|
499
|
+
|
|
500
|
+
High-performance, bounded ring buffers for inter-thread communication. Four lock-free variants cover every producer/consumer pattern (SPSC, MPSC, SPMC, MPMC).
|
|
501
|
+
|
|
502
|
+
### Why Ring Buffer?
|
|
503
|
+
|
|
504
|
+
Standard `java.util.concurrent` queues use node allocation (`ConcurrentLinkedQueue`) or coarse locking (`ArrayBlockingQueue`). Ring buffers avoid both:
|
|
505
|
+
|
|
506
|
+
- **Zero allocation** on the hot path—pre-allocated circular array
|
|
507
|
+
- **Lock-free** on the fast path—CAS or release/acquire semantics only
|
|
508
|
+
- **Cache-friendly**—sequential memory access with 128-byte padding between producer/consumer fields
|
|
509
|
+
|
|
510
|
+
### Key Features
|
|
511
|
+
|
|
512
|
+
- **Four concurrency patterns**: SPSC, SPMC, MPSC, MPMC—pick the most constrained variant for your use case
|
|
513
|
+
- **Cross-platform**: Same API on JVM and Scala.js (JS uses sequential implementations)
|
|
514
|
+
|
|
515
|
+
### Installation
|
|
516
|
+
|
|
517
|
+
```scala
|
|
518
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-ringbuffer" % "0.0.29"
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
### Example
|
|
522
|
+
|
|
523
|
+
```scala
|
|
524
|
+
import zio.blocks.ringbuffer._
|
|
525
|
+
|
|
526
|
+
// SPSC: fastest, for dedicated producer-consumer pairs
|
|
527
|
+
val spsc = SpscRingBuffer[String](1024)
|
|
528
|
+
spsc.offer("hello") // true
|
|
529
|
+
spsc.take() // "hello"
|
|
530
|
+
|
|
531
|
+
// MPMC: general-purpose, any number of threads
|
|
532
|
+
val mpmc = MpmcRingBuffer[String](1024)
|
|
533
|
+
mpmc.offer("hello") // false if full
|
|
534
|
+
mpmc.take() // null if empty
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
---
|
|
538
|
+
|
|
497
539
|
## Streams (In Development)
|
|
498
540
|
|
|
499
541
|
A pull-based streaming library for composable, backpressure-aware data processing.
|
|
@@ -526,10 +568,10 @@ Each block has zero dependencies on effect systems. Use the blocks directly, or
|
|
|
526
568
|
|
|
527
569
|
ZIO Blocks supports **Scala 2.13** and **Scala 3.x** with full source compatibility. Write your code once and compile it against either version—migrate to Scala 3 when your team is ready, not when your dependencies force you.
|
|
528
570
|
|
|
529
|
-
| Platform | Schema | Chunk | Scope | Docs | TypeId | Context | Streams |
|
|
530
|
-
|
|
531
|
-
| JVM | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
532
|
-
| Scala.js | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
571
|
+
| Platform | Schema | Chunk | Scope | Docs | TypeId | Context | Ring Buffer | Streams |
|
|
572
|
+
|----------|--------|-------|-------|------|--------|---------|-------------|---------|
|
|
573
|
+
| JVM | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
574
|
+
| Scala.js | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
533
575
|
|
|
534
576
|
## Documentation
|
|
535
577
|
|
|
@@ -555,6 +597,7 @@ ZIO Blocks supports **Scala 2.13** and **Scala 3.x** with full source compatibil
|
|
|
555
597
|
- [Codec & Format](./reference/codec.md) - Codec, Format, BinaryCodec & TextCodec
|
|
556
598
|
- [JSON](./reference/json.md) - JSON codec and parsing
|
|
557
599
|
- [JsonPatch](./reference/json-patch.md) - Diff and patch JSON values
|
|
600
|
+
- [JsonDiffer](./reference/json-differ.md) - Compute minimal diffs between JSON values
|
|
558
601
|
- [JSON Schema](./reference/json-schema.md) - JSON Schema generation and validation
|
|
559
602
|
- [Formats](./reference/formats.md) - Avro, TOON, MessagePack, BSON, Thrift
|
|
560
603
|
- [Extension Syntax](./reference/syntax.md) - `.toJson`, `.fromJson`, and more
|
|
@@ -571,11 +614,14 @@ ZIO Blocks supports **Scala 2.13** and **Scala 3.x** with full source compatibil
|
|
|
571
614
|
### Other Blocks
|
|
572
615
|
|
|
573
616
|
- [Chunk](./reference/chunk.md) - High-performance immutable sequences
|
|
574
|
-
- [Scope](./scope.md) - Compile-time safe resource management and DI
|
|
617
|
+
- [Scope](./reference/resource-management-di/scope.md) - Compile-time safe resource management and DI
|
|
618
|
+
- [Wire](./reference/resource-management-di/wire.md) - Recipes for constructing services and dependencies
|
|
575
619
|
- [TypeId](./reference/typeid.md) - Type identity and metadata
|
|
576
620
|
- [Context](./reference/context.md) - Type-indexed heterogeneous collections
|
|
577
621
|
- [Docs (Markdown)](./reference/docs.md) - Markdown parsing and rendering
|
|
578
622
|
- [MediaType](./reference/media-type.md) - Type-safe IANA media types
|
|
623
|
+
- [HTTP Model](./reference/http-model.md) - Pure HTTP data model with URL parsing, headers, cookies, and forms
|
|
624
|
+
- [Ring Buffer](./ringbuffer.md) - High-performance bounded ring buffers
|
|
579
625
|
|
|
580
626
|
### Guides
|
|
581
627
|
|
package/package.json
CHANGED
package/path-interpolator.md
CHANGED
|
@@ -212,6 +212,65 @@ p"<café>" // Unicode case names
|
|
|
212
212
|
p"<A><B><C>" // Nested variants
|
|
213
213
|
```
|
|
214
214
|
|
|
215
|
+
### Schema Search
|
|
216
|
+
|
|
217
|
+
Search for values matching a schema pattern anywhere in a data structure using the `#` prefix.
|
|
218
|
+
|
|
219
|
+
**Nominal types:**
|
|
220
|
+
|
|
221
|
+
```scala
|
|
222
|
+
p"#Person" // Find all values of type Person
|
|
223
|
+
p"#User" // Find all values of type User
|
|
224
|
+
p"#Address" // Find all values of type Address
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
**Primitive types:**
|
|
228
|
+
|
|
229
|
+
```scala
|
|
230
|
+
p"#string" // Find all string values
|
|
231
|
+
p"#int" // Find all integer values
|
|
232
|
+
p"#boolean" // Find all boolean values
|
|
233
|
+
p"#uuid" // Find all UUID values
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Structural records:**
|
|
237
|
+
|
|
238
|
+
```scala
|
|
239
|
+
p"#record { name: string }" // Find records with a string 'name' field
|
|
240
|
+
p"#record { name: string, age: int }" // Find records with both fields
|
|
241
|
+
p"#record { items: list(Person) }" // Nested schema
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**Structural variants:**
|
|
245
|
+
|
|
246
|
+
```scala
|
|
247
|
+
p"#variant { Left: int, Right: string }" // Find Either-like variants
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**Collections:**
|
|
251
|
+
|
|
252
|
+
```scala
|
|
253
|
+
p"#list(string)" // Find lists of strings
|
|
254
|
+
p"#list(Person)" // Find lists of Person
|
|
255
|
+
p"#map(string, int)" // Find maps from string to int
|
|
256
|
+
p"#option(Person)" // Find optional Person values
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
**Wildcard:**
|
|
260
|
+
|
|
261
|
+
```scala
|
|
262
|
+
p"#_" // Find any value (matches everything)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Combined paths with search:**
|
|
266
|
+
|
|
267
|
+
```scala
|
|
268
|
+
p".users#Person" // Search for Person in users field
|
|
269
|
+
p"#Person.name" // Find all Person values, then get name
|
|
270
|
+
p".items[*]#Person.email" // Elements then search then field
|
|
271
|
+
p"#list(Person)#Person" // Chained searches
|
|
272
|
+
```
|
|
273
|
+
|
|
215
274
|
## Escape Sequences
|
|
216
275
|
|
|
217
276
|
String and character literals support standard escape sequences:
|
|
@@ -623,15 +682,17 @@ val same = p".users[*].email"
|
|
|
623
682
|
|------------------------------------------------------|-------------------|
|
|
624
683
|
| `DynamicOptic.root.field("name")` | `.name` |
|
|
625
684
|
| `DynamicOptic.root.field("address").field("street")` | `.address.street` |
|
|
626
|
-
| `DynamicOptic.root.caseOf("Some")`
|
|
627
|
-
| `DynamicOptic.root.at(0)`
|
|
628
|
-
| `DynamicOptic.root.atIndices(0, 2, 5)`
|
|
629
|
-
| `DynamicOptic.elements`
|
|
630
|
-
| `DynamicOptic.root.atKey("host")`
|
|
631
|
-
| `DynamicOptic.root.atKey(80)`
|
|
632
|
-
| `DynamicOptic.mapValues`
|
|
633
|
-
| `DynamicOptic.mapKeys`
|
|
634
|
-
| `DynamicOptic.wrapped`
|
|
685
|
+
| `DynamicOptic.root.caseOf("Some")` | `<Some>` |
|
|
686
|
+
| `DynamicOptic.root.at(0)` | `[0]` |
|
|
687
|
+
| `DynamicOptic.root.atIndices(0, 2, 5)` | `[0,2,5]` |
|
|
688
|
+
| `DynamicOptic.elements` | `[*]` |
|
|
689
|
+
| `DynamicOptic.root.atKey("host")` | `{"host"}` |
|
|
690
|
+
| `DynamicOptic.root.atKey(80)` | `{80}` |
|
|
691
|
+
| `DynamicOptic.mapValues` | `{*}` |
|
|
692
|
+
| `DynamicOptic.mapKeys` | `{*:}` |
|
|
693
|
+
| `DynamicOptic.wrapped` | `.~` |
|
|
694
|
+
| `DynamicOptic.root.searchSchema(SchemaRepr.Nominal("Person"))` | `#Person` |
|
|
695
|
+
| `DynamicOptic.root.searchSchema(SchemaRepr.Primitive("string"))` | `#string` |
|
|
635
696
|
|
|
636
697
|
## Summary
|
|
637
698
|
|
package/reference/allows.md
CHANGED
|
@@ -584,6 +584,22 @@ sbt "schema-examples/runMain comptime.AllowsCsvExample"
|
|
|
584
584
|
```
|
|
585
585
|
|
|
586
586
|
```scala title="schema-examples/src/main/scala/comptime/AllowsCsvExample.scala"
|
|
587
|
+
/*
|
|
588
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
589
|
+
*
|
|
590
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
591
|
+
* you may not use this file except in compliance with the License.
|
|
592
|
+
* You may obtain a copy of the License at
|
|
593
|
+
*
|
|
594
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
595
|
+
*
|
|
596
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
597
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
598
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
599
|
+
* See the License for the specific language governing permissions and
|
|
600
|
+
* limitations under the License.
|
|
601
|
+
*/
|
|
602
|
+
|
|
587
603
|
package comptime
|
|
588
604
|
|
|
589
605
|
import zio.blocks.schema._
|
|
@@ -692,6 +708,22 @@ sbt "schema-examples/runMain comptime.AllowsEventBusExample"
|
|
|
692
708
|
```
|
|
693
709
|
|
|
694
710
|
```scala title="schema-examples/src/main/scala/comptime/AllowsEventBusExample.scala"
|
|
711
|
+
/*
|
|
712
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
713
|
+
*
|
|
714
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
715
|
+
* you may not use this file except in compliance with the License.
|
|
716
|
+
* You may obtain a copy of the License at
|
|
717
|
+
*
|
|
718
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
719
|
+
*
|
|
720
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
721
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
722
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
723
|
+
* See the License for the specific language governing permissions and
|
|
724
|
+
* limitations under the License.
|
|
725
|
+
*/
|
|
726
|
+
|
|
695
727
|
package comptime
|
|
696
728
|
|
|
697
729
|
import zio.blocks.schema._
|
|
@@ -798,6 +830,22 @@ sbt "schema-examples/runMain comptime.AllowsGraphQLTreeExample"
|
|
|
798
830
|
```
|
|
799
831
|
|
|
800
832
|
```scala title="schema-examples/src/main/scala/comptime/AllowsGraphQLTreeExample.scala"
|
|
833
|
+
/*
|
|
834
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
835
|
+
*
|
|
836
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
837
|
+
* you may not use this file except in compliance with the License.
|
|
838
|
+
* You may obtain a copy of the License at
|
|
839
|
+
*
|
|
840
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
841
|
+
*
|
|
842
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
843
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
844
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
845
|
+
* See the License for the specific language governing permissions and
|
|
846
|
+
* limitations under the License.
|
|
847
|
+
*/
|
|
848
|
+
|
|
801
849
|
package comptime
|
|
802
850
|
|
|
803
851
|
import zio.blocks.schema._
|
|
@@ -922,6 +970,22 @@ sbt "schema-examples/runMain comptime.AllowsSealedTraitExample"
|
|
|
922
970
|
```
|
|
923
971
|
|
|
924
972
|
```scala title="schema-examples/src/main/scala/comptime/AllowsSealedTraitExample.scala"
|
|
973
|
+
/*
|
|
974
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
975
|
+
*
|
|
976
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
977
|
+
* you may not use this file except in compliance with the License.
|
|
978
|
+
* You may obtain a copy of the License at
|
|
979
|
+
*
|
|
980
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
981
|
+
*
|
|
982
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
983
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
984
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
985
|
+
* See the License for the specific language governing permissions and
|
|
986
|
+
* limitations under the License.
|
|
987
|
+
*/
|
|
988
|
+
|
|
925
989
|
package comptime
|
|
926
990
|
|
|
927
991
|
import zio.blocks.schema._
|
|
@@ -1017,6 +1081,22 @@ object AllowsSealedTraitExample extends App {
|
|
|
1017
1081
|
Demonstrates how Allows constraints are verified at compile time — the code below shows valid examples that compile successfully, and includes comments showing which patterns would be rejected:
|
|
1018
1082
|
|
|
1019
1083
|
```scala title="schema-examples/src/main/scala/comptime/RdbmsExample.scala"
|
|
1084
|
+
/*
|
|
1085
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
1086
|
+
*
|
|
1087
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1088
|
+
* you may not use this file except in compliance with the License.
|
|
1089
|
+
* You may obtain a copy of the License at
|
|
1090
|
+
*
|
|
1091
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1092
|
+
*
|
|
1093
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1094
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1095
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1096
|
+
* See the License for the specific language governing permissions and
|
|
1097
|
+
* limitations under the License.
|
|
1098
|
+
*/
|
|
1099
|
+
|
|
1020
1100
|
package comptime
|
|
1021
1101
|
|
|
1022
1102
|
import zio.blocks.schema._
|
|
@@ -1210,6 +1290,22 @@ object RdbmsDemo {
|
|
|
1210
1290
|
Demonstrates how Allows enforces recursive schema constraints at compile time:
|
|
1211
1291
|
|
|
1212
1292
|
```scala title="schema-examples/src/main/scala/comptime/DocumentStoreExample.scala"
|
|
1293
|
+
/*
|
|
1294
|
+
* Copyright 2024-2026 John A. De Goes and the ZIO Contributors
|
|
1295
|
+
*
|
|
1296
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1297
|
+
* you may not use this file except in compliance with the License.
|
|
1298
|
+
* You may obtain a copy of the License at
|
|
1299
|
+
*
|
|
1300
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1301
|
+
*
|
|
1302
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1303
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1304
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1305
|
+
* See the License for the specific language governing permissions and
|
|
1306
|
+
* limitations under the License.
|
|
1307
|
+
*/
|
|
1308
|
+
|
|
1213
1309
|
package comptime
|
|
1214
1310
|
|
|
1215
1311
|
import zio.blocks.schema._
|
package/reference/codec.md
CHANGED
|
@@ -48,23 +48,23 @@ val result: Either[SchemaError, Person] = Person.codec.decode(bytes)
|
|
|
48
48
|
To include the base schema module with JSON support, add the following dependency to your `build.sbt`:
|
|
49
49
|
|
|
50
50
|
```scala
|
|
51
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
51
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.29"
|
|
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.29"
|
|
58
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.29"
|
|
59
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.29"
|
|
60
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.29"
|
|
61
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.29"
|
|
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.29"
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -152,7 +152,7 @@ object Person extends CompanionOptics[Person] {
|
|
|
152
152
|
|
|
153
153
|
// Override the codec for the "name" field
|
|
154
154
|
val customNameCodec = new JsonBinaryCodec[String] {
|
|
155
|
-
def decodeValue(in: JsonReader
|
|
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
|
|