@zio.dev/zio-blocks 0.0.22 → 0.0.25
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 +758 -0
- package/guides/query-dsl-fluent-builder.md +1287 -0
- package/guides/query-dsl-reified-optics.md +494 -0
- package/guides/query-dsl-sql.md +680 -0
- package/index.md +42 -39
- package/package.json +1 -1
- package/reference/codec.md +20 -18
- package/reference/docs.md +1 -1
- package/reference/dynamic-optic.md +4 -0
- package/reference/json-schema.md +1 -1
- package/reference/json.md +2 -2
- package/reference/media-type.md +460 -0
- package/reference/optics.md +4 -0
- package/reference/schema-expr.md +669 -0
- package/reference/schema.md +1 -0
- package/reference/type-class-derivation.md +50 -12
- package/scope.md +744 -490
- package/sidebars.js +12 -0
- package/undocumented-report.md +331 -0
package/index.md
CHANGED
|
@@ -23,6 +23,7 @@ The philosophy is simple: **use what you need, nothing more**. Each block is ind
|
|
|
23
23
|
| **Docs** | GitHub Flavored Markdown parsing and rendering | ✅ Available |
|
|
24
24
|
| **TypeId** | Compile-time type identity with rich metadata | ✅ Available |
|
|
25
25
|
| **Context** | Type-indexed heterogeneous collections | ✅ Available |
|
|
26
|
+
| **MediaType** | Type-safe IANA media types with 2,600+ predefined types | ✅ Available |
|
|
26
27
|
| **Streams** | Pull-based streaming primitives | 🚧 In Development |
|
|
27
28
|
|
|
28
29
|
## Core Principles
|
|
@@ -80,14 +81,14 @@ val thriftCodec = Schema[Person].derive(ThriftFormat) // Thrift
|
|
|
80
81
|
### Installation
|
|
81
82
|
|
|
82
83
|
```scala
|
|
83
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
84
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.25"
|
|
84
85
|
|
|
85
86
|
// Optional format modules:
|
|
86
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.
|
|
87
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.
|
|
88
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.
|
|
89
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.
|
|
90
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.
|
|
87
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.25"
|
|
88
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.25"
|
|
89
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.25"
|
|
90
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.25"
|
|
91
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.25"
|
|
91
92
|
```
|
|
92
93
|
|
|
93
94
|
### Example: Optics
|
|
@@ -142,7 +143,7 @@ Chunk is designed for:
|
|
|
142
143
|
### Installation
|
|
143
144
|
|
|
144
145
|
```scala
|
|
145
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-chunk" % "0.0.
|
|
146
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-chunk" % "0.0.25"
|
|
146
147
|
```
|
|
147
148
|
|
|
148
149
|
### Example
|
|
@@ -201,19 +202,19 @@ Using(openDatabase()) { db =>
|
|
|
201
202
|
Scope makes resource leaks a **compile error**, not a runtime bug:
|
|
202
203
|
|
|
203
204
|
```scala
|
|
204
|
-
import zio.blocks.scope
|
|
205
|
+
import zio.blocks.scope.*
|
|
205
206
|
|
|
206
207
|
Scope.global.scoped { scope =>
|
|
207
|
-
import scope
|
|
208
|
+
import scope.*
|
|
208
209
|
|
|
209
210
|
val db: $[Database] = allocate(Resource(openDatabase()))
|
|
210
211
|
|
|
211
212
|
// Methods are hidden - can't call db.query() directly
|
|
212
|
-
// Must use
|
|
213
|
-
val result =
|
|
213
|
+
// Must use $ to access:
|
|
214
|
+
val result: String = $(db)(_.query("SELECT 1"))
|
|
214
215
|
|
|
215
216
|
// Trying to return `db` would be a compile error!
|
|
216
|
-
result // Only pure data escapes
|
|
217
|
+
result // Only pure data (String) escapes
|
|
217
218
|
}
|
|
218
219
|
// db.close() called automatically
|
|
219
220
|
```
|
|
@@ -230,27 +231,26 @@ Scope.global.scoped { scope =>
|
|
|
230
231
|
### Installation
|
|
231
232
|
|
|
232
233
|
```scala
|
|
233
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.
|
|
234
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-scope" % "0.0.25"
|
|
234
235
|
```
|
|
235
236
|
|
|
236
237
|
### Example: Basic Resource Management
|
|
237
238
|
|
|
238
239
|
```scala
|
|
239
|
-
import zio.blocks.scope
|
|
240
|
+
import zio.blocks.scope.*
|
|
240
241
|
|
|
241
|
-
final class Database extends AutoCloseable
|
|
242
|
+
final class Database extends AutoCloseable:
|
|
242
243
|
def query(sql: String): String = s"Result: $sql"
|
|
243
244
|
def close(): Unit = println("Database closed")
|
|
244
|
-
}
|
|
245
245
|
|
|
246
246
|
Scope.global.scoped { scope =>
|
|
247
|
-
import scope
|
|
247
|
+
import scope.*
|
|
248
248
|
|
|
249
|
-
// Allocate returns
|
|
249
|
+
// Allocate returns $[Database] (scoped value)
|
|
250
250
|
val db: $[Database] = allocate(Resource(new Database))
|
|
251
251
|
|
|
252
|
-
// Access via
|
|
253
|
-
val result =
|
|
252
|
+
// Access via $ - result (String) escapes, db does not
|
|
253
|
+
val result: String = $(db)(_.query("SELECT * FROM users"))
|
|
254
254
|
|
|
255
255
|
println(result)
|
|
256
256
|
}
|
|
@@ -261,7 +261,7 @@ Scope.global.scoped { scope =>
|
|
|
261
261
|
### Example: Dependency Injection
|
|
262
262
|
|
|
263
263
|
```scala
|
|
264
|
-
import zio.blocks.scope
|
|
264
|
+
import zio.blocks.scope.*
|
|
265
265
|
|
|
266
266
|
case class Config(dbUrl: String)
|
|
267
267
|
class Database(config: Config) extends AutoCloseable { ... }
|
|
@@ -275,11 +275,11 @@ val serviceResource: Resource[UserService] = Resource.from[UserService](
|
|
|
275
275
|
)
|
|
276
276
|
|
|
277
277
|
Scope.global.scoped { scope =>
|
|
278
|
-
import scope
|
|
278
|
+
import scope.*
|
|
279
279
|
|
|
280
280
|
val service = allocate(serviceResource)
|
|
281
281
|
|
|
282
|
-
|
|
282
|
+
$(service)(_.createUser("Alice"))
|
|
283
283
|
}
|
|
284
284
|
// Cleanup runs LIFO: UserService → Database (UserRepo has no cleanup)
|
|
285
285
|
```
|
|
@@ -288,24 +288,18 @@ Scope.global.scoped { scope =>
|
|
|
288
288
|
|
|
289
289
|
```scala
|
|
290
290
|
Scope.global.scoped { connScope =>
|
|
291
|
-
import connScope
|
|
291
|
+
import connScope.*
|
|
292
292
|
|
|
293
293
|
val conn = allocate(Resource.fromAutoCloseable(new Connection))
|
|
294
294
|
|
|
295
295
|
// Transaction lives in child scope - cleaned up before connection
|
|
296
296
|
val result: String = scoped { txScope =>
|
|
297
|
-
import txScope
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
tx <- allocate(c.beginTransaction())
|
|
304
|
-
} yield {
|
|
305
|
-
tx.execute("INSERT INTO users VALUES (1, 'Alice')")
|
|
306
|
-
tx.commit()
|
|
307
|
-
"success"
|
|
308
|
-
}
|
|
297
|
+
import txScope.*
|
|
298
|
+
val c = lower(conn)
|
|
299
|
+
val tx = $(c)(_.beginTransaction()).allocate
|
|
300
|
+
$(tx)(_.execute("INSERT INTO users VALUES (1, 'Alice')"))
|
|
301
|
+
$(tx)(_.commit())
|
|
302
|
+
"success"
|
|
309
303
|
}
|
|
310
304
|
// Transaction closed here, connection still open
|
|
311
305
|
|
|
@@ -340,7 +334,7 @@ Generating documentation, README files, or any Markdown content programmatically
|
|
|
340
334
|
### Installation
|
|
341
335
|
|
|
342
336
|
```scala
|
|
343
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.
|
|
337
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.25"
|
|
344
338
|
```
|
|
345
339
|
|
|
346
340
|
### Example
|
|
@@ -424,7 +418,7 @@ Compile-time type identity with rich metadata. TypeId captures comprehensive inf
|
|
|
424
418
|
### Installation
|
|
425
419
|
|
|
426
420
|
```scala
|
|
427
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-typeid" % "0.0.
|
|
421
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-typeid" % "0.0.25"
|
|
428
422
|
```
|
|
429
423
|
|
|
430
424
|
### Example
|
|
@@ -467,7 +461,7 @@ A type-indexed heterogeneous collection that stores values by their types with c
|
|
|
467
461
|
### Installation
|
|
468
462
|
|
|
469
463
|
```scala
|
|
470
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-context" % "0.0.
|
|
464
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-context" % "0.0.25"
|
|
471
465
|
```
|
|
472
466
|
|
|
473
467
|
### Example
|
|
@@ -548,6 +542,7 @@ ZIO Blocks supports **Scala 2.13** and **Scala 3.x** with full source compatibil
|
|
|
548
542
|
### Optics & Navigation
|
|
549
543
|
|
|
550
544
|
- [Optics](./reference/optics.md) - Lenses, prisms, and traversals
|
|
545
|
+
- [SchemaExpr](./reference/schema-expr.md) - Schema-aware expressions for queries and validation
|
|
551
546
|
- [Path Interpolator](./path-interpolator.md) - Type-safe path construction
|
|
552
547
|
- [DynamicValue](./reference/dynamic-value.md) - Schema-less dynamic values
|
|
553
548
|
|
|
@@ -572,3 +567,11 @@ ZIO Blocks supports **Scala 2.13** and **Scala 3.x** with full source compatibil
|
|
|
572
567
|
- [TypeId](./reference/typeid.md) - Type identity and metadata
|
|
573
568
|
- [Context](./reference/context.md) - Type-indexed heterogeneous collections
|
|
574
569
|
- [Docs (Markdown)](./reference/docs.md) - Markdown parsing and rendering
|
|
570
|
+
- [MediaType](./reference/media-type.md) - Type-safe IANA media types
|
|
571
|
+
|
|
572
|
+
### Guides
|
|
573
|
+
|
|
574
|
+
- [Query DSL Part 1: Expressions](./guides/query-dsl-reified-optics.md) - Build type-safe, composable query expressions
|
|
575
|
+
- [Query DSL Part 2: SQL Generation](./guides/query-dsl-sql.md) - Translate query expressions into SQL
|
|
576
|
+
- [Query DSL Part 3: Extending the Expression Language](./guides/query-dsl-extending.md) - Add custom operators beyond SchemaExpr
|
|
577
|
+
- [Query DSL Part 4: A Fluent SQL Builder](./guides/query-dsl-fluent-builder.md) - Build type-safe SELECT, UPDATE, INSERT, DELETE statements
|
package/package.json
CHANGED
package/reference/codec.md
CHANGED
|
@@ -48,23 +48,23 @@ val result: Either[SchemaError, Person] = Person.codec.decode(bytes)
|
|
|
48
48
|
To include the base schema module with JSON support, add the following dependency to your `build.sbt`:
|
|
49
49
|
|
|
50
50
|
```scala
|
|
51
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.
|
|
51
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema" % "0.0.25"
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
Additional format modules are separate artifacts:
|
|
55
55
|
|
|
56
56
|
```scala
|
|
57
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.
|
|
58
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.
|
|
59
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.
|
|
60
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.
|
|
61
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.
|
|
57
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-avro" % "0.0.25"
|
|
58
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-toon" % "0.0.25"
|
|
59
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-messagepack" % "0.0.25"
|
|
60
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-thrift" % "0.0.25"
|
|
61
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-schema-bson" % "0.0.25"
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
For cross-platform projects (Scala.js):
|
|
65
65
|
|
|
66
66
|
```scala
|
|
67
|
-
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.
|
|
67
|
+
libraryDependencies += "dev.zio" %%% "zio-blocks-schema" % "0.0.25"
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
Supported Scala versions: 2.13.x and 3.x.
|
|
@@ -227,7 +227,8 @@ val person = Person("Alice", 30)
|
|
|
227
227
|
|
|
228
228
|
// Array[Byte]
|
|
229
229
|
val bytes: Array[Byte] = codec.encode(person)
|
|
230
|
-
val
|
|
230
|
+
val fromBytes1: Either[SchemaError, Person] = codec.decode(bytes)
|
|
231
|
+
val fromBytes2: Either[SchemaError, Person] = codec.decode(bytes, 0, bytes.length)
|
|
231
232
|
|
|
232
233
|
// String
|
|
233
234
|
val jsonStr: String = codec.encodeToString(person)
|
|
@@ -272,16 +273,17 @@ val fromStr: Either[SchemaError, Person] = codec.decode("name: Alice\nage: 30")
|
|
|
272
273
|
|
|
273
274
|
`BinaryCodec` subclasses (JSON, TOON, MessagePack, Avro, Thrift) expose the following convenience overloads (availability may vary by format):
|
|
274
275
|
|
|
275
|
-
| Method
|
|
276
|
-
|
|
277
|
-
| `encode(value): Array[Byte]`
|
|
278
|
-
| `decode(input: Array[Byte]): Either[SchemaError, A]`
|
|
279
|
-
| `
|
|
280
|
-
| `
|
|
281
|
-
| `
|
|
282
|
-
| `
|
|
283
|
-
| `
|
|
284
|
-
| `
|
|
276
|
+
| Method | Description |
|
|
277
|
+
|--------------------------------------------------------------------------|--------------------------------------------------|
|
|
278
|
+
| `encode(value): Array[Byte]` | Encode to a byte array |
|
|
279
|
+
| `decode(input: Array[Byte]): Either[SchemaError, A]` | Decode from a byte array |
|
|
280
|
+
| `decode(input: Array[Byte], from: Int, to: Int): Either[SchemaError, A]` | Decode from a byte array slice |
|
|
281
|
+
| `encode(value, output: ByteBuffer): Unit` | Encode into a `ByteBuffer` |
|
|
282
|
+
| `decode(input: ByteBuffer): Either[SchemaError, A]` | Decode from a `ByteBuffer` |
|
|
283
|
+
| `encode(value, output: OutputStream): Unit` | Encode into an `OutputStream` (JSON, TOON, Avro) |
|
|
284
|
+
| `decode(input: InputStream): Either[SchemaError, A]` | Decode from an `InputStream` (JSON, TOON, Avro) |
|
|
285
|
+
| `encodeToString(value): String` | Encode to a `String` (JSON, TOON) |
|
|
286
|
+
| `decode(input: String): Either[SchemaError, A]` | Decode from a `String` (JSON, TOON) |
|
|
285
287
|
|
|
286
288
|
The `String`-based methods are available on text-oriented binary codecs (JSON, TOON) but not on purely binary formats like Avro or Thrift.
|
|
287
289
|
|
package/reference/docs.md
CHANGED
|
@@ -10,7 +10,7 @@ Complete API reference for the zio-blocks-docs module - a zero-dependency GitHub
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
12
12
|
```scala
|
|
13
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.
|
|
13
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-docs" % "0.0.25"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
## Core Types
|
|
@@ -25,6 +25,10 @@ val result = data.get(path).one
|
|
|
25
25
|
// Right(DynamicValue.Primitive(PrimitiveValue.String("Alice")))
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
:::tip
|
|
29
|
+
For a practical example of extracting column names from `DynamicOptic` paths to generate SQL, see the [Query DSL Part 2: SQL Generation](../guides/query-dsl-sql.md) guide.
|
|
30
|
+
:::
|
|
31
|
+
|
|
28
32
|
## Motivation
|
|
29
33
|
|
|
30
34
|
Most of the time you work with typed `Optic[S, A]` values — they are statically verified and provide type-safe
|
package/reference/json-schema.md
CHANGED
package/reference/json.md
CHANGED
|
@@ -971,9 +971,9 @@ error.errors.head.source // DynamicOptic path to error location
|
|
|
971
971
|
|
|
972
972
|
## Cross-Platform Support
|
|
973
973
|
|
|
974
|
-
The `Json` type works across
|
|
974
|
+
The `Json` type works across 2 platforms:
|
|
975
975
|
|
|
976
976
|
- **JVM** - Full functionality
|
|
977
977
|
- **Scala.js** - Browser and Node.js
|
|
978
978
|
|
|
979
|
-
String interpolators use compile-time validation that works on
|
|
979
|
+
String interpolators use compile-time validation that works on both platforms too.
|