@zio.dev/zio-blocks 0.0.27 → 0.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/guides/query-dsl-extending.md +1 -1
- package/guides/query-dsl-fluent-builder.md +1 -1
- package/guides/query-dsl-reified-optics.md +1 -1
- package/guides/query-dsl-sql.md +1 -1
- package/guides/zio-schema-migration.md +6 -6
- package/index.md +69 -17
- package/package.json +1 -1
- package/path-interpolator.md +70 -9
- package/reference/allows.md +1155 -34
- package/reference/binding-resolver.md +469 -0
- package/reference/binding.md +1 -1
- package/reference/codec.md +8 -8
- package/reference/combinators.md +345 -0
- package/reference/context.md +639 -67
- package/reference/docs.md +1 -1
- package/reference/dynamic-optic.md +5 -0
- package/reference/dynamic-schema.md +602 -0
- package/reference/dynamic-value.md +5 -0
- package/reference/http-model.md +1716 -0
- package/reference/json-differ.md +320 -0
- package/reference/json-patch.md +803 -0
- package/reference/json.md +1 -1
- package/reference/media-type.md +2 -2
- package/reference/patch.md +4 -0
- package/reference/resource-management-di/index.md +49 -0
- package/reference/resource-management-di/resource.md +1125 -0
- package/{scope.md → reference/resource-management-di/scope.md} +92 -10
- package/reference/resource-management-di/wire.md +832 -0
- package/reference/schema-evolution/as.md +587 -0
- package/reference/schema-evolution/index.md +50 -0
- package/reference/schema-evolution/into.md +1027 -0
- package/reference/schema-expr.md +2 -2
- package/reference/structural-types.md +369 -0
- package/reference/type-class-derivation.md +31 -31
- package/reference/xml.md +606 -45
- package/ringbuffer.md +249 -0
- package/sidebars.js +31 -1
- package/reference/schema-evolution.md +0 -540
package/reference/json.md
CHANGED
|
@@ -828,7 +828,7 @@ Type ordering: Null < Boolean < Number < String < Array < Object
|
|
|
828
828
|
|
|
829
829
|
## JSON Diffing
|
|
830
830
|
|
|
831
|
-
`JsonDiffer` computes the difference between two JSON values, producing a `JsonPatch` that transforms the source into the target:
|
|
831
|
+
`JsonDiffer` computes the difference between two JSON values, producing a [`JsonPatch`](./json-patch.md) that transforms the source into the target:
|
|
832
832
|
|
|
833
833
|
```scala
|
|
834
834
|
import zio.blocks.schema.json.{Json, JsonPatch}
|
package/reference/media-type.md
CHANGED
|
@@ -75,13 +75,13 @@ textAny.matches(html) // true
|
|
|
75
75
|
Add the following to your `build.sbt`:
|
|
76
76
|
|
|
77
77
|
```scala
|
|
78
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-mediatype" % "0.0.
|
|
78
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-mediatype" % "0.0.29"
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
For cross-platform projects (Scala.js):
|
|
82
82
|
|
|
83
83
|
```scala
|
|
84
|
-
libraryDependencies += "dev.zio" %%% "zio-blocks-mediatype" % "0.0.
|
|
84
|
+
libraryDependencies += "dev.zio" %%% "zio-blocks-mediatype" % "0.0.29"
|
|
85
85
|
```
|
|
86
86
|
|
|
87
87
|
Supported Scala versions: 2.13.x and 3.x.
|
package/reference/patch.md
CHANGED
|
@@ -15,6 +15,10 @@ A `Patch[S]` represents a sequence of operations that transform a value of type
|
|
|
15
15
|
- **Optimistic Updates** — Apply patches locally while syncing with a server
|
|
16
16
|
- **Schema Evolution** — Patches work with the schema system, adapting as data structures evolve
|
|
17
17
|
|
|
18
|
+
:::note
|
|
19
|
+
For **untyped JSON patching** without a schema, use [`JsonPatch`](./json-patch.md) instead. `JsonPatch` is optimized for diff-and-apply workflows on raw JSON values and provides compact delta representations without requiring typed optics.
|
|
20
|
+
:::
|
|
21
|
+
|
|
18
22
|
```scala
|
|
19
23
|
import zio.blocks.schema._
|
|
20
24
|
import zio.blocks.schema.patch._
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: index
|
|
3
|
+
title: "Resource Management & Dependency Injection"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
## Introduction
|
|
7
|
+
|
|
8
|
+
Resource management and dependency injection are fundamental to building reliable, maintainable applications. ZIO Blocks provides three complementary types that work together to eliminate common lifetime bugs while enabling powerful composition patterns: **Scope** provides compile-time safe resource boundaries, **Resource** encapsulates acquisition and cleanup with automatic finalization, and **Wire** describes dependency graphs with type-safe construction recipes. Together, they form a cohesive system for managing object lifecycles, preventing resource leaks, and building dependency-injected architectures.
|
|
9
|
+
|
|
10
|
+
**Related Types:**
|
|
11
|
+
- [`Resource`](./resource.md) — Lazy recipe for managing resource lifecycles with automatic cleanup
|
|
12
|
+
- [`Scope`](./scope.md) — Compile-time safe resource management and scoped value access
|
|
13
|
+
- [`Wire`](./wire.md) — Type-safe recipes for constructing services and their dependencies
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
These three types solve the fundamental problem of managing resources and dependencies in concurrent, long-lived applications:
|
|
18
|
+
|
|
19
|
+
**Scope** is the foundation — it provides a compile-time safe boundary that prevents resources from escaping their intended lifetime. Using path-dependent types, Scope ensures that values allocated in one scope cannot accidentally be used in another scope, catching lifetime violations at compile time rather than causing runtime bugs.
|
|
20
|
+
|
|
21
|
+
**Resource** builds on Scope to describe how to acquire and finalize resources. Rather than executing immediately, a Resource is a lazy recipe that composes naturally with `map`, `flatMap`, and `zip`. When allocated within a scope, finalizers run automatically in LIFO order, ensuring cleanup happens even when errors occur.
|
|
22
|
+
|
|
23
|
+
**Wire** brings it all together by describing how to construct services and their dependencies. The Wire macro automatically handles dependency resolution, cycle detection, and AutoCloseable registration, letting you declaratively specify a dependency graph that the compiler validates.
|
|
24
|
+
|
|
25
|
+
### How They Work Together
|
|
26
|
+
|
|
27
|
+
The typical flow is:
|
|
28
|
+
|
|
29
|
+
1. **Define** dependencies using `Wire.shared[T]` or `Wire.unique[T]` — the macro inspects constructor parameters and generates a wire
|
|
30
|
+
2. **Compose** wires together using `Resource.from[App](wire1, wire2, ...)` — builds the dependency graph
|
|
31
|
+
3. **Allocate** within a scope using `scope.allocate(resource)` — acquires resources and registers finalizers
|
|
32
|
+
4. **Use** scoped values via the `$` accessor — compile-time ensures they can't escape
|
|
33
|
+
5. **Cleanup** happens automatically when the scope exits — finalizers run in reverse order (LIFO)
|
|
34
|
+
|
|
35
|
+
### Common Patterns
|
|
36
|
+
|
|
37
|
+
**Shared Singletons** — Use `Wire.shared[T]` for expensive resources (database connections, thread pools) that should be created once and reused across the application.
|
|
38
|
+
|
|
39
|
+
**Per-Request Instances** — Use `Wire.unique[T]` for request-scoped state that should be fresh for each request or operation.
|
|
40
|
+
|
|
41
|
+
**Manual Construction** — Use `Wire.Shared.fromFunction` or `Wire.Unique.fromFunction` when macro derivation doesn't fit your use case (custom initialization logic, special parameters).
|
|
42
|
+
|
|
43
|
+
**Resource Composition** — Use `Resource.map`, `Resource.flatMap`, and `Resource.zip` to build complex dependency chains where later resources depend on earlier ones.
|
|
44
|
+
|
|
45
|
+
### Integration Points
|
|
46
|
+
|
|
47
|
+
- **Wire** uses **Resource** to manage lifecycles of constructed services
|
|
48
|
+
- **Resource** uses **Scope** for finalization and scoped value boundaries
|
|
49
|
+
- Both **Wire** and **Resource** produce values that are usable only within a **Scope** context
|