@zio.dev/zio-blocks 0.0.51 → 0.0.55

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.
Files changed (164) hide show
  1. package/adr/2026-07-18-data-migration.md +123 -0
  2. package/guides/async-getting-started.md +687 -0
  3. package/guides/compile-time-resource-safety-with-scope.md +6 -0
  4. package/guides/getting-started-with-mux.md +0 -112
  5. package/guides/query-dsl-extending.md +1 -1
  6. package/guides/query-dsl-fluent-builder.md +1 -1
  7. package/guides/query-dsl-reified-optics.md +1 -1
  8. package/guides/query-dsl-sql.md +395 -1
  9. package/guides/sql-checked-interpolation.md +173 -0
  10. package/guides/sql-transactions.md +286 -0
  11. package/guides/telemetry-guide.md +131 -70
  12. package/guides/zio-schema-migration.md +6 -6
  13. package/index.md +200 -583
  14. package/package.json +1 -1
  15. package/reference/async.md +1379 -531
  16. package/reference/chunk.md +3 -3
  17. package/reference/codegen/index.md +1 -1
  18. package/reference/combinators.md +4 -4
  19. package/reference/config/config-decoder.md +460 -0
  20. package/reference/config/config-source.md +489 -0
  21. package/reference/config/errors.md +278 -0
  22. package/reference/config/flags.md +369 -0
  23. package/reference/config/formats.md +314 -0
  24. package/reference/config/index.md +304 -0
  25. package/reference/config/rollout.md +336 -0
  26. package/reference/context.md +6 -49
  27. package/reference/data-migration.md +269 -0
  28. package/reference/datastar/attributes.md +302 -0
  29. package/reference/datastar/events.md +234 -0
  30. package/reference/datastar/index.md +256 -0
  31. package/reference/datastar/signals.md +230 -0
  32. package/reference/datastar/sse.md +295 -0
  33. package/reference/datastar.md +2 -2
  34. package/reference/docs.md +2 -2
  35. package/reference/endpoint/bulk-creation.md +96 -0
  36. package/reference/endpoint/index.md +9 -89
  37. package/reference/endpoint/path-codec.md +12 -24
  38. package/reference/endpoint/route-pattern.md +4 -6
  39. package/reference/endpoint/segment-codec.md +19 -32
  40. package/reference/html.md +313 -9
  41. package/reference/htmx/index.md +4 -52
  42. package/reference/htmx/response-headers.md +240 -0
  43. package/reference/http-model/headers.md +735 -0
  44. package/reference/http-model/index.md +3 -1
  45. package/reference/http-model/model.md +107 -71
  46. package/reference/http-model/schema-codecs.md +522 -0
  47. package/reference/http-model/schema.md +6 -3
  48. package/reference/http-model/server-sent-event.md +341 -0
  49. package/reference/jwt.md +195 -0
  50. package/reference/maybe.md +128 -11
  51. package/reference/media-type.md +2 -2
  52. package/reference/mux.md +254 -0
  53. package/reference/mux.mdx +7 -2
  54. package/reference/openapi.md +3 -3
  55. package/reference/projection.md +654 -0
  56. package/reference/resource-management/resource.md +2 -98
  57. package/reference/resource-management/scope.md +1 -209
  58. package/reference/resource-management/wire.md +4 -50
  59. package/reference/ringbuffer/advanced.mdx +1 -1
  60. package/reference/ringbuffer/index.mdx +3 -3
  61. package/reference/ringbuffer/mpmc.mdx +38 -4
  62. package/reference/ringbuffer/mpsc.mdx +36 -4
  63. package/reference/ringbuffer/spmc.mdx +1 -1
  64. package/reference/ringbuffer/spsc.mdx +87 -15
  65. package/reference/schema/allows.md +0 -96
  66. package/reference/schema/binding.md +2 -2
  67. package/reference/schema/built-in-codecs/avro.md +2 -2
  68. package/reference/schema/built-in-codecs/bson.md +50 -20
  69. package/reference/schema/built-in-codecs/csv.md +2 -2
  70. package/reference/schema/built-in-codecs/index.md +3 -3
  71. package/reference/schema/built-in-codecs/json/index.md +2 -2
  72. package/reference/schema/built-in-codecs/messagepack.md +3 -3
  73. package/reference/schema/built-in-codecs/thrift.md +2 -2
  74. package/reference/schema/built-in-codecs/toon.md +3 -3
  75. package/reference/schema/built-in-codecs/yaml.md +2 -2
  76. package/reference/schema/codec.md +11 -11
  77. package/reference/schema/dynamic-optic.md +48 -3
  78. package/reference/schema/dynamic-schema.md +3 -3
  79. package/reference/schema/index.md +2 -0
  80. package/reference/schema/path-interpolator.md +2 -0
  81. package/reference/schema/reflect-transformer.md +140 -0
  82. package/reference/schema/schema-evolution/as.md +4 -4
  83. package/reference/schema/schema-evolution/into.md +2 -2
  84. package/reference/schema/schema-expr.md +2 -2
  85. package/reference/schema/schema-search.md +263 -0
  86. package/reference/schema/schema.md +10 -2
  87. package/reference/schema/type-class-derivation.md +1 -1
  88. package/reference/smithy.md +502 -3
  89. package/reference/sql/db-codec-deriver.md +3 -3
  90. package/reference/sql/db-codec.md +22 -22
  91. package/reference/sql/db-con.md +4 -4
  92. package/reference/sql/db-connection.md +1 -1
  93. package/reference/sql/db-param.md +1 -1
  94. package/reference/sql/db-result-reader.md +4 -2
  95. package/reference/sql/db-tx.md +46 -14
  96. package/reference/sql/ddl.md +1 -1
  97. package/reference/sql/frag.md +44 -10
  98. package/reference/sql/index.md +7 -7
  99. package/reference/sql/repo.md +15 -15
  100. package/reference/sql/sql-dialect.md +1 -1
  101. package/reference/sql/sql-logger.md +1 -1
  102. package/reference/sql/sql-name-mapper.md +3 -3
  103. package/reference/sql/table-metadata.md +3 -3
  104. package/reference/sql/table.md +10 -10
  105. package/reference/sql/transactor-zio.md +1 -1
  106. package/reference/sql/transactor.md +21 -11
  107. package/reference/sql-zio.md +1 -1
  108. package/reference/streams/core/index.md +32 -0
  109. package/reference/streams/{pipeline.md → core/pipeline.md} +210 -74
  110. package/reference/streams/{sink.md → core/sink.md} +331 -353
  111. package/reference/streams/{stream.md → core/stream.md} +919 -209
  112. package/reference/streams/execution-and-compatibility/async-execution.md +822 -0
  113. package/reference/streams/execution-and-compatibility/index.md +35 -0
  114. package/reference/streams/execution-and-compatibility/platform-differences.md +297 -0
  115. package/reference/streams/execution-and-compatibility/scala-2-compatibility.md +88 -0
  116. package/reference/streams/execution-and-compatibility/zero-boxing.md +393 -0
  117. package/reference/streams/index.md +140 -67
  118. package/reference/streams/primitives/index.md +30 -0
  119. package/reference/streams/primitives/reader.md +1992 -0
  120. package/reference/streams/{writer.md → primitives/writer.md} +254 -98
  121. package/reference/telemetry/common/any-value.md +90 -0
  122. package/reference/telemetry/common/attribute-key.md +87 -0
  123. package/reference/telemetry/common/attributes.md +118 -0
  124. package/reference/telemetry/common/index.md +39 -0
  125. package/reference/telemetry/common/instrumentation-scope.md +24 -0
  126. package/reference/telemetry/common/resource.md +34 -0
  127. package/reference/telemetry/index.md +311 -0
  128. package/reference/telemetry/logging/index.md +197 -0
  129. package/reference/telemetry/logging/log-enrichment.md +72 -0
  130. package/reference/telemetry/logging/log-formatter.md +100 -0
  131. package/reference/telemetry/logging/log-record-processor.md +56 -0
  132. package/reference/telemetry/logging/log-record.md +44 -0
  133. package/reference/telemetry/logging/log-writer.md +64 -0
  134. package/reference/telemetry/logging/logger-provider.md +142 -0
  135. package/reference/telemetry/logging/logger.md +83 -0
  136. package/reference/telemetry/logging/severity.md +62 -0
  137. package/reference/telemetry/metrics/index.md +150 -0
  138. package/reference/telemetry/metrics/instruments.md +183 -0
  139. package/reference/telemetry/metrics/labeled-instruments.md +74 -0
  140. package/reference/telemetry/metrics/meter-provider.md +76 -0
  141. package/reference/telemetry/metrics/meter.md +98 -0
  142. package/reference/telemetry/metrics/metric-data.md +57 -0
  143. package/reference/telemetry/otel/custom-exporter.md +216 -0
  144. package/reference/telemetry/otel/index.md +212 -0
  145. package/reference/telemetry/tracing/index.md +155 -0
  146. package/reference/telemetry/tracing/sampler.md +89 -0
  147. package/reference/telemetry/tracing/span-builder.md +57 -0
  148. package/reference/telemetry/tracing/span-context.md +39 -0
  149. package/reference/telemetry/tracing/span-data.md +32 -0
  150. package/reference/telemetry/tracing/span-kind.md +55 -0
  151. package/reference/telemetry/tracing/span-processor.md +53 -0
  152. package/reference/telemetry/tracing/span-status.md +47 -0
  153. package/reference/telemetry/tracing/span.md +117 -0
  154. package/reference/telemetry/tracing/tracer-provider.md +91 -0
  155. package/reference/telemetry/tracing/tracer.md +52 -0
  156. package/reference/typeid.md +0 -64
  157. package/sidebars.js +150 -12
  158. package/undocumented-report.md +528 -270
  159. package/reference/config.md +0 -158
  160. package/reference/streams/concurrent-operators.md +0 -106
  161. package/reference/streams/reader.md +0 -1284
  162. package/reference/streams/scala-2-compatibility.md +0 -55
  163. package/reference/streams/zero-boxing.md +0 -275
  164. package/reference/telemetry.md +0 -693
@@ -59,7 +59,7 @@ Creates a new MPSC ring buffer with the given capacity. The capacity must be a p
59
59
 
60
60
  To create an MPSC buffer:
61
61
 
62
- ```scala mdoc:compile-only
62
+ ```scala
63
63
  import zio.blocks.ringbuffer.MpscRingBuffer
64
64
 
65
65
  val rb = MpscRingBuffer[java.lang.Long](32)
@@ -119,10 +119,42 @@ Removes up to `limit` elements from the buffer, passing each to the `consumer` c
119
119
 
120
120
  When multiple threads produce work for a single processor, use `MpscRingBuffer`. This example shows how three producer threads safely offer items to a single consumer.
121
121
 
122
- ```scala mdoc:passthrough
123
- import docs.SourceFile
122
+ ```scala title="zio-blocks-examples/src/main/scala/ringbuffer/MpscExample.scala"
123
+ package ringbuffer
124
124
 
125
- SourceFile.print("zio-blocks-examples/src/main/scala/ringbuffer/MpscExample.scala")
125
+ import zio.blocks.ringbuffer.MpscRingBuffer
126
+ import java.util.concurrent.{CountDownLatch, Thread}
127
+
128
+ object MpscExample extends App {
129
+ val buffer = MpscRingBuffer[java.lang.Integer](16)
130
+ val latch = new CountDownLatch(1)
131
+
132
+ val producers = (0 until 3).map { id =>
133
+ new Thread(() => {
134
+ for (i <- 1 to 4) {
135
+ buffer.offer(java.lang.Integer.valueOf(id * 100 + i))
136
+ }
137
+ })
138
+ }
139
+
140
+ val consumer = new Thread(() => {
141
+ var received = 0
142
+ while (received < 12) {
143
+ val item = buffer.take()
144
+ if (item ne null) {
145
+ println(s"Processed: $item")
146
+ received += 1
147
+ }
148
+ }
149
+ latch.countDown()
150
+ })
151
+
152
+ producers.foreach(_.start())
153
+ consumer.start()
154
+ producers.foreach(_.join())
155
+ latch.await()
156
+ println("All items processed")
157
+ }
126
158
  ```
127
159
 
128
160
  ([source](https://github.com/zio/zio-blocks/blob/main/zio-blocks-examples/src/main/scala/ringbuffer/MpscExample.scala))
@@ -67,7 +67,7 @@ object SpmcRingBuffer {
67
67
 
68
68
  The capacity must be a positive power of two. To create an SPMC buffer:
69
69
 
70
- ```scala mdoc:compile-only
70
+ ```scala
71
71
  import zio.blocks.ringbuffer.SpmcRingBuffer
72
72
 
73
73
  val rb = SpmcRingBuffer[java.lang.Integer](64)
@@ -104,7 +104,7 @@ Creates a new SPSC ring buffer with the given capacity. The capacity must be a p
104
104
 
105
105
  We create an SPSC buffer as follows:
106
106
 
107
- ```scala mdoc:compile-only
107
+ ```scala
108
108
  import zio.blocks.ringbuffer.SpscRingBuffer
109
109
 
110
110
  val rb = SpscRingBuffer[String](16) // capacity must be power of 2
@@ -128,7 +128,7 @@ Inserts the element without blocking. Returns `true` on successful insertion, `f
128
128
 
129
129
  To handle backpressure by checking if insertion succeeds:
130
130
 
131
- ```scala mdoc:silent:reset
131
+ ```scala
132
132
  import zio.blocks.ringbuffer.SpscRingBuffer
133
133
 
134
134
  val rb = SpscRingBuffer[String](4)
@@ -136,12 +136,17 @@ val rb = SpscRingBuffer[String](4)
136
136
 
137
137
  When the buffer becomes full, `offer` returns `false`:
138
138
 
139
- ```scala mdoc
139
+ ```scala
140
140
  val result1 = rb.offer("a")
141
+ // result1: Boolean = true
141
142
  val result2 = rb.offer("b")
143
+ // result2: Boolean = true
142
144
  val result3 = rb.offer("c")
145
+ // result3: Boolean = true
143
146
  val result4 = rb.offer("d")
147
+ // result4: Boolean = true
144
148
  val result5 = rb.offer("e")
149
+ // result5: Boolean = false
145
150
  ```
146
151
 
147
152
  ### Removing Elements — `SpscRingBuffer#take`
@@ -158,12 +163,17 @@ Retrieves and removes an element from the front of the buffer. Returns immediate
158
163
 
159
164
  To retrieve elements in FIFO order:
160
165
 
161
- ```scala mdoc
166
+ ```scala
162
167
  rb.take()
168
+ // res2: String = "a"
163
169
  rb.take()
170
+ // res3: String = "b"
164
171
  rb.take()
172
+ // res4: String = "c"
165
173
  rb.take()
174
+ // res5: String = "d"
166
175
  rb.take()
176
+ // res6: String = null
167
177
  ```
168
178
 
169
179
  ### Checking State — `size`, `isEmpty`, `isFull`
@@ -202,7 +212,7 @@ Returns `true` if the buffer is at capacity (approximate). O(1).
202
212
 
203
213
  All four implementations provide the same three methods. To check state after operations:
204
214
 
205
- ```scala mdoc:silent:reset
215
+ ```scala
206
216
  import zio.blocks.ringbuffer.SpscRingBuffer
207
217
 
208
218
  val rb2 = SpscRingBuffer[String](8)
@@ -210,13 +220,18 @@ val rb2 = SpscRingBuffer[String](8)
210
220
 
211
221
  State queries are cheap but approximate under concurrency:
212
222
 
213
- ```scala mdoc
223
+ ```scala
214
224
  rb2.offer("x")
225
+ // res8: Boolean = true
215
226
  rb2.offer("y")
227
+ // res9: Boolean = true
216
228
 
217
229
  rb2.size
230
+ // res10: Int = 2
218
231
  rb2.isEmpty
232
+ // res11: Boolean = false
219
233
  rb2.isFull
234
+ // res12: Boolean = false
220
235
  ```
221
236
 
222
237
  ### Batch Operations — `SpscRingBuffer#drain` and `SpscRingBuffer#fill`
@@ -243,7 +258,7 @@ Inserts up to `limit` elements by calling the `supplier` for each new element. R
243
258
 
244
259
  Batch operations amortize synchronization costs. To drain multiple elements at once:
245
260
 
246
- ```scala mdoc:silent:reset
261
+ ```scala
247
262
  import zio.blocks.ringbuffer.SpscRingBuffer
248
263
 
249
264
  val rb3 = SpscRingBuffer[java.lang.Integer](16)
@@ -257,7 +272,7 @@ println(s"Drained items: ${collected.mkString(", ")}")
257
272
 
258
273
  To avoid repeated `offer` calls when producing elements, use fill:
259
274
 
260
- ```scala mdoc:silent:reset
275
+ ```scala
261
276
  import zio.blocks.ringbuffer.SpscRingBuffer
262
277
  import java.util.concurrent.atomic.AtomicInteger
263
278
 
@@ -288,7 +303,7 @@ In addition, each primitive variant exposes two methods for **in-band end-of-str
288
303
 
289
304
  `pollPacked` is intended for advanced consumers that want a single atomic operation distinguishing empty / data / DONE. Most application code that simply needs primitive throughput is fine using the higher-level concurrent stream operators below.
290
305
 
291
- ```scala mdoc:silent:reset
306
+ ```scala
292
307
  import zio.blocks.ringbuffer.{IntSpscRingBuffer, LongSpscRingBuffer, DoubleSpscRingBuffer}
293
308
 
294
309
  val ints = new IntSpscRingBuffer(16)
@@ -315,10 +330,36 @@ These variants underpin the primitive-specialized concurrent stream operators (`
315
330
 
316
331
  In a single-producer, single-consumer setup, use `SpscRingBuffer` for maximum throughput. This example demonstrates how two threads communicate efficiently using FastFlow signaling.
317
332
 
318
- ```scala mdoc:passthrough
319
- import docs.SourceFile
333
+ ```scala title="zio-blocks-examples/src/main/scala/ringbuffer/SpscExample.scala"
334
+ package ringbuffer
320
335
 
321
- SourceFile.print("zio-blocks-examples/src/main/scala/ringbuffer/SpscExample.scala")
336
+ import zio.blocks.ringbuffer.SpscRingBuffer
337
+ import java.util.concurrent.{CountDownLatch, Thread}
338
+
339
+ object SpscExample extends App {
340
+ val buffer = SpscRingBuffer[String](8)
341
+ val latch = new CountDownLatch(1)
342
+
343
+ val producer = new Thread(() => {
344
+ for (i <- 1 to 5) {
345
+ buffer.offer(s"message-$i")
346
+ }
347
+ })
348
+
349
+ val consumer = new Thread(() => {
350
+ for (_ <- 1 to 5) {
351
+ var msg: String = null
352
+ while ({ msg = buffer.take(); msg.eq(null) }) {}
353
+ println(s"Received: $msg")
354
+ }
355
+ latch.countDown()
356
+ })
357
+
358
+ producer.start()
359
+ consumer.start()
360
+ latch.await()
361
+ println("Done")
362
+ }
322
363
  ```
323
364
 
324
365
  ([source](https://github.com/zio/zio-blocks/blob/main/zio-blocks-examples/src/main/scala/ringbuffer/SpscExample.scala))
@@ -331,10 +372,41 @@ sbt "zio-blocks-examples/runMain ringbuffer.SpscExample"
331
372
 
332
373
  Use `fill` and `drain` for efficient batch operations. This example shows how to amortize synchronization costs by processing multiple elements at once.
333
374
 
334
- ```scala mdoc:passthrough
335
- import docs.SourceFile
375
+ ```scala title="zio-blocks-examples/src/main/scala/ringbuffer/BatchExample.scala"
376
+ package ringbuffer
336
377
 
337
- SourceFile.print("zio-blocks-examples/src/main/scala/ringbuffer/BatchExample.scala")
378
+ import zio.blocks.ringbuffer.SpscRingBuffer
379
+ import java.util.concurrent.{CountDownLatch, Thread}
380
+
381
+ object BatchExample extends App {
382
+ val buffer = SpscRingBuffer[java.lang.Integer](64)
383
+ val latch = new CountDownLatch(1)
384
+
385
+ val producer = new Thread(() => {
386
+ var batch = 1
387
+ while (batch <= 3) {
388
+ val currentBatch = batch
389
+ val count = buffer.fill(() => java.lang.Integer.valueOf(currentBatch * 100), 10)
390
+ println(s"Filled $count items in batch $currentBatch")
391
+ batch += 1
392
+ }
393
+ })
394
+
395
+ val consumer = new Thread(() => {
396
+ val items = scala.collection.mutable.Buffer[java.lang.Integer]()
397
+ while (items.size < 30) {
398
+ val drained = buffer.drain(items += _, 10)
399
+ if (drained > 0) println(s"Drained $drained items")
400
+ }
401
+ println(s"Total items consumed: ${items.size}")
402
+ latch.countDown()
403
+ })
404
+
405
+ producer.start()
406
+ consumer.start()
407
+ latch.await()
408
+ println("Done")
409
+ }
338
410
  ```
339
411
 
340
412
  ([source](https://github.com/zio/zio-blocks/blob/main/zio-blocks-examples/src/main/scala/ringbuffer/BatchExample.scala))
@@ -584,22 +584,6 @@ 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
-
603
587
  package comptime
604
588
 
605
589
  import zio.blocks.schema._
@@ -708,22 +692,6 @@ sbt "schema-examples/runMain comptime.AllowsEventBusExample"
708
692
  ```
709
693
 
710
694
  ```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
-
727
695
  package comptime
728
696
 
729
697
  import zio.blocks.schema._
@@ -830,22 +798,6 @@ sbt "schema-examples/runMain comptime.AllowsGraphQLTreeExample"
830
798
  ```
831
799
 
832
800
  ```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
-
849
801
  package comptime
850
802
 
851
803
  import zio.blocks.schema._
@@ -970,22 +922,6 @@ sbt "schema-examples/runMain comptime.AllowsSealedTraitExample"
970
922
  ```
971
923
 
972
924
  ```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
-
989
925
  package comptime
990
926
 
991
927
  import zio.blocks.schema._
@@ -1081,22 +1017,6 @@ object AllowsSealedTraitExample extends App {
1081
1017
  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:
1082
1018
 
1083
1019
  ```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
-
1100
1020
  package comptime
1101
1021
 
1102
1022
  import zio.blocks.schema._
@@ -1290,22 +1210,6 @@ object RdbmsDemo {
1290
1210
  Demonstrates how Allows enforces recursive schema constraints at compile time:
1291
1211
 
1292
1212
  ```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
-
1309
1213
  package comptime
1310
1214
 
1311
1215
  import zio.blocks.schema._
@@ -336,9 +336,9 @@ Used when the schema of the data is not known at compile time, such as JSON payl
336
336
  When `F[_, _] = NoBinding` in `Reflect[F[_, _], A]` the `Reflect` structure contains only pure data (no functions) and becomes fully serializable. This enables:
337
337
 
338
338
  1. **Schema serialization**: Convert schemas to JSON Schema or other formats, making them portable
339
- 2. **Schema rebinding**: Deserialize a schema and rebind it using a `TypeRegistry`, so it becomes type-safe and operational again
339
+ 2. **Schema rebinding**: Deserialize a schema and rebind it using a `BindingResolver`, so it becomes type-safe and operational again
340
340
 
341
- We will cover schema serialization and rebinding in more detail in the `Reflect` data type documentation page. For the full API of the binding lookup mechanism used during rebinding, see [BindingResolver](binding-resolver.md).
341
+ [ReflectTransformer](./reflect-transformer.md) covers schema serialization and rebinding in full detail — the transformer that strips bindings, the one that reattaches them, and how each is exposed as `Schema#toDynamicSchema`/`DynamicSchema#rebind`. For the full API of the binding lookup mechanism used during rebinding, see [BindingResolver](binding-resolver.md).
342
342
 
343
343
  ## Summary
344
344
 
@@ -26,7 +26,7 @@ Rather than writing custom encoders or relying on string-based Avro schema confi
26
26
  Add the module to your `build.sbt` (JVM-only, not available for Scala.js):
27
27
 
28
28
  ```sbt
29
- libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.51"
29
+ libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.55"
30
30
  ```
31
31
 
32
32
  Supported Scala versions: 2.13.x and 3.x
@@ -341,7 +341,7 @@ object Person {
341
341
  }
342
342
 
343
343
  val codec = Person.schema.derive(AvroFormat)
344
- // codec: AvroCodec[Person] = zio.blocks.schema.avro.AvroCodecDeriver$$anon$4@3d8dcca9
344
+ // codec: AvroCodec[Person] = zio.blocks.schema.avro.AvroCodecDeriver$$anon$4@601650a
345
345
  ```
346
346
 
347
347
  ### Primitive Type Support
@@ -5,7 +5,7 @@ title: "BSON Codec Module"
5
5
 
6
6
  `zio-blocks-schema-bson` is a **schema-driven BSON codec module** for serializing and deserializing Scala types to and from BSON (Binary JSON) format. It provides comprehensive encoding and decoding with support for 27 primitive types, records, variants, sequences, maps, and recursive types.
7
7
 
8
- Core types: `BsonCodec`, `BsonEncoder`, `BsonDecoder`, `BsonSchemaCodec`.
8
+ Core types: `BsonCodec`, `BsonEncoder`, `BsonDecoder`, `BsonCodecDeriver`, and the compatibility facade `BsonSchemaCodec`.
9
9
 
10
10
  The module integrates with org.bson to provide native BSON type support including special handling for `ObjectId`, `Decimal128`, and other BSON-specific types.
11
11
 
@@ -27,7 +27,7 @@ Rather than writing custom encoders or relying on string-based configuration, yo
27
27
  Add the module to your `build.sbt`:
28
28
 
29
29
  ```sbt
30
- libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.51"
30
+ libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.55"
31
31
  ```
32
32
 
33
33
  **Note:** This module is JVM-only and is not available for Scala.js.
@@ -39,7 +39,7 @@ Supported Scala versions: 2.13.x and 3.x
39
39
  The module provides a complete pipeline for BSON codec derivation and usage:
40
40
 
41
41
  1. **Define your type** — Any Scala type with a `Schema` instance
42
- 2. **Derive a codec** — Use `BsonSchemaCodec.bsonCodec(schema)` to obtain a `BsonCodec[A]`
42
+ 2. **Derive a codec** — Use `schema.derive(BsonCodecDeriver)` to obtain a `BsonCodec[A]`
43
43
  3. **Encode or decode** — Call `codec.encoder.toBsonValue()` or `codec.decoder.fromBsonValue()`
44
44
  4. **Handle errors** — Catch `BsonDecoder.Error` with location traces showing where the error occurred
45
45
 
@@ -52,9 +52,9 @@ The BSON codec pipeline flows through these layers:
52
52
  ```
53
53
  1. User defines Schema[A] for their type
54
54
  ↓
55
- 2. BsonSchemaCodec.bsonCodec(schema) creates BsonCodec[A]
55
+ 2. Schema[A].derive(BsonCodecDeriver) creates BsonCodec[A]
56
56
  ↓
57
- 3. BsonSchemaCodec derives Encoder and Decoder implementations
57
+ 3. DerivationBuilder traverses the schema and BsonCodecDeriver composes Encoder and Decoder implementations
58
58
  - For primitives: type-specific BSON encoders/decoders
59
59
  - For records: field-by-field composition
60
60
  - For variants: discriminator-based selection
@@ -64,7 +64,7 @@ The BSON codec pipeline flows through these layers:
64
64
  4. BsonEncoder writes values to BsonValue or BsonWriter
65
65
  BsonDecoder reads BsonValue or BsonReader to values
66
66
  ↓
67
- 5. BsonSchemaCodec.Config customizes behavior
67
+ 5. BsonCodecDeriver configuration methods customize behavior
68
68
  - Sum type handling (discriminator, wrapper, or none)
69
69
  - Field name mapping for MongoDB conventions
70
70
  - ObjectId detection and native BSON encoding
@@ -83,7 +83,7 @@ User type (e.g., case class Person)
83
83
  ↓
84
84
  Schema.derived (automatic via macro)
85
85
  ↓
86
- BsonSchemaCodec.bsonCodec(schema, config) → BsonCodec[Person]
86
+ schema.derive(configuredBsonCodecDeriver) → BsonCodec[Person]
87
87
  ↓
88
88
  Use codec.encoder.toBsonValue(person) to serialize
89
89
  Use codec.decoder.fromBsonValue(bsonValue) to deserialize
@@ -110,7 +110,7 @@ object Person {
110
110
  implicit val schema: Schema[Person] = Schema.derived
111
111
  }
112
112
 
113
- val codec = BsonSchemaCodec.bsonCodec(Person.schema)
113
+ val codec = Person.schema.derive(BsonCodecDeriver)
114
114
  val person = Person("Alice", 30, "alice@example.com")
115
115
  val bsonValue = codec.encoder.toBsonValue(person)
116
116
  ```
@@ -342,13 +342,11 @@ val rendered = BsonTrace.render(trace) // ".user[0].age"
342
342
 
343
343
  ---
344
344
 
345
- ## BsonSchemaCodec
345
+ ## BsonCodecDeriver and BsonSchemaCodec
346
346
 
347
- Configuration and derivation system for creating `BsonCodec[A]` instances from `Schema[A]`.
347
+ `BsonCodecDeriver` implements the shared `Deriver[BsonCodec]` contract. It supports direct derivation as well as `Schema.deriving` instance and modifier overrides by type, exact optic, or parent type and term name.
348
348
 
349
- ### Overview
350
-
351
- `BsonSchemaCodec` provides the `bsonCodec()` method to derive codecs, along with configurable behavior for sum types, field mapping, and ObjectId handling.
349
+ `BsonSchemaCodec` retains `bsonCodec`, `bsonEncoder`, `bsonDecoder`, and `Config` as compatibility and convenience APIs. These methods delegate to `BsonCodecDeriver`, so both entry points have the same BSON behavior.
352
350
 
353
351
  ### Configuration
354
352
 
@@ -396,18 +394,50 @@ object Person {
396
394
  implicit val schema: Schema[Person] = Schema.derived
397
395
  }
398
396
 
399
- val codec = BsonSchemaCodec.bsonCodec(Person.schema)
397
+ val codec = Person.schema.derive(BsonCodecDeriver)
400
398
  // codec: BsonCodec[Person] = BsonCodec(
401
- // encoder = zio.blocks.schema.bson.BsonSchemaCodec$$anon$4@77dddeaa,
402
- // decoder = zio.blocks.schema.bson.BsonSchemaCodec$$anon$5@1692f6db
399
+ // encoder = zio.blocks.schema.bson.BsonCodecDeriver$$anon$5@75f2c0f,
400
+ // decoder = zio.blocks.schema.bson.BsonCodecDeriver$$anon$6@5b87f051
403
401
  // )
404
- val customCodec = BsonSchemaCodec.bsonCodec(Person.schema, BsonSchemaCodec.Config)
405
- // customCodec: BsonCodec[Person] = BsonCodec(
406
- // encoder = zio.blocks.schema.bson.BsonSchemaCodec$$anon$4@3497a5ea,
407
- // decoder = zio.blocks.schema.bson.BsonSchemaCodec$$anon$5@2d26055c
402
+ val configuredCodec = Person.schema.derive(BsonCodecDeriver.withIgnoreExtraFields(false))
403
+ // configuredCodec: BsonCodec[Person] = BsonCodec(
404
+ // encoder = zio.blocks.schema.bson.BsonCodecDeriver$$anon$5@117db32c,
405
+ // decoder = zio.blocks.schema.bson.BsonCodecDeriver$$anon$6@6fbcca58
406
+ // )
407
+
408
+ // Compatibility facade
409
+ val compatibleCodec = BsonSchemaCodec.bsonCodec(Person.schema)
410
+ // compatibleCodec: BsonCodec[Person] = BsonCodec(
411
+ // encoder = zio.blocks.schema.bson.BsonCodecDeriver$$anon$5@79d7f29,
412
+ // decoder = zio.blocks.schema.bson.BsonCodecDeriver$$anon$6@7b055825
408
413
  // )
414
+ val configuredCompatibleCodec = BsonSchemaCodec.bsonCodec(Person.schema, BsonSchemaCodec.Config)
415
+ // configuredCompatibleCodec: BsonCodec[Person] = BsonCodec(
416
+ // encoder = zio.blocks.schema.bson.BsonCodecDeriver$$anon$5@148d2e57,
417
+ // decoder = zio.blocks.schema.bson.BsonCodecDeriver$$anon$6@78856fd8
418
+ // )
419
+ ```
420
+
421
+ ### Derivation overrides
422
+
423
+ Use `Schema.deriving` when part of a schema needs a custom codec or runtime modifier:
424
+
425
+ ```scala
426
+ val codec = Person.schema
427
+ .deriving(BsonCodecDeriver)
428
+ .instance(Person.schema.reflect.typeId, "age", customIntCodec)
429
+ .modifier(Person.schema.reflect.typeId, "name", Modifier.rename("fullName"))
430
+ .derive
409
431
  ```
410
432
 
433
+ Type-level overrides affect every matching occurrence. Parent-type and term-name overloads are also available for fields and variant cases. String map keys remain BSON document field names; override map values or the whole map codec when custom map behavior is needed.
434
+
435
+ Record-level `Modifier.fieldNaming` and `Modifier.noExtraFields` annotations override the corresponding default BSON behavior. Variant-level `Modifier.caseNaming` and `Modifier.discriminator` annotations override class-name mapping and sum-type handling for the annotated variant.
436
+
437
+ ### Semantic Json values
438
+
439
+ `zio.blocks.schema.json.Json` objects, arrays, scalars, and nulls map directly to their semantic BSON equivalents. Finite BSON doubles other than signed zero retain their exact value when converted through `Json`; BSON signed zero is normalized to JSON zero because `Json.Number` does not retain its sign. Duplicate `Json.Object` field names are rejected because `BsonDocument` cannot represent them without data loss.
440
+
411
441
  ---
412
442
 
413
443
  ## BsonTrace
@@ -37,13 +37,13 @@ Rather than writing custom parsers or relying on string-based configuration, you
37
37
  Add the module to your `build.sbt`:
38
38
 
39
39
  ```sbt
40
- libraryDependencies += "dev.zio" %% "zio-blocks-schema-csv" % "0.0.51"
40
+ libraryDependencies += "dev.zio" %% "zio-blocks-schema-csv" % "0.0.55"
41
41
  ```
42
42
 
43
43
  For Scala.js, use `%%%` instead of `%%`:
44
44
 
45
45
  ```sbt
46
- libraryDependencies += "dev.zio" %%% "zio-blocks-schema-csv" % "0.0.51"
46
+ libraryDependencies += "dev.zio" %%% "zio-blocks-schema-csv" % "0.0.55"
47
47
  ```
48
48
 
49
49
  Supported Scala versions: 2.13.x and 3.x
@@ -4,17 +4,17 @@ title: "Built-in Formats and Codecs"
4
4
  sidebar_label: "Built-in Formats and Codecs"
5
5
  ---
6
6
 
7
- ZIO Blocks Schema provides codec derivation for multiple serialization formats. Once you have a `Schema[A]` for your data type, you can derive codecs for most formats using the unified `Schema.derive(Format)` pattern. BSON uses a different API: `BsonSchemaCodec.bsonCodec(schema)`. See the [Format documentation](../format.md) for details on how formats work.
7
+ ZIO Blocks Schema provides codec derivation for multiple serialization formats. Once you have a `Schema[A]`, formats can be passed to `Schema.derive`, while BSON is derived with `Schema[A].derive(BsonCodecDeriver)`. The older `BsonSchemaCodec.bsonCodec(schema)` API remains a compatibility facade. See the [Format documentation](../format.md) for details.
8
8
 
9
9
  ## Built-in Codecs
10
10
 
11
- Here's a summary of the codecs currently supported by ZIO Blocks. Most codecs provide a `BinaryFormat` or `TextFormat` object that can be passed to `derive`. BSON uses a different API (see below). See the dedicated codec documentation for installation, usage examples, and detailed type mappings:
11
+ Here's a summary of the codecs currently supported by ZIO Blocks. Most codecs provide a `BinaryFormat` or `TextFormat`; BSON provides a `Deriver` because it operates on native BSON readers, writers, and values. See the dedicated documentation for details:
12
12
 
13
13
  | Derivation API | Codec Type | MIME Type | Module | Documentation |
14
14
  |---------------------|-----------------------|-----------------------|---------------------------------|---------------------------------|
15
15
  | `JsonFormat` | `JsonCodec[A]` | `application/json` | `zio-blocks-schema` | [JSON](./json/index.md) |
16
16
  | `AvroFormat` | `AvroCodec[A]` | `application/avro` | `zio-blocks-schema-avro` | [Avro](./avro.md) |
17
- | `BsonSchemaCodec` | `BsonCodec[A]` | `application/bson` | `zio-blocks-schema-bson` | [BSON](./bson.md) |
17
+ | `BsonCodecDeriver` | `BsonCodec[A]` | `application/bson` | `zio-blocks-schema-bson` | [BSON](./bson.md) |
18
18
  | `CsvFormat` | `CsvCodec[A]` | `text/csv` | `zio-blocks-schema-csv` | [CSV](./csv.md) |
19
19
  | `MessagePackFormat` | `MessagePackCodec[A]` | `application/msgpack` | `zio-blocks-schema-messagepack` | [MessagePack](./messagepack.md) |
20
20
  | `ThriftFormat` | `ThriftCodec[A]` | `application/thrift` | `zio-blocks-schema-thrift` | [Thrift](./thrift.md) |
@@ -36,13 +36,13 @@ schema.conforms(person) // true
36
36
  The JSON codec is included in the ZIO Blocks Schema module. Add it to your `build.sbt`:
37
37
 
38
38
  ```scala
39
- libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.51"
39
+ libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.55"
40
40
  ```
41
41
 
42
42
  For Scala.js projects, use `%%%` instead:
43
43
 
44
44
  ```scala
45
- libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.51"
45
+ libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.55"
46
46
  ```
47
47
 
48
48
  **Supported Scala versions:** 2.13.x and 3.x
@@ -27,13 +27,13 @@ Rather than writing custom encoders or relying on string-based schema configurat
27
27
  Add the module to your `build.sbt`:
28
28
 
29
29
  ```sbt
30
- libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.51"
30
+ libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.55"
31
31
  ```
32
32
 
33
33
  For Scala.js, use `%%%` instead of `%%`:
34
34
 
35
35
  ```sbt
36
- libraryDependencies += "dev.zio" %%% "zio-blocks-schema-messagepack" % "0.0.51"
36
+ libraryDependencies += "dev.zio" %%% "zio-blocks-schema-messagepack" % "0.0.55"
37
37
  ```
38
38
 
39
39
  Supported Scala versions: 2.13.x and 3.x
@@ -338,7 +338,7 @@ object Person {
338
338
  }
339
339
 
340
340
  val codec = Person.schema.derive(MessagePackFormat)
341
- // codec: MessagePackCodec[Person] = zio.blocks.schema.msgpack.MessagePackCodecDeriver$$anon$3@7752c755
341
+ // codec: MessagePackCodec[Person] = zio.blocks.schema.msgpack.MessagePackCodecDeriver$$anon$3@2bd1156b
342
342
  ```
343
343
 
344
344
  ### Primitive Type Support
@@ -26,7 +26,7 @@ Rather than writing custom encoders or relying on code generation from .thrift f
26
26
  Add the module to your `build.sbt`:
27
27
 
28
28
  ```sbt
29
- libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.51"
29
+ libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.55"
30
30
  ```
31
31
 
32
32
  **Note:** This module is JVM-only and is not available for Scala.js.
@@ -323,7 +323,7 @@ object Person {
323
323
  }
324
324
 
325
325
  val codec = Person.schema.derive(ThriftFormat)
326
- // codec: ThriftCodec[Person] = zio.blocks.schema.thrift.ThriftCodecDeriver$$anon$3@52aa2c93
326
+ // codec: ThriftCodec[Person] = zio.blocks.schema.thrift.ThriftCodecDeriver$$anon$3@3a518fc7
327
327
  ```
328
328
 
329
329
  ### Primitive Type Support