@zio.dev/zio-blocks 0.0.51 → 0.0.56

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 (166) 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 -559
  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/endpoint.md +1 -0
  37. package/reference/endpoint/index.md +9 -89
  38. package/reference/endpoint/path-codec.md +12 -24
  39. package/reference/endpoint/route-pattern.md +4 -6
  40. package/reference/endpoint/segment-codec.md +19 -32
  41. package/reference/html.md +313 -9
  42. package/reference/htmx/index.md +4 -52
  43. package/reference/htmx/response-headers.md +240 -0
  44. package/reference/http-model/headers.md +735 -0
  45. package/reference/http-model/index.md +3 -1
  46. package/reference/http-model/model.md +107 -71
  47. package/reference/http-model/schema-codecs.md +522 -0
  48. package/reference/http-model/schema.md +6 -3
  49. package/reference/http-model/server-sent-event.md +341 -0
  50. package/reference/jwt.md +195 -0
  51. package/reference/maybe.md +128 -11
  52. package/reference/media-type.md +2 -2
  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/index.md +1 -1
  57. package/reference/resource-management/resource.md +2 -98
  58. package/reference/resource-management/scope.md +1 -209
  59. package/reference/resource-management/wire.md +4 -50
  60. package/reference/ringbuffer/advanced.mdx +1 -1
  61. package/reference/ringbuffer/index.mdx +3 -3
  62. package/reference/ringbuffer/mpmc.mdx +38 -4
  63. package/reference/ringbuffer/mpsc.mdx +36 -4
  64. package/reference/ringbuffer/spmc.mdx +1 -1
  65. package/reference/ringbuffer/spsc.mdx +87 -15
  66. package/reference/schema/allows.md +0 -96
  67. package/reference/schema/binding.md +2 -2
  68. package/reference/schema/built-in-codecs/avro.md +2 -2
  69. package/reference/schema/built-in-codecs/bson.md +50 -20
  70. package/reference/schema/built-in-codecs/csv.md +2 -2
  71. package/reference/schema/built-in-codecs/index.md +3 -3
  72. package/reference/schema/built-in-codecs/json/index.md +2 -2
  73. package/reference/schema/built-in-codecs/json/json.md +1 -0
  74. package/reference/schema/built-in-codecs/messagepack.md +3 -3
  75. package/reference/schema/built-in-codecs/thrift.md +2 -2
  76. package/reference/schema/built-in-codecs/toon.md +3 -3
  77. package/reference/schema/built-in-codecs/yaml.md +2 -2
  78. package/reference/schema/codec.md +11 -11
  79. package/reference/schema/dynamic-optic.md +48 -3
  80. package/reference/schema/dynamic-schema.md +3 -3
  81. package/reference/schema/index.md +2 -0
  82. package/reference/schema/path-interpolator.md +2 -0
  83. package/reference/schema/reflect-transformer.md +140 -0
  84. package/reference/schema/schema-evolution/as.md +4 -4
  85. package/reference/schema/schema-evolution/into.md +2 -2
  86. package/reference/schema/schema-expr.md +2 -2
  87. package/reference/schema/schema-search.md +263 -0
  88. package/reference/schema/schema.md +10 -2
  89. package/reference/schema/type-class-derivation.md +1 -1
  90. package/reference/smithy.md +502 -3
  91. package/reference/sql/db-codec-deriver.md +3 -3
  92. package/reference/sql/db-codec.md +22 -22
  93. package/reference/sql/db-con.md +4 -4
  94. package/reference/sql/db-connection.md +1 -1
  95. package/reference/sql/db-param.md +1 -1
  96. package/reference/sql/db-result-reader.md +4 -2
  97. package/reference/sql/db-tx.md +46 -14
  98. package/reference/sql/ddl.md +1 -1
  99. package/reference/sql/frag.md +44 -10
  100. package/reference/sql/index.md +7 -7
  101. package/reference/sql/repo.md +15 -15
  102. package/reference/sql/sql-dialect.md +1 -1
  103. package/reference/sql/sql-logger.md +1 -1
  104. package/reference/sql/sql-name-mapper.md +3 -3
  105. package/reference/sql/table-metadata.md +3 -3
  106. package/reference/sql/table.md +10 -10
  107. package/reference/sql/transactor-zio.md +1 -1
  108. package/reference/sql/transactor.md +21 -11
  109. package/reference/sql-zio.md +2 -2
  110. package/reference/streams/core/index.md +32 -0
  111. package/reference/streams/{pipeline.md → core/pipeline.md} +210 -74
  112. package/reference/streams/{sink.md → core/sink.md} +331 -353
  113. package/reference/streams/{stream.md → core/stream.md} +919 -209
  114. package/reference/streams/execution-and-compatibility/async-execution.md +822 -0
  115. package/reference/streams/execution-and-compatibility/index.md +35 -0
  116. package/reference/streams/execution-and-compatibility/platform-differences.md +297 -0
  117. package/reference/streams/execution-and-compatibility/scala-2-compatibility.md +88 -0
  118. package/reference/streams/execution-and-compatibility/zero-boxing.md +393 -0
  119. package/reference/streams/index.md +140 -67
  120. package/reference/streams/primitives/index.md +30 -0
  121. package/reference/streams/primitives/reader.md +1992 -0
  122. package/reference/streams/{writer.md → primitives/writer.md} +254 -98
  123. package/reference/telemetry/common/any-value.md +90 -0
  124. package/reference/telemetry/common/attribute-key.md +87 -0
  125. package/reference/telemetry/common/attributes.md +118 -0
  126. package/reference/telemetry/common/index.md +39 -0
  127. package/reference/telemetry/common/instrumentation-scope.md +24 -0
  128. package/reference/telemetry/common/resource.md +34 -0
  129. package/reference/telemetry/index.md +311 -0
  130. package/reference/telemetry/logging/index.md +197 -0
  131. package/reference/telemetry/logging/log-enrichment.md +72 -0
  132. package/reference/telemetry/logging/log-formatter.md +100 -0
  133. package/reference/telemetry/logging/log-record-processor.md +56 -0
  134. package/reference/telemetry/logging/log-record.md +44 -0
  135. package/reference/telemetry/logging/log-writer.md +64 -0
  136. package/reference/telemetry/logging/logger-provider.md +142 -0
  137. package/reference/telemetry/logging/logger.md +83 -0
  138. package/reference/telemetry/logging/severity.md +62 -0
  139. package/reference/telemetry/metrics/index.md +150 -0
  140. package/reference/telemetry/metrics/instruments.md +183 -0
  141. package/reference/telemetry/metrics/labeled-instruments.md +74 -0
  142. package/reference/telemetry/metrics/meter-provider.md +76 -0
  143. package/reference/telemetry/metrics/meter.md +98 -0
  144. package/reference/telemetry/metrics/metric-data.md +57 -0
  145. package/reference/telemetry/otel/custom-exporter.md +216 -0
  146. package/reference/telemetry/otel/index.md +212 -0
  147. package/reference/telemetry/tracing/index.md +155 -0
  148. package/reference/telemetry/tracing/sampler.md +89 -0
  149. package/reference/telemetry/tracing/span-builder.md +57 -0
  150. package/reference/telemetry/tracing/span-context.md +39 -0
  151. package/reference/telemetry/tracing/span-data.md +32 -0
  152. package/reference/telemetry/tracing/span-kind.md +55 -0
  153. package/reference/telemetry/tracing/span-processor.md +53 -0
  154. package/reference/telemetry/tracing/span-status.md +47 -0
  155. package/reference/telemetry/tracing/span.md +117 -0
  156. package/reference/telemetry/tracing/tracer-provider.md +91 -0
  157. package/reference/telemetry/tracing/tracer.md +52 -0
  158. package/reference/typeid.md +0 -64
  159. package/sidebars.js +365 -185
  160. package/undocumented-report.md +528 -270
  161. package/reference/config.md +0 -158
  162. package/reference/streams/concurrent-operators.md +0 -106
  163. package/reference/streams/reader.md +0 -1284
  164. package/reference/streams/scala-2-compatibility.md +0 -55
  165. package/reference/streams/zero-boxing.md +0 -275
  166. package/reference/telemetry.md +0 -693
package/index.md CHANGED
@@ -3,144 +3,165 @@ id: index
3
3
  title: "ZIO Blocks"
4
4
  ---
5
5
 
6
- **Modular, zero-dependency building blocks for modern Scala applications.**
6
+ **Modular building blocks for modern Scala applications—no effect system required.**
7
7
 
8
- [![Development](https://img.shields.io/badge/Project%20Stage-Development-green.svg)](https://github.com/zio/zio/wiki/Project-Stages) ![CI Badge](https://github.com/zio/zio-blocks/workflows/CI/badge.svg) [![ZIO Blocks](https://img.shields.io/github/stars/zio/zio-blocks?style=social)](https://github.com/zio/zio-blocks)
8
+ [![Development](https://img.shields.io/badge/Project%20Stage-Development-green.svg)](https://github.com/zio/zio/wiki/Project-Stages) ![CI Badge](https://github.com/zio/zio-blocks/workflows/CI/badge.svg) [![Maven Central](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Frepo1.maven.org%2Fmaven2%2Fdev%2Fzio%2Fzio-blocks-config_3%2Fmaven-metadata.xml&label=Maven%20Central)](https://central.sonatype.com/artifact/dev.zio/zio-blocks-config_3) [![Sonatype Snapshot](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fcentral.sonatype.com%2Frepository%2Fmaven-snapshots%2Fdev%2Fzio%2Fzio-blocks-config_3%2Fmaven-metadata.xml&label=Sonatype%20Snapshot)](https://central.sonatype.com/repository/maven-snapshots/dev/zio/zio-blocks-config_3/) [![ZIO Blocks](https://img.shields.io/github/stars/zio/zio-blocks?style=social)](https://github.com/zio/zio-blocks)
9
9
 
10
10
  ## What Is ZIO Blocks?
11
11
 
12
12
  ZIO Blocks is a **family of type-safe, modular building blocks** for Scala applications. Each block is a standalone library with zero or minimal dependencies, designed to work with *any* Scala stack—ZIO, Cats Effect, Kyo, Ox, Akka, or plain Scala.
13
13
 
14
- The philosophy is simple: **use what you need, nothing more**. Each block is independently useful, cross-platform (JVM, JS), and designed to compose with other blocks or your existing code.
14
+ The philosophy is simple: **use what you need, nothing more**. Each block is independently useful and designed to compose with other blocks or your existing code.
15
15
 
16
- ## The Blocks
17
-
18
- | Block | Description | Status |
19
- |-------|-------------|--------|
20
- | **Schema** | Type-safe schemas with automatic codec derivation | ✅ Available |
21
- | **Chunk** | High-performance immutable indexed sequences | ✅ Available |
22
- | **Scope** | Compile-time safe resource management and DI | ✅ Available |
23
- | **Docs** | GitHub Flavored Markdown parsing and rendering | ✅ Available |
24
- | **Codegen** | Generic Scala code generation IR and emitter | ✅ Available |
25
- | **TypeId** | Compile-time type identity with rich metadata | ✅ Available |
26
- | **Context** | Type-indexed heterogeneous collections | ✅ Available |
27
- | **MediaType** | Type-safe IANA media types with 2,600+ predefined types | ✅ Available |
28
- | **OpenAPI** | Type-safe OpenAPI 3.1 specification generation | ✅ Available |
29
- | **Ring Buffer** | High-performance bounded ring buffers (SPSC, MPSC, SPMC, MPMC) | ✅ Available |
30
- | **Streams** | Pull-based streaming primitives | ✅ Available |
31
- | **SQL** | Type-safe JDBC wrapper with schema-derived codecs and CRUD repository | ✅ Available |
32
- | **Async** | Zero-allocation asynchronous effect type with direct-style `await` | ✅ Available |
33
-
34
- ## Config
35
-
36
- Type-safe configuration loading, feature flags, rollout logic, and source adapters for YAML, JSON, and HOCON.
37
-
38
- See the [Config reference](reference/config.md) for the full API surface, supported rollout syntax, and format-adapter entry points.
16
+ ## Core Principles
39
17
 
40
- ### Key Features
18
+ - **Zero Lock-In**: No dependency on ZIO, Cats Effect, or any other effect system. Use a block with whatever stack you already have.
19
+ - **Modular**: Each block is a separate artifact. Depend on exactly what you need.
20
+ - **Cross-Platform**: Most blocks cross-build for JVM and Scala.js, and for Scala 2.13 and 3.x with source compatibility—adopt Scala 3 on your timeline, not ours. The catalog below records the exceptions per block.
21
+ - **High Performance**: Implementations that avoid boxing, minimize allocations, and use platform-specific features where they pay off.
22
+ - **Type Safety**: Scala's type system carries the correctness guarantees, without runtime overhead.
41
23
 
42
- - **Static flags**: Resolve once at class load with `StaticFlag[A]`
43
- - **Typed config loading**: Decode case classes with `Config.load[A]`
44
- - **Flag sources**: Register custom flag sources in `FlagSource.Registry`
45
- - **Source composition**: Combine sources with `orElse` and keep provenance
46
- - **Rollout DSL**: Select values with path and percentage rules
47
- - **File adapters**: Parse YAML, JSON, and HOCON into `ConfigSource`
24
+ ## Getting Started
48
25
 
49
- ### Installation
26
+ Add a block and use it. Nothing else to wire up—no runtime to install, no effect
27
+ type to adopt:
50
28
 
51
29
  ```scala
52
- libraryDependencies += "dev.zio" %% "zio-blocks-config" % "0.0.51"
53
- libraryDependencies += "dev.zio" %% "zio-blocks-config-yaml" % "0.0.51"
54
- libraryDependencies += "dev.zio" %% "zio-blocks-config-json" % "0.0.51"
55
- libraryDependencies += "dev.zio" %% "zio-blocks-config-hocon" % "0.0.51"
30
+ libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.56"
56
31
  ```
57
32
 
58
- ### Quick Start: StaticFlag
59
-
60
33
  ```scala
61
- import zio.blocks.config._
62
-
63
- object poolSize extends StaticFlag[Int](10)
34
+ import zio.blocks.schema._
64
35
 
65
- val size: Int = poolSize()
66
- ```
36
+ case class Person(name: String, age: Int)
67
37
 
68
- ### Quick Start: Config.load[A]
38
+ object Person {
39
+ implicit val schema: Schema[Person] = Schema.derived
40
+ }
69
41
 
70
- The snippet below uses Scala 3 syntax.
42
+ val alice = Person("Alice", 30)
71
43
 
72
- ```scala
73
- import zio.blocks.config._
74
- import zio.blocks.scope.Unscoped
44
+ // One schema, every format
45
+ val jsonStr = alice.toJsonString // {"name":"Alice","age":30}
46
+ val parsed = """{"name":"Bob","age":25}""".fromJson[Person]
47
+ ```
75
48
 
76
- final case class AppConfig(host: String, port: Int) derives Schema, Unscoped
49
+ The four blocks below get a full walkthrough because they have no close
50
+ equivalent elsewhere in Scala. Every other block is one row away in the catalog,
51
+ and each row links to its own reference page.
77
52
 
78
- val cfg = Config.load[AppConfig](ConfigSource.fromMap(Map("host" -> "localhost", "port" -> "8080")))
79
- ```
53
+ ## All Blocks
80
54
 
81
- ### Example: FlagSource Plugin
55
+ Every block is published under the `dev.zio` organization. Most cross-build for
56
+ **Scala 2.13 and 3.x** on both **JVM and Scala.js** with full source compatibility —
57
+ adopt Scala 3 on your timeline, not ours. The handful of modules that are narrower
58
+ say so in their own row.
82
59
 
83
- ```scala
84
- package myapp
60
+ ### Meta Programming
85
61
 
86
- import zio.blocks.config._
62
+ JSON support is built into `zio-blocks-schema`; the modules below add further formats.
87
63
 
88
- object poolSize extends StaticFlag[Int](10)
64
+ | Block | Artifact | Platform | Scala | Description |
65
+ |-------|----------|----------|-------|-------------|
66
+ | [Schema](./reference/schema/index.md) | `zio-blocks-schema` | JVM · JS | 2.13 · 3.x | Type-safe schemas with automatic codec, optic, and validator derivation |
67
+ | [Avro Codec](./reference/schema/built-in-codecs/avro.md) | `zio-blocks-schema-avro` | JVM | 2.13 · 3.x | Apache Avro binary serialization with automatic schema generation |
68
+ | [BSON Codec](./reference/schema/built-in-codecs/bson.md) | `zio-blocks-schema-bson` | JVM | 2.13 · 3.x | MongoDB-compatible BSON serialization with native type support |
69
+ | [CSV Codec](./reference/schema/built-in-codecs/csv.md) | `zio-blocks-schema-csv` | JVM · JS | 2.13 · 3.x | RFC 4180-compliant CSV serialization |
70
+ | [MessagePack Codec](./reference/schema/built-in-codecs/messagepack.md) | `zio-blocks-schema-messagepack` | JVM · JS | 2.13 · 3.x | Compact binary serialization with optimized streaming |
71
+ | [Thrift Codec](./reference/schema/built-in-codecs/thrift.md) | `zio-blocks-schema-thrift` | JVM | 2.13 · 3.x | Apache Thrift binary serialization with TBinaryProtocol |
72
+ | [TOON Codec](./reference/schema/built-in-codecs/toon.md) | `zio-blocks-schema-toon` | JVM · JS | 2.13 · 3.x | Token-oriented notation 30–60% smaller than JSON, tuned for LLM prompts |
73
+ | [XML Codec](./reference/schema/built-in-codecs/xml.md) | `zio-blocks-schema-xml` | JVM · JS | 2.13 · 3.x | Zero-dependency XML serialization with fluent navigation and patching |
74
+ | [YAML Codec](./reference/schema/built-in-codecs/yaml.md) | `zio-blocks-schema-yaml` | JVM · JS | 2.13 · 3.x | Human-readable YAML serialization with JSON interop |
75
+ | [TypeId](./reference/typeid.md) | `zio-blocks-typeid` | JVM · JS | 2.13 · 3.x | Compile-time type identity with rich metadata |
89
76
 
90
- FlagSource.Registry.register(
91
- FlagSource.fromMap(Map("myapp.poolSize" -> "20"), "demo")
92
- )
77
+ ### Resource Management
93
78
 
94
- val size = poolSize()
95
- ```
79
+ All of these ship in `zio-blocks-scope`.
96
80
 
97
- :::note
98
- Register a `FlagSource` before the first reference to a `StaticFlag` object. `StaticFlag` resolves during object initialization, so a source registered later will not change a flag that has already been loaded. The lookup key is the flag object's fully qualified name (`myapp.poolSize` in this example).
99
- :::
81
+ | Block | Artifact | Platform | Scala | Description |
82
+ |-------|----------|----------|-------|-------------|
83
+ | [Scope](./reference/resource-management/index.md) | `zio-blocks-scope` | JVM · JS | 2.13 · 3.x | Compile-time safe resource boundaries that keep values from escaping their lifetime |
84
+ | [Resource](./reference/resource-management/resource.md) | `zio-blocks-scope` | JVM · JS | 2.13 · 3.x | Lazy recipes that pair acquisition with finalization, composable with `map`, `flatMap`, and `zip` |
85
+ | [Unscoped](./reference/resource-management/unscoped.md) | `zio-blocks-scope` | JVM · JS | 2.13 · 3.x | Marker typeclass for plain data that can safely leave a scope |
86
+ | [DeferHandle](./reference/resource-management/defer-handle.md) | `zio-blocks-scope` | JVM · JS | 2.13 · 3.x | Handle returned by `Scope.defer` for cancelling a registered finalizer |
87
+ | [Finalizer](./reference/resource-management/finalizer.md) | `zio-blocks-scope` | JVM · JS | 2.13 · 3.x | Minimal capability interface for registering cleanup actions |
88
+ | [Finalization](./reference/resource-management/finalization.md) | `zio-blocks-scope` | JVM · JS | 2.13 · 3.x | Result of running a scope's finalizers, including any cleanup errors |
100
89
 
101
- ### Example: ConfigSource Composition with Provenance
90
+ ### Dependency Injection
102
91
 
103
- The snippet below uses Scala 3 syntax.
92
+ | Block | Artifact | Platform | Scala | Description |
93
+ |-------|----------|----------|-------|-------------|
94
+ | [Wire](./reference/resource-management/wire.md) | `zio-blocks-scope` | JVM · JS | 2.13 · 3.x | Compile-time safe recipes for constructing a service and its dependencies |
95
+ | [Context](./reference/context.md) | `zio-blocks-context` | JVM · JS | 2.13 · 3.x | Type-indexed heterogeneous collections |
104
96
 
105
- ```scala
106
- import zio.blocks.config._
107
- import zio.blocks.scope.Unscoped
97
+ ### Configuration & Feature Flags
108
98
 
109
- val defaults = ConfigSource.fromMap(Map("app.host" -> "localhost"), "defaults")
110
- val env = ConfigSource.fromMap(Map("app.port" -> "8080"), "env")
111
- val source = env.orElse(defaults).prefix("app")
99
+ | Block | Artifact | Platform | Scala | Description |
100
+ |-------|----------|----------|-------|-------------|
101
+ | [Configuration](./reference/config/index.md) | `zio-blocks-config` | JVM · JS | 2.13 · 3.x | Typed configuration loading, feature flags, and rollout rules |
102
+ | [Config YAML](./reference/config/formats.md) | `zio-blocks-config-yaml` | JVM · JS | 2.13 · 3.x | YAML source adapter for `ConfigSource` |
103
+ | [Config JSON](./reference/config/formats.md) | `zio-blocks-config-json` | JVM · JS | 2.13 · 3.x | JSON source adapter for `ConfigSource` |
104
+ | [Config HOCON](./reference/config/formats.md) | `zio-blocks-config-hocon` | JVM · JS | 2.13 · 3.x | HOCON source adapter for `ConfigSource` |
112
105
 
113
- final case class AppConfig(host: String, port: Int) derives Schema, Unscoped
106
+ ### Web & HTTP
114
107
 
115
- val loaded = Config.loadWithProvenance[AppConfig](source)
116
- val hostProv = loaded.map(_.provenanceOf("host"))
117
- ```
108
+ | Block | Artifact | Platform | Scala | Description |
109
+ |-------|----------|----------|-------|-------------|
110
+ | [MediaType](./reference/media-type.md) | `zio-blocks-mediatype` | JVM · JS | 2.13 · 3.x | Type-safe IANA media types with 2,600+ predefined types |
111
+ | [HTTP Model](./reference/http-model/index.md) | `zio-blocks-http-model` | JVM · JS | 2.13 · 3.x | Pure HTTP data model with URL parsing, headers, cookies, and forms |
112
+ | [HTTP Model Schema](./reference/http-model/schema.md) | `zio-blocks-http-model-schema` | JVM · JS | 2.13 · 3.x | Schema-based typed access to the HTTP model |
113
+ | [Endpoint](./reference/endpoint/index.md) | `zio-blocks-endpoint` | JVM · JS | 2.13 · 3.x | Type-safe HTTP endpoint descriptors with composable codecs and typed auth |
114
+ | [OpenAPI](./reference/openapi.md) | `zio-blocks-openapi` | JVM · JS | 2.13 · 3.x | Type-safe OpenAPI 3.1 specification generation and rendering |
115
+ | [JWT](./reference/jwt.md) | `zio-blocks-jwt` | JVM · JS | 2.13 · 3.x | Zero-dependency JWT signing and verification with HMAC, RSA, ECDSA and EdDSA support |
116
+ | [HTML](./reference/html.md) | `zio-blocks-html` | JVM · JS | 2.13 · 3.x | Type-safe HTML templating with XSS protection |
117
+ | [Datastar](./reference/datastar/index.md) | `zio-blocks-datastar` | JVM · JS | 3.x | Typed Datastar attribute and signal DSL, plus the SSE events that patch a live page |
118
+ | [HTMX](./reference/htmx/index.md) | `zio-blocks-http-htmx` | JVM · JS | 3.x | Typed HTMX DSL for compile-time-checked HTMX attributes |
118
119
 
119
- ### Example: Rollout DSL
120
+ ### Data Types
120
121
 
121
- ```scala
122
- import zio.blocks.config._
122
+ | Block | Artifact | Platform | Scala | Description |
123
+ |-------|----------|----------|-------|-------------|
124
+ | [Chunk](./reference/chunk.md) | `zio-blocks-chunk` | JVM · JS | 2.13 · 3.x | High-performance immutable indexed sequences with zero-boxing builders |
125
+ | [Maybe](./reference/maybe.md) | `zio-blocks-maybe` | JVM · JS | 2.13 · 3.x | Low-allocation optional values backed by `null` |
126
+ | [Combinators](./reference/combinators.md) | `zio-blocks-combinators` | JVM · JS | 2.13 · 3.x | Compile-time composition and decomposition of tuples, eithers, and unions |
123
127
 
124
- val bucket = Rollout.bucketFor("user-123")
125
- val choice = Rollout.select("true@prod/50%;false", "prod", bucket)
126
- ```
128
+ ### Concurrency
127
129
 
128
- `prod/50%` applies the choice to the `prod` path and enables it for roughly half of the `prod` buckets. The trailing `false` entry is the catch-all fallback for every non-matching case.
130
+ | Block | Artifact | Platform | Scala | Description |
131
+ |-------|----------|----------|-------|-------------|
132
+ | [Async](./reference/async.md) | `zio-blocks-async` | JVM · JS | 2.13 · 3.x | Zero-allocation asynchronous effect type with direct-style `await` |
133
+ | [Mux](./reference/mux.mdx) | `zio-blocks-mux` | JVM · JS | 2.13 · 3.x | Thread-safe multiplexer for HTTP/2, QUIC, and WebSocket-style protocols |
134
+ | [RingBuffer](./reference/ringbuffer/index.mdx) | `zio-blocks-ringbuffer` | JVM · JS | 2.13 · 3.x | Lock-free bounded ring buffers (SPSC, SPMC, MPSC, MPMC) |
129
135
 
130
- ### File Format Adapters
136
+ ### Streams
131
137
 
132
- - **YAML**: `ConfigSource.fromYaml(...)` (requires `config-yaml` dependency and `import zio.blocks.config.yaml._`)
133
- - **JSON**: `ConfigSource.fromJson(...)` (requires `config-json` dependency and `import zio.blocks.config.json._`)
134
- - **HOCON**: `ConfigSource.fromHocon(...)` (requires `config-hocon` dependency and `import zio.blocks.config.hocon._`)
138
+ | Block | Artifact | Platform | Scala | Description |
139
+ |-------|----------|----------|-------|-------------|
140
+ | [Streams](./reference/streams/index.md) | `zio-blocks-streams` | JVM · JS | 2.13 · 3.x | Pull-based streaming with typed errors, zero boxing, and synchronous or asynchronous execution |
135
141
 
136
- ## Core Principles
142
+ ### Telemetry
137
143
 
138
- - **Zero Lock-In**: No dependencies on ZIO, Cats Effect, or any effect system. Use with whatever stack you prefer.
139
- - **Modular**: Each block is a separate artifact. Import only what you need.
140
- - **Cross-Platform**: Full support for JVM and Scala.js.
141
- - **Cross-Version**: Full support for Scala 2.13 and Scala 3.x with source compatibility—adopt Scala 3 on your timeline, not ours.
142
- - **High Performance**: Optimized implementations that avoid boxing, minimize allocations, and leverage platform-specific features.
143
- - **Type Safety**: Leverage Scala's type system for correctness without runtime overhead.
144
+ | Block | Artifact | Platform | Scala | Description |
145
+ |-------|----------|----------|-------|-------------|
146
+ | [Telemetry](./reference/telemetry/index.md) | `zio-blocks-telemetry` | JVM · JS | 2.13 · 3.x | Zero-dependency OpenTelemetry-aligned tracing, logging, and metrics |
147
+ | [OTLP Export](./reference/telemetry/otel/index.md) | `zio-blocks-telemetry-otel` | JVM | 2.13 · 3.x | OTLP exporters bridging telemetry signals to an OpenTelemetry collector |
148
+
149
+ ### Persistence
150
+
151
+ | Block | Artifact | Platform | Scala | Description |
152
+ |-------|----------|----------|-------|-------------|
153
+ | [SQL Module](./reference/sql/index.md) | `zio-blocks-sql` | JVM · JS | 3.x | Type-safe JDBC wrapper with schema-derived codecs and a CRUD repository |
154
+ | [ZIO Integration](./reference/sql-zio.md) | `zio-blocks-sql-zio` | JVM | 3.x | ZIO integration with `ZIO.attemptBlocking` and `ZLayer` |
155
+ | [Data Migration](./reference/data-migration.md) | `zio-blocks-data-migration` | JVM · JS | 3.x | Typed, online database schema migrations in three execution models, with no hand-written SQL |
156
+ | [Projection](./reference/projection.md) | `zio-blocks-projection` | JVM | 3.x | Event-sourced projections with per-entity SQLite storage |
157
+
158
+ ### Tooling & Codegen
159
+
160
+ | Block | Artifact | Platform | Scala | Description |
161
+ |-------|----------|----------|-------|-------------|
162
+ | [Code Generation](./reference/codegen/index.md) | `zio-blocks-codegen` | JVM | 2.13 · 3.x | Generic Scala code generation IR and emitter |
163
+ | [Docs](./reference/docs.md) | `zio-blocks-markdown` | JVM · JS | 2.13 · 3.x | GitHub Flavored Markdown parsing, rendering, and programmatic construction |
164
+ | [Smithy](./reference/smithy.md) | `zio-blocks-smithy` | JVM | 2.13 · 3.x | Smithy IDL parser and AST library for API modeling |
144
165
 
145
166
  ---
146
167
 
@@ -180,7 +201,7 @@ val thriftCodec = Schema[Person].derive(ThriftFormat) // Thrift
180
201
 
181
202
  ### Key Features
182
203
 
183
- - **Universal Data Formats**: JSON, Avro, TOON (compact LLM-optimized format), MessagePack, Thrift, and BSON, with Protobuf planned.
204
+ - **Universal Data Formats**: JSON built in, plus Avro, BSON, CSV, MessagePack, Thrift, TOON, XML, and YAML as separate modules, with Protobuf planned.
184
205
  - **High Performance**: Register-based design stores primitives directly in byte arrays, enabling zero-allocation serialization.
185
206
  - **Reflective Optics**: Type-safe lenses, prisms, and traversals with embedded structural metadata.
186
207
  - **Automatic Derivation**: Derive type class instances for any type with a schema.
@@ -188,17 +209,12 @@ val thriftCodec = Schema[Person].derive(ThriftFormat) // Thrift
188
209
  ### Installation
189
210
 
190
211
  ```scala
191
- libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.51"
192
-
193
- // Optional format modules:
194
- libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.51"
195
- libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.51"
196
- libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.51"
197
- libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.51"
198
- libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.51"
212
+ libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.56"
199
213
  ```
200
214
 
201
- ### Example: Optics
215
+ See the [Meta Programming](#meta-programming) rows above for the optional format modules.
216
+
217
+ ### Example
202
218
 
203
219
  ```scala
204
220
  import zio.blocks.schema._
@@ -218,64 +234,10 @@ val person = Person("Alice", 30, Address("123 Main St", "Springfield"))
218
234
  val updated = Person.age.replace(person, 31)
219
235
  ```
220
236
 
221
- ---
222
-
223
- ## Chunk
224
-
225
- A high-performance, immutable indexed sequence optimized for the patterns common in streaming, parsing, and data processing. Think of it as `Vector` but faster for the operations that matter most.
226
-
227
- ### Why Chunk?
228
-
229
- Standard library collections make trade-offs that aren't ideal for streaming and binary data processing:
230
-
231
- - `Vector` is general-purpose but not optimized for concatenation patterns
232
- - `Array` is mutable and boxes primitives when used generically
233
- - `List` has O(n) random access
234
-
235
- Chunk is designed for:
236
-
237
- - **Fast concatenation** via balanced trees (Conc-Trees)
238
- - **Zero-boxing** for primitive types with specialized builders
239
- - **Efficient slicing** without copying
240
- - **Seamless interop** with `ByteBuffer`, `Array`, and standard collections
241
-
242
- ### Key Features
243
-
244
- - **Specialized Builders**: Dedicated builders for `Byte`, `Int`, `Long`, `Double`, etc. avoid boxing overhead.
245
- - **Balanced Concatenation**: Based on Conc-Trees for O(log n) concatenation while maintaining O(1) indexed access.
246
- - **Bit Operations**: First-class support for bit-level operations, bit chunks backed by `Byte`, `Int`, or `Long` arrays.
247
- - **NonEmptyChunk**: A statically-guaranteed non-empty variant for APIs that require at least one element.
248
- - **Full Scala Collection Integration**: Implements `IndexedSeq` for seamless interop.
249
-
250
- ### Installation
251
-
252
- ```scala
253
- libraryDependencies += "dev.zio" %% "zio-blocks-chunk" % "0.0.51"
254
- ```
255
-
256
- ### Example
257
-
258
- ```scala
259
- import zio.blocks.chunk._
260
-
261
- // Create chunks
262
- val bytes = Chunk[Byte](1, 2, 3, 4, 5)
263
- val moreBytes = Chunk.fromArray(Array[Byte](6, 7, 8))
264
-
265
- // Efficient concatenation (O(log n))
266
- val combined = bytes ++ moreBytes
267
-
268
- // Zero-copy slicing
269
- val slice = combined.slice(2, 6)
237
+ ### Learn More
270
238
 
271
- // Bit operations
272
- val bits = bytes.asBitsByte
273
- val masked = bits & Chunk.fill(bits.length)(true)
274
-
275
- // NonEmptyChunk for type-safe non-emptiness
276
- val nonEmpty = NonEmptyChunk(1, 2, 3)
277
- val head: Int = nonEmpty.head // Always safe, no Option needed
278
- ```
239
+ - [Schema reference](./reference/schema/index.md) — the full API surface, from `Reflect` and `Binding` through optics, validation, and schema evolution
240
+ - [Migrating from ZIO Schema](./guides/zio-schema-migration.md) — a step-by-step port from ZIO Schema 1.x
279
241
 
280
242
  ---
281
243
 
@@ -339,10 +301,10 @@ Scope.global.scoped { scope =>
339
301
  ### Installation
340
302
 
341
303
  ```scala
342
- libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.51"
304
+ libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.56"
343
305
  ```
344
306
 
345
- ### Example: Basic Resource Management
307
+ ### Example
346
308
 
347
309
  ```scala
348
310
  import zio.blocks.scope.*
@@ -366,279 +328,77 @@ Scope.global.scoped { scope =>
366
328
  // Database closed
367
329
  ```
368
330
 
369
- ### Example: Dependency Injection
370
-
371
- ```scala
372
- import zio.blocks.scope.*
373
-
374
- case class Config(dbUrl: String)
375
- class Database(config: Config) extends AutoCloseable { ... }
376
- class UserRepo(db: Database) { ... }
377
- class UserService(repo: UserRepo) extends AutoCloseable { ... }
331
+ ### Learn More
378
332
 
379
- // Resource.from auto-wires the dependency graph
380
- // Only provide leaf values - concrete classes are auto-wired
381
- val serviceResource: Resource[UserService] = Resource.from[UserService](
382
- Wire(Config("jdbc:postgresql://localhost/mydb"))
383
- )
384
-
385
- serviceResource.use(_.createUser("Alice"))
386
- // Cleanup runs LIFO: UserService → Database (UserRepo has no cleanup)
387
- ```
388
-
389
- ### Example: Nested Scopes with Transactions
390
-
391
- ```scala
392
- Scope.global.scoped { connScope =>
393
- import connScope.*
394
-
395
- val conn = allocate(Resource.fromAutoCloseable(new Connection))
396
-
397
- // Transaction lives in child scope - cleaned up before connection
398
- val result: String = scoped { txScope =>
399
- import txScope.*
400
- val c = lower(conn)
401
- val tx = $(c)(_.beginTransaction()).allocate
402
- $(tx)(_.execute("INSERT INTO users VALUES (1, 'Alice')"))
403
- $(tx)(_.commit())
404
- "success"
405
- }
406
- // Transaction closed here, connection still open
407
-
408
- println(result)
409
- }
410
- // Connection closed here
411
- ```
412
-
413
- ### Getting Started
414
-
415
- New to Scope? Check out the [Scope Tutorial](./guides/compile-time-resource-safety-with-scope.md) for a comprehensive step-by-step guide that walks you through the concepts, patterns, and real-world examples. The tutorial is designed for newcomers and covers everything from basic resource management to advanced dependency injection.
416
-
417
- For detailed API documentation, see the [Scope Reference](./reference/resource-management/scope.md).
333
+ - [Compile-Time Resource Safety with Scope](./guides/compile-time-resource-safety-with-scope.md) — the step-by-step tutorial, from basic resource management through dependency injection
334
+ - [Resource Management reference](./reference/resource-management/index.md) — `Scope`, `Resource`, `Wire`, `Unscoped`, and finalization order
418
335
 
419
336
  ---
420
337
 
421
- ## Docs
422
-
423
- A zero-dependency GitHub Flavored Markdown library for parsing, rendering, and programmatic construction of Markdown documents.
424
-
425
- ### Why Docs?
426
-
427
- Generating documentation, README files, or any Markdown content programmatically is common but error-prone with string concatenation. Docs provides:
428
-
429
- - **Type-safe AST**: Build Markdown documents with compile-time guarantees
430
- - **Compile-time validation**: The `md"..."` interpolator validates syntax at compile time
431
- - **Multiple renderers**: Output to Markdown, HTML, or ANSI terminal
432
- - **Round-trip parsing**: Parse Markdown to AST and render back to Markdown
338
+ ## Async
433
339
 
434
- ### Key Features
340
+ A lightweight, zero-dependency asynchronous effect type. A ready `Async[A]` *is*
341
+ an `A`, so synchronous code composed with `map` / `flatMap` allocates nothing on
342
+ the happy path while still suspending on genuinely asynchronous work.
435
343
 
436
- - **GFM Compliant**: Tables, strikethrough, autolinks, task lists, fenced code blocks
437
- - **Zero Dependencies**: Only depends on zio-blocks-chunk
438
- - **Cross-Platform**: Full support for JVM and Scala.js
439
- - **Type-Safe Interpolator**: `md"# Hello $name"` with compile-time validation
440
- - **Multiple Renderers**: Markdown, HTML (full document or fragment), ANSI terminal
344
+ ### The Problem
441
345
 
442
- ### Installation
346
+ Asynchronous Scala forces a choice between two costs. `Future` allocates for
347
+ every combinator and needs an `ExecutionContext` threaded everywhere, even when
348
+ the value is already available. Full effect systems avoid that but ask you to
349
+ adopt a runtime, a set of type classes, and a programming model across your
350
+ whole codebase—a heavy price for a library that only occasionally suspends.
443
351
 
444
- ```scala
445
- libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.51"
446
- ```
352
+ ### The Solution
447
353
 
448
- ### Example
354
+ `Async[A]` is a value, not a wrapper. When the result is already known, the
355
+ representation *is* the result, so composing ready values costs nothing:
449
356
 
450
357
  ```scala
451
- import zio.blocks.docs._
452
-
453
- // Parse Markdown
454
- val doc = Parser.parse("# Hello\n\nThis is **bold** text.")
455
- // Right(Doc(Chunk(Heading(H1, "Hello"), Paragraph(...))))
456
-
457
- // Render to HTML
458
- val html = doc.map(_.toHtml)
459
- // Full HTML5 document with <html>, <head>, <body>
460
-
461
- // Render to HTML fragment (just the content)
462
- val fragment = doc.map(_.toHtmlFragment)
463
- // "<h1>Hello</h1><p>This is <strong>bold</strong> text.</p>"
464
-
465
- // Render to terminal with ANSI colors
466
- val terminal = doc.map(_.toTerminal)
467
-
468
- // Use the type-safe interpolator
469
- val name = "World"
470
- val greeting = md"# Hello $name"
471
- // Doc containing: Heading(H1, Chunk(Text("Hello World")))
472
-
473
- // Build documents programmatically
474
- import zio.blocks.chunk.Chunk
475
-
476
- val manual = Doc(Chunk(
477
- Block.Heading(HeadingLevel.H1, Chunk(Inline.Text("API Reference"))),
478
- Block.Paragraph(Chunk(
479
- Inline.Text("See "),
480
- Inline.Link(Chunk(Inline.Text("docs")), "/docs", None),
481
- Inline.Text(" for details.")
482
- ))
483
- ))
358
+ import zio.blocks.async._
484
359
 
485
- // Render back to Markdown
486
- val markdown = Renderer.render(manual)
360
+ // Constructors collapse to bare values; transformers inline with no allocation
361
+ val computed: Int =
362
+ Async.succeed(20).map(_ + 1).flatMap(n => Async.succeed(n * 2)).block
363
+ // computed: Int = 42
487
364
  ```
488
365
 
489
- ### Supported GFM Features
490
-
491
- | Feature | Supported |
492
- |---------|-----------|
493
- | Headings (ATX) | ✅ |
494
- | Paragraphs | ✅ |
495
- | Emphasis/Strong | ✅ |
496
- | Code (inline & fenced) | ✅ |
497
- | Links & Images | ✅ |
498
- | Lists (bullet, ordered, task) | ✅ |
499
- | Blockquotes | ✅ |
500
- | Tables | ✅ |
501
- | Strikethrough | ✅ |
502
- | Autolinks | ✅ |
503
- | Hard/Soft breaks | ✅ |
504
- | HTML (passthrough) | ✅ |
505
-
506
- ### Limitations
507
-
508
- - **No frontmatter**: YAML/TOML headers are not parsed
509
- - **No HTML entity decoding**: `&amp;` stays as-is
510
- - **No footnotes**: GFM footnote extension not supported
511
- - **No emoji shortcodes**: `:smile:` not converted to emoji
512
-
513
- ---
514
-
515
- ## TypeId
516
-
517
- Compile-time type identity with rich metadata. TypeId captures comprehensive information about Scala types including name, owner, type parameters, variance, parent types, and annotations.
518
-
519
366
  ### Key Features
520
367
 
521
- - **Rich Metadata**: Captures type name, owner, kind (class/trait/object/enum), parent types, and annotations
522
- - **Higher-Kinded Support**: Works with proper types and type constructors via `AnyKind`
523
- - **Subtype Checking**: Runtime subtype/supertype relationship checks using compile-time extracted information
524
- - **Cross-Platform**: Works identically on JVM and Scala.js
368
+ - **Zero Allocation on the Happy Path**: A completed `Async[A]` is represented as the `A` itself; `map` and `flatMap` over ready values allocate nothing.
369
+ - **Direct-Style `await`**: `Async.async { ... }` rewrites `.await` calls at compile time into a non-blocking `flatMap` chain—straight-line code, asynchronous execution.
370
+ - **No Runtime to Adopt**: No `ExecutionContext` to thread, no type class hierarchy, no effect system dependency.
371
+ - **Interop Built In**: Bridges to `Future` and `CompletionStage`, plus `Async.promise` for callback-based APIs.
525
372
 
526
373
  ### Installation
527
374
 
528
375
  ```scala
529
- libraryDependencies += "dev.zio" %% "zio-blocks-typeid" % "0.0.51"
376
+ libraryDependencies += "dev.zio" %% "zio-blocks-async" % "0.0.56"
530
377
  ```
531
378
 
532
379
  ### Example
533
380
 
534
- ```scala
535
- import zio.blocks.typeid._
536
-
537
- // Get TypeId for any type
538
- val listId = TypeId.of[List[Int]]
539
- println(listId.name) // "List"
540
- println(listId.fullName) // "scala.collection.immutable.List"
541
- println(listId.arity) // 1 (type constructor)
542
-
543
- // Check type relationships
544
- trait Animal
545
- case class Dog(name: String) extends Animal
546
-
547
- val dogId = TypeId.of[Dog]
548
- val animalId = TypeId.of[Animal]
549
- dogId.isSubtypeOf(animalId) // true
550
-
551
- // Access structural information
552
- dogId.isCaseClass // true
553
- dogId.isSealed // false
554
- ```
555
-
556
- ---
557
-
558
- ## Context
559
-
560
- A type-indexed heterogeneous collection that stores values by their types with compile-time type safety.
561
-
562
- ### Key Features
563
-
564
- - **Type-Safe Lookup**: Retrieve values by type with compile-time guarantees
565
- - **Covariant**: `Context[Specific]` is a subtype of `Context[General]`
566
- - **Subtype Matching**: Lookup by supertype finds matching subtypes
567
- - **Cached Access**: O(1) subsequent lookups after first retrieval
568
-
569
- ### Installation
570
-
571
- ```scala
572
- libraryDependencies += "dev.zio" %% "zio-blocks-context" % "0.0.51"
573
- ```
574
-
575
- ### Example
381
+ Write straight-line asynchronous code with `Async.async` and `.await`, rewritten
382
+ at compile time into a non-blocking `flatMap` chain:
576
383
 
577
384
  ```scala
578
- import zio.blocks.context._
579
-
580
- case class Config(debug: Boolean)
581
- case class Metrics(count: Int)
582
-
583
- // Create a context with multiple values
584
- val ctx: Context[Config & Metrics] = Context(
585
- Config(debug = true),
586
- Metrics(count = 42)
587
- )
588
-
589
- // Retrieve values by type
590
- val config: Config = ctx.get[Config]
591
- val metrics: Metrics = ctx.get[Metrics]
592
-
593
- // Add or update values
594
- val updated = ctx.update[Metrics](m => m.copy(count = m.count + 1))
595
-
596
- // Combine contexts
597
- val ctx1 = Context(Config(false))
598
- val ctx2 = Context(Metrics(0))
599
- val merged: Context[Config & Metrics] = ctx1 ++ ctx2
600
- ```
601
-
602
- ---
603
-
604
- ## Ring Buffer
605
-
606
- High-performance, bounded ring buffers for inter-thread communication. Four lock-free variants cover every producer/consumer pattern (SPSC, MPSC, SPMC, MPMC).
607
-
608
- ### Why Ring Buffer?
609
-
610
- Standard `java.util.concurrent` queues use node allocation (`ConcurrentLinkedQueue`) or coarse locking (`ArrayBlockingQueue`). Ring buffers avoid both:
611
-
612
- - **Zero allocation** on the hot path—pre-allocated circular array
613
- - **Lock-free** on the fast path—CAS or release/acquire semantics only
614
- - **Cache-friendly**—sequential memory access with 128-byte padding between producer/consumer fields
615
-
616
- ### Key Features
617
-
618
- - **Four concurrency patterns**: SPSC, SPMC, MPSC, MPMC—pick the most constrained variant for your use case
619
- - **Cross-platform**: Same API on JVM and Scala.js (JS uses sequential implementations)
385
+ import zio.blocks.async._
620
386
 
621
- ### Installation
387
+ def fetch(id: Int): Async[String] = Async.succeed(s"item-$id")
622
388
 
623
- ```scala
624
- libraryDependencies += "dev.zio" %% "zio-blocks-ringbuffer" % "0.0.51"
389
+ val program: Async[Int] =
390
+ Async.async {
391
+ val a = fetch(1).await
392
+ val b = fetch(2).await
393
+ (a + b).length
394
+ }
625
395
  ```
626
396
 
627
- ### Example
397
+ ### Learn More
628
398
 
629
- ```scala
630
- import zio.blocks.ringbuffer._
631
-
632
- // SPSC: fastest, for dedicated producer-consumer pairs
633
- val spsc = SpscRingBuffer[String](1024)
634
- spsc.offer("hello") // true
635
- spsc.take() // "hello"
636
-
637
- // MPMC: general-purpose, any number of threads
638
- val mpmc = MpmcRingBuffer[String](1024)
639
- mpmc.offer("hello") // false if full
640
- mpmc.take() // null if empty
641
- ```
399
+ - [Getting Started with Async](./guides/async-getting-started.md) — create, compose, and run async effects
400
+ - [Async reference](./reference/async.md) — the full API, including `zip`, `catchAll`, `collectAll`, the `Async.promise` callback bridge, and `Future` / `CompletionStage` interop
401
+ - [`async-examples`](https://github.com/zio/zio-blocks/blob/main/async-examples/src/main/scala/async/AsyncShowcaseExample.scala) — a single-file order-fulfillment demo (`sbt "++3.9.0; async-examples/run"`)
642
402
 
643
403
  ---
644
404
 
@@ -678,11 +438,10 @@ val frag = sql"SELECT * FROM user WHERE email = ${"alice@example.com"}"
678
438
  ### Installation
679
439
 
680
440
  ```scala
681
- // Core module (Scala 3, JVM + Scala.js)
682
- libraryDependencies += "dev.zio" %% "zio-blocks-sql" % "0.0.51"
441
+ libraryDependencies += "dev.zio" %% "zio-blocks-sql" % "0.0.56"
683
442
 
684
- // ZIO integration (Scala 3, JVM only)
685
- libraryDependencies += "dev.zio" %% "zio-blocks-sql-zio" % "0.0.51"
443
+ // Optional ZIO integration
444
+ libraryDependencies += "dev.zio" %% "zio-blocks-sql-zio" % "0.0.56"
686
445
  ```
687
446
 
688
447
  ### Example
@@ -709,58 +468,10 @@ val program = transactor.transact:
709
468
  sql"SELECT * FROM product WHERE price < ${15.0}".query[Product]
710
469
  ```
711
470
 
712
- ---
713
-
714
- ## Streams (In Development)
715
-
716
- A pull-based streaming library for composable, backpressure-aware data processing.
471
+ ### Learn More
717
472
 
718
- ```scala
719
- import zio.blocks.streams._
720
-
721
- // Coming soon: efficient pull-based streams
722
- // that compose with any effect system
723
- ```
724
-
725
- ---
726
-
727
- ## Async
728
-
729
- A lightweight, zero-dependency asynchronous effect type. A ready `Async[A]` *is*
730
- an `A`, so synchronous code composed with `map` / `flatMap` allocates nothing on
731
- the happy path while still suspending on genuinely asynchronous work.
732
-
733
- ```scala
734
- import zio.blocks.async._
735
-
736
- // Constructors collapse to bare values; transformers inline with no allocation
737
- val computed: Int =
738
- Async.succeed(20).map(_ + 1).flatMap(n => Async.succeed(n * 2)).block
739
- // computed: Int = 42
740
- ```
741
-
742
- Write straight-line asynchronous code with `Async.async` and `.await`, rewritten
743
- at compile time into a non-blocking `flatMap` chain:
744
-
745
- ```scala
746
- import zio.blocks.async._
747
-
748
- def fetch(id: Int): Async[String] = Async.succeed(s"item-$id")
749
-
750
- val program: Async[Int] =
751
- Async.async {
752
- val a = fetch(1).await
753
- val b = fetch(2).await
754
- (a + b).length
755
- }
756
- ```
757
-
758
- See the [Async reference](./reference/async.md) for the full API, including
759
- `zip`, `catchAll`, `collectAll`, the `Async.promise` callback bridge, and
760
- `Future` / `CompletionStage` interop.
761
-
762
- **Runnable tour:** the [`async-examples`](https://github.com/zio/zio-blocks/blob/main/async-examples/src/main/scala/async/AsyncShowcaseExample.scala)
763
- module is a single-file order-fulfillment demo (`sbt "++3.8.3; async-examples/run"`).
473
+ - [SQL reference](./reference/sql/index.md) — `DbCodec`, `Frag`, `Table`, `Repo`, `Transactor`, dialects, and DDL generation
474
+ - [Query DSL guide](./guides/query-dsl-reified-optics.md) — a four-part series building a type-safe query language on reified optics
764
475
 
765
476
  ---
766
477
 
@@ -779,102 +490,32 @@ ZIO Blocks works with any Scala stack:
779
490
 
780
491
  Each block has zero dependencies on effect systems. Use the blocks directly, or integrate them with your effect system of choice.
781
492
 
782
- ## Scala & Platform Support
783
-
784
- 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.
785
-
786
- | Platform | Schema | Chunk | Scope | Docs | TypeId | Context | Ring Buffer | Streams | SQL | Async |
787
- |----------|--------|-------|-------|------|--------|---------|-------------|---------|-----|-------|
788
- | JVM | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | ✅ | ✅ |
789
- | Scala.js | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | 🚧 | ✅ | ✅ |
790
-
791
- ## Documentation
792
-
793
- ### Core Schema Concepts
794
-
795
- - [Schema](./reference/schema/schema.md) - Core schema definitions and derivation
796
- - [Allows](./reference/schema/allows.md) - Compile-time structural grammar constraints
797
- - [Reflect](./reference/schema/reflect.md) - Structural reflection API
798
- - [Binding](./reference/schema/binding.md) - Runtime constructors and deconstructors
799
- - [BindingResolver](reference/schema/binding-resolver.md) - Binding lookup and schema rebinding
800
- - [Registers](./reference/schema/registers.md) - Register-based primitive storage
801
-
802
- ### Optics & Navigation
803
-
804
- - [Optics](./reference/schema/optics.md) - Lenses, prisms, and traversals
805
- - [SchemaExpr](./reference/schema/schema-expr.md) - Schema-aware expressions for queries and validation
806
- - [Path Interpolator](./reference/schema/path-interpolator.md) - Type-safe path construction
807
- - [DynamicValue](./reference/schema/dynamic-value.md) - Schema-less dynamic values
808
- - [DynamicSchema](./reference/schema/dynamic-schema.md) - Type-erased schemas for validation and cross-process transport
809
-
810
- ### Serialization
811
-
812
- - [Codec & Format](./reference/schema/codec.md) - Codec, Format, BinaryCodec & TextCodec
813
- - [JSON](./reference/schema/built-in-codecs/json/index.md) - JSON codec and parsing
814
- - [JsonPatch](./reference/schema/built-in-codecs/json/json-patch.md) - Diff and patch JSON values
815
- - [JsonDiffer](./reference/schema/built-in-codecs/json/json-differ.md) - Compute minimal diffs between JSON values
816
- - [JSON Schema](./reference/schema/built-in-codecs/json/json-schema.md) - JSON Schema generation and validation
817
- - [XML Codec](./reference/schema/built-in-codecs/xml.md) - Zero-dependency XML serialization with fluent navigation and patching
818
- - [CSV Codec](./reference/schema/built-in-codecs/csv.md) - RFC 4180-compliant CSV serialization with schema-driven derivation
819
- - [BSON Codec](./reference/schema/built-in-codecs/bson.md) - MongoDB-compatible BSON serialization with native type support
820
- - [Avro Codec](./reference/schema/built-in-codecs/avro.md) - Apache Avro binary serialization with automatic schema generation
821
- - [MessagePack Codec](./reference/schema/built-in-codecs/messagepack.md) - Compact binary serialization with optimized streaming
822
- - [Thrift Codec](./reference/schema/built-in-codecs/thrift.md) - Apache Thrift binary serialization with TBinaryProtocol
823
- - [YAML Codec](./reference/schema/built-in-codecs/yaml.md) - Human-readable YAML serialization with JSON interop
824
- - [TOON Codec](./reference/schema/built-in-codecs/toon.md) - Compact token-oriented notation 30-60% smaller than JSON, optimized for LLM prompts
825
- - [Built-in Codecs](./reference/schema/built-in-codecs/index.md) - Overview of all supported serialization formats
826
- - [Extension Syntax](./reference/schema/syntax.md) - `.toJson`, `.fromJson`, and more
827
-
828
- ### Data Operations
829
-
830
- - [Patching](./reference/schema/patch.md) - Serializable data transformations
831
- - [SchemaError](./reference/schema/schema-error.md) - Structured error type for schema operations
832
- - [Validation](./reference/schema/validation.md) - Data validation and error handling
833
- - [Schema Evolution](reference/schema/schema-evolution/index.md) - One-way and bidirectional type-safe conversions
834
- - [Into](reference/schema/schema-evolution/into.md) - One-way conversion with validation
835
- - [As](reference/schema/schema-evolution/as.md) - Bidirectional round-trip conversion
836
-
837
- ### Other Blocks
838
-
839
- - [Chunk](./reference/chunk.md) - High-performance immutable sequences
840
- - [Maybe](./reference/maybe.md) - Low-allocation optional values using null
841
- - [Mux](./reference/mux.mdx) - Thread-safe multiplexer for ID-multiplexed protocols (HTTP/2, QUIC, WebSockets) with lock-free per-stream queues
842
- - [Scope](./reference/resource-management/scope.md) - Compile-time safe resource management and DI
843
- - [Wire](./reference/resource-management/wire.md) - Recipes for constructing services and dependencies
844
- - [TypeId](./reference/typeid.md) - Type identity and metadata
845
- - [Context](./reference/context.md) - Type-indexed heterogeneous collections
846
- - [Combinators](./reference/combinators.md) - Compile-time composition and decomposition of values (Tuples, Eithers, Unions)
847
- - [Docs (Markdown)](./reference/docs.md) - Markdown parsing and rendering
848
- - [HTML](./reference/html.md) - Type-safe HTML templating with XSS protection
849
- - [HTMX](./reference/htmx/index.md) - Typed HTMX DSL for safe, compile-time HTMX attribute declarations
850
- - [HTTP Model](./reference/http-model/index.md) - Pure HTTP data model with URL parsing, headers, cookies, and forms
851
- - [Endpoint](./reference/endpoint/index.md) - Pure, type-safe HTTP endpoint descriptors with composable codecs and typed auth
852
- - [MediaType](./reference/media-type.md) - Type-safe IANA media types
853
- - [Smithy](./reference/smithy.md) - Smithy IDL parser and AST library for API modeling
854
- - [OpenAPI](./reference/openapi.md) - Type-safe OpenAPI 3.1 specification generation and rendering
855
- - [Ring Buffer](./reference/ringbuffer/index.mdx) - High-performance bounded ring buffers
856
- - [Stream](./reference/streams/stream.md) - Lazy, pull-based, type-safe streaming with resource safety
857
- - [Pipeline](./reference/streams/pipeline.md) - Reusable, composable stream transformations
858
- - [Sink](./reference/streams/sink.md) - Stream consumers that produce typed results
859
- - [Reader](./reference/streams/reader.md) - Low-level pull-based sources for streaming
860
- - [Writer](./reference/streams/writer.md) - Low-level push-based sinks for streaming
861
- - [SQL](./reference/sql/index.md) - Type-safe JDBC wrapper with schema-derived codecs and repository
862
- - [DbCodec](./reference/sql/db-codec.md) - Bidirectional codec between Scala values and database columns
863
- - [Frag](./reference/sql/frag.md) - Immutable SQL fragment with safe parameterization via `sql"..."` interpolator
864
- - [Table](./reference/sql/table.md) - Schema-derived table metadata binding Scala types to database tables
865
- - [Repo](./reference/sql/repo.md) - Type-safe CRUD repository with pre-built SQL operations
866
- - [Transactor](./reference/sql/transactor.md) - Connection lifecycle and transaction management
867
- - [DbCon](./reference/sql/db-con.md) - Implicit context carrying connection, dialect, and logger
868
- - [DbTx](./reference/sql/db-tx.md) - Transactional scope marker extending `DbCon`
869
- - [SqlDialect](./reference/sql/sql-dialect.md) - Database-specific SQL rendering (PostgreSQL, SQLite)
870
- - [TransactorZIO](./reference/sql/transactor-zio.md) - ZIO integration with `ZIO.attemptBlocking` and `ZLayer`
871
- - [Async](./reference/async.md) - Zero-allocation asynchronous effect type with direct-style `await`
872
-
873
- ### Guides
874
-
875
- - [Getting Started with Mux](./guides/getting-started-with-mux.md) - Learn how to manage multiplexed bidirectional message streams with capacity limits
876
- - [Migrating from ZIO Schema](./guides/zio-schema-migration.md) - Step-by-step guide to migrating from ZIO Schema 1.x to ZIO Blocks Schema
493
+ ## Guides
494
+
495
+ - [Getting Started with Async](./guides/async-getting-started.md) - Create, compose, and run zero-allocation async effects with the `Async[A]` type
496
+ - [Compile-Time Resource Safety with Scope](./guides/compile-time-resource-safety-with-scope.md) - Resource management and dependency injection, from first principles
497
+ - [Getting Started with Mux](./guides/getting-started-with-mux.md) - Manage multiplexed bidirectional message streams with capacity limits
498
+ - [Telemetry: Architecture, Patterns, and Real-World Usage](./guides/telemetry-guide.md) - Wire tracing, logging, and metrics into a running application
499
+ - [Migrating from ZIO Schema](./guides/zio-schema-migration.md) - Step-by-step migration from ZIO Schema 1.x to ZIO Blocks Schema
877
500
  - [Query DSL Part 1: Expressions](./guides/query-dsl-reified-optics.md) - Build type-safe, composable query expressions
878
501
  - [Query DSL Part 2: SQL Generation](./guides/query-dsl-sql.md) - Translate query expressions into SQL
879
- - [Query DSL Part 3: Extending the Expression Language](./guides/query-dsl-extending.md) - Add custom operators beyond SchemaExpr
880
- - [Query DSL Part 4: A Fluent SQL Builder](./guides/query-dsl-fluent-builder.md) - Build type-safe SELECT, UPDATE, INSERT, DELETE statements
502
+ - [Query DSL Part 3: Extending the Expression Language](./guides/query-dsl-extending.md) - Add custom operators beyond `SchemaExpr`
503
+ - [Query DSL Part 4: A Fluent SQL Builder](./guides/query-dsl-fluent-builder.md) - Build type-safe SELECT, UPDATE, INSERT, and DELETE statements
504
+
505
+ ## Full API Reference
506
+
507
+ Every block in the catalog above links to its own reference page. The blocks
508
+ large enough to have several pages start from an overview:
509
+
510
+ - [Schema](./reference/schema/index.md) - core type system, dynamic values, optics, validation, and schema evolution
511
+ - [Built-in Codecs](./reference/schema/built-in-codecs/index.md) - JSON, Avro, BSON, CSV, MessagePack, Thrift, TOON, XML, and YAML
512
+ - [Schema Evolution](./reference/schema/schema-evolution/index.md) - one-way and bidirectional type-safe conversions
513
+ - [Telemetry](./reference/telemetry/index.md) - tracing, logging, metrics, and OTLP export
514
+ - [SQL](./reference/sql/index.md) - codecs, fragments, tables, repositories, transactors, and dialects
515
+ - [Resource Management](./reference/resource-management/index.md) - `Scope`, `Resource`, `Wire`, `Unscoped`, and finalization
516
+ - [Streams](./reference/streams/index.md) - `Stream`, `Pipeline`, `Sink`, and the low-level readers and writers
517
+ - [Endpoint](./reference/endpoint/index.md) - endpoint descriptors, HTTP codecs, route patterns, and typed auth
518
+ - [HTTP Model](./reference/http-model/index.md) - the pure HTTP data model and its schema-based typed access
519
+ - [HTMX](./reference/htmx/index.md) - the typed HTMX attribute DSL
520
+ - [Ring Buffer](./reference/ringbuffer/index.mdx) - the SPSC, SPMC, MPSC, and MPMC variants
521
+ - [Code Generation](./reference/codegen/index.md) - the Scala code generation IR and emitter