@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.
- package/adr/2026-07-18-data-migration.md +123 -0
- package/guides/async-getting-started.md +687 -0
- package/guides/compile-time-resource-safety-with-scope.md +6 -0
- package/guides/getting-started-with-mux.md +0 -112
- package/guides/query-dsl-extending.md +1 -1
- package/guides/query-dsl-fluent-builder.md +1 -1
- package/guides/query-dsl-reified-optics.md +1 -1
- package/guides/query-dsl-sql.md +395 -1
- package/guides/sql-checked-interpolation.md +173 -0
- package/guides/sql-transactions.md +286 -0
- package/guides/telemetry-guide.md +131 -70
- package/guides/zio-schema-migration.md +6 -6
- package/index.md +200 -559
- package/package.json +1 -1
- package/reference/async.md +1379 -531
- package/reference/chunk.md +3 -3
- package/reference/codegen/index.md +1 -1
- package/reference/combinators.md +4 -4
- package/reference/config/config-decoder.md +460 -0
- package/reference/config/config-source.md +489 -0
- package/reference/config/errors.md +278 -0
- package/reference/config/flags.md +369 -0
- package/reference/config/formats.md +314 -0
- package/reference/config/index.md +304 -0
- package/reference/config/rollout.md +336 -0
- package/reference/context.md +6 -49
- package/reference/data-migration.md +269 -0
- package/reference/datastar/attributes.md +302 -0
- package/reference/datastar/events.md +234 -0
- package/reference/datastar/index.md +256 -0
- package/reference/datastar/signals.md +230 -0
- package/reference/datastar/sse.md +295 -0
- package/reference/datastar.md +2 -2
- package/reference/docs.md +2 -2
- package/reference/endpoint/bulk-creation.md +96 -0
- package/reference/endpoint/endpoint.md +1 -0
- package/reference/endpoint/index.md +9 -89
- package/reference/endpoint/path-codec.md +12 -24
- package/reference/endpoint/route-pattern.md +4 -6
- package/reference/endpoint/segment-codec.md +19 -32
- package/reference/html.md +313 -9
- package/reference/htmx/index.md +4 -52
- package/reference/htmx/response-headers.md +240 -0
- package/reference/http-model/headers.md +735 -0
- package/reference/http-model/index.md +3 -1
- package/reference/http-model/model.md +107 -71
- package/reference/http-model/schema-codecs.md +522 -0
- package/reference/http-model/schema.md +6 -3
- package/reference/http-model/server-sent-event.md +341 -0
- package/reference/jwt.md +195 -0
- package/reference/maybe.md +128 -11
- package/reference/media-type.md +2 -2
- package/reference/mux.mdx +7 -2
- package/reference/openapi.md +3 -3
- package/reference/projection.md +654 -0
- package/reference/resource-management/index.md +1 -1
- package/reference/resource-management/resource.md +2 -98
- package/reference/resource-management/scope.md +1 -209
- package/reference/resource-management/wire.md +4 -50
- package/reference/ringbuffer/advanced.mdx +1 -1
- package/reference/ringbuffer/index.mdx +3 -3
- package/reference/ringbuffer/mpmc.mdx +38 -4
- package/reference/ringbuffer/mpsc.mdx +36 -4
- package/reference/ringbuffer/spmc.mdx +1 -1
- package/reference/ringbuffer/spsc.mdx +87 -15
- package/reference/schema/allows.md +0 -96
- package/reference/schema/binding.md +2 -2
- package/reference/schema/built-in-codecs/avro.md +2 -2
- package/reference/schema/built-in-codecs/bson.md +50 -20
- package/reference/schema/built-in-codecs/csv.md +2 -2
- package/reference/schema/built-in-codecs/index.md +3 -3
- package/reference/schema/built-in-codecs/json/index.md +2 -2
- package/reference/schema/built-in-codecs/json/json.md +1 -0
- package/reference/schema/built-in-codecs/messagepack.md +3 -3
- package/reference/schema/built-in-codecs/thrift.md +2 -2
- package/reference/schema/built-in-codecs/toon.md +3 -3
- package/reference/schema/built-in-codecs/yaml.md +2 -2
- package/reference/schema/codec.md +11 -11
- package/reference/schema/dynamic-optic.md +48 -3
- package/reference/schema/dynamic-schema.md +3 -3
- package/reference/schema/index.md +2 -0
- package/reference/schema/path-interpolator.md +2 -0
- package/reference/schema/reflect-transformer.md +140 -0
- package/reference/schema/schema-evolution/as.md +4 -4
- package/reference/schema/schema-evolution/into.md +2 -2
- package/reference/schema/schema-expr.md +2 -2
- package/reference/schema/schema-search.md +263 -0
- package/reference/schema/schema.md +10 -2
- package/reference/schema/type-class-derivation.md +1 -1
- package/reference/smithy.md +502 -3
- package/reference/sql/db-codec-deriver.md +3 -3
- package/reference/sql/db-codec.md +22 -22
- package/reference/sql/db-con.md +4 -4
- package/reference/sql/db-connection.md +1 -1
- package/reference/sql/db-param.md +1 -1
- package/reference/sql/db-result-reader.md +4 -2
- package/reference/sql/db-tx.md +46 -14
- package/reference/sql/ddl.md +1 -1
- package/reference/sql/frag.md +44 -10
- package/reference/sql/index.md +7 -7
- package/reference/sql/repo.md +15 -15
- package/reference/sql/sql-dialect.md +1 -1
- package/reference/sql/sql-logger.md +1 -1
- package/reference/sql/sql-name-mapper.md +3 -3
- package/reference/sql/table-metadata.md +3 -3
- package/reference/sql/table.md +10 -10
- package/reference/sql/transactor-zio.md +1 -1
- package/reference/sql/transactor.md +21 -11
- package/reference/sql-zio.md +2 -2
- package/reference/streams/core/index.md +32 -0
- package/reference/streams/{pipeline.md → core/pipeline.md} +210 -74
- package/reference/streams/{sink.md → core/sink.md} +331 -353
- package/reference/streams/{stream.md → core/stream.md} +919 -209
- package/reference/streams/execution-and-compatibility/async-execution.md +822 -0
- package/reference/streams/execution-and-compatibility/index.md +35 -0
- package/reference/streams/execution-and-compatibility/platform-differences.md +297 -0
- package/reference/streams/execution-and-compatibility/scala-2-compatibility.md +88 -0
- package/reference/streams/execution-and-compatibility/zero-boxing.md +393 -0
- package/reference/streams/index.md +140 -67
- package/reference/streams/primitives/index.md +30 -0
- package/reference/streams/primitives/reader.md +1992 -0
- package/reference/streams/{writer.md → primitives/writer.md} +254 -98
- package/reference/telemetry/common/any-value.md +90 -0
- package/reference/telemetry/common/attribute-key.md +87 -0
- package/reference/telemetry/common/attributes.md +118 -0
- package/reference/telemetry/common/index.md +39 -0
- package/reference/telemetry/common/instrumentation-scope.md +24 -0
- package/reference/telemetry/common/resource.md +34 -0
- package/reference/telemetry/index.md +311 -0
- package/reference/telemetry/logging/index.md +197 -0
- package/reference/telemetry/logging/log-enrichment.md +72 -0
- package/reference/telemetry/logging/log-formatter.md +100 -0
- package/reference/telemetry/logging/log-record-processor.md +56 -0
- package/reference/telemetry/logging/log-record.md +44 -0
- package/reference/telemetry/logging/log-writer.md +64 -0
- package/reference/telemetry/logging/logger-provider.md +142 -0
- package/reference/telemetry/logging/logger.md +83 -0
- package/reference/telemetry/logging/severity.md +62 -0
- package/reference/telemetry/metrics/index.md +150 -0
- package/reference/telemetry/metrics/instruments.md +183 -0
- package/reference/telemetry/metrics/labeled-instruments.md +74 -0
- package/reference/telemetry/metrics/meter-provider.md +76 -0
- package/reference/telemetry/metrics/meter.md +98 -0
- package/reference/telemetry/metrics/metric-data.md +57 -0
- package/reference/telemetry/otel/custom-exporter.md +216 -0
- package/reference/telemetry/otel/index.md +212 -0
- package/reference/telemetry/tracing/index.md +155 -0
- package/reference/telemetry/tracing/sampler.md +89 -0
- package/reference/telemetry/tracing/span-builder.md +57 -0
- package/reference/telemetry/tracing/span-context.md +39 -0
- package/reference/telemetry/tracing/span-data.md +32 -0
- package/reference/telemetry/tracing/span-kind.md +55 -0
- package/reference/telemetry/tracing/span-processor.md +53 -0
- package/reference/telemetry/tracing/span-status.md +47 -0
- package/reference/telemetry/tracing/span.md +117 -0
- package/reference/telemetry/tracing/tracer-provider.md +91 -0
- package/reference/telemetry/tracing/tracer.md +52 -0
- package/reference/typeid.md +0 -64
- package/sidebars.js +365 -185
- package/undocumented-report.md +528 -270
- package/reference/config.md +0 -158
- package/reference/streams/concurrent-operators.md +0 -106
- package/reference/streams/reader.md +0 -1284
- package/reference/streams/scala-2-compatibility.md +0 -55
- package/reference/streams/zero-boxing.md +0 -275
- 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
|
|
6
|
+
**Modular building blocks for modern Scala applications—no effect system required.**
|
|
7
7
|
|
|
8
|
-
[](https://github.com/zio/zio/wiki/Project-Stages)  [](https://github.com/zio/zio-blocks)
|
|
8
|
+
[](https://github.com/zio/zio/wiki/Project-Stages)  [](https://central.sonatype.com/artifact/dev.zio/zio-blocks-config_3) [](https://central.sonatype.com/repository/maven-snapshots/dev/zio/zio-blocks-config_3/) [](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
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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-
|
|
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.
|
|
62
|
-
|
|
63
|
-
object poolSize extends StaticFlag[Int](10)
|
|
34
|
+
import zio.blocks.schema._
|
|
64
35
|
|
|
65
|
-
|
|
66
|
-
```
|
|
36
|
+
case class Person(name: String, age: Int)
|
|
67
37
|
|
|
68
|
-
|
|
38
|
+
object Person {
|
|
39
|
+
implicit val schema: Schema[Person] = Schema.derived
|
|
40
|
+
}
|
|
69
41
|
|
|
70
|
-
|
|
42
|
+
val alice = Person("Alice", 30)
|
|
71
43
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
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
|
-
|
|
79
|
-
```
|
|
53
|
+
## All Blocks
|
|
80
54
|
|
|
81
|
-
|
|
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
|
-
|
|
84
|
-
package myapp
|
|
60
|
+
### Meta Programming
|
|
85
61
|
|
|
86
|
-
|
|
62
|
+
JSON support is built into `zio-blocks-schema`; the modules below add further formats.
|
|
87
63
|
|
|
88
|
-
|
|
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
|
-
|
|
91
|
-
FlagSource.fromMap(Map("myapp.poolSize" -> "20"), "demo")
|
|
92
|
-
)
|
|
77
|
+
### Resource Management
|
|
93
78
|
|
|
94
|
-
|
|
95
|
-
```
|
|
79
|
+
All of these ship in `zio-blocks-scope`.
|
|
96
80
|
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
###
|
|
90
|
+
### Dependency Injection
|
|
102
91
|
|
|
103
|
-
|
|
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
|
-
|
|
106
|
-
import zio.blocks.config._
|
|
107
|
-
import zio.blocks.scope.Unscoped
|
|
97
|
+
### Configuration & Feature Flags
|
|
108
98
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
106
|
+
### Web & HTTP
|
|
114
107
|
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
###
|
|
120
|
+
### Data Types
|
|
120
121
|
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
125
|
-
val choice = Rollout.select("true@prod/50%;false", "prod", bucket)
|
|
126
|
-
```
|
|
128
|
+
### Concurrency
|
|
127
129
|
|
|
128
|
-
|
|
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
|
-
###
|
|
136
|
+
### Streams
|
|
131
137
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
142
|
+
### Telemetry
|
|
137
143
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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,
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
272
|
-
|
|
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.
|
|
304
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.56"
|
|
343
305
|
```
|
|
344
306
|
|
|
345
|
-
### Example
|
|
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
|
-
###
|
|
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
|
-
|
|
380
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
445
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.51"
|
|
446
|
-
```
|
|
352
|
+
### The Solution
|
|
447
353
|
|
|
448
|
-
|
|
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.
|
|
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
|
-
//
|
|
486
|
-
val
|
|
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**: `&` 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
|
-
- **
|
|
522
|
-
- **
|
|
523
|
-
- **
|
|
524
|
-
- **
|
|
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-
|
|
376
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-async" % "0.0.56"
|
|
530
377
|
```
|
|
531
378
|
|
|
532
379
|
### Example
|
|
533
380
|
|
|
534
|
-
|
|
535
|
-
|
|
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.
|
|
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
|
-
|
|
387
|
+
def fetch(id: Int): Async[String] = Async.succeed(s"item-$id")
|
|
622
388
|
|
|
623
|
-
|
|
624
|
-
|
|
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
|
-
###
|
|
397
|
+
### Learn More
|
|
628
398
|
|
|
629
|
-
|
|
630
|
-
|
|
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
|
-
|
|
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
|
|
685
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-sql-zio" % "0.0.
|
|
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
|
-
|
|
719
|
-
|
|
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
|
-
##
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
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
|