@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/reference/smithy.md
CHANGED
|
@@ -10,7 +10,7 @@ title: "Smithy"
|
|
|
10
10
|
Add the library to your build configuration:
|
|
11
11
|
|
|
12
12
|
```scala
|
|
13
|
-
libraryDependencies += "dev.zio" %% "zio-blocks-smithy" % "0.0.
|
|
13
|
+
libraryDependencies += "dev.zio" %% "zio-blocks-smithy" % "0.0.56"
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
Supported Scala versions: 2.13.x and 3.x
|
|
@@ -80,8 +80,10 @@ SmithyModel (contains shapes, metadata, traits)
|
|
|
80
80
|
│ ├─ ServiceShape(operations, resources, errors)
|
|
81
81
|
│ ├─ OperationShape(input, output, errors)
|
|
82
82
|
│ ├─ UnionShape(members: List[MemberDefinition])
|
|
83
|
-
│ ├─
|
|
84
|
-
│
|
|
83
|
+
│ ├─ EnumShape(members: List[EnumMember])
|
|
84
|
+
│ ├─ ResourceShape(identifiers, create, read, update, delete, list, ...)
|
|
85
|
+
│ ├─ StringShape, BooleanShape, IntegerShape, and 10 more simple shapes
|
|
86
|
+
│ └─ ... (20 subtypes in total — see the Shape Catalog below)
|
|
85
87
|
├─ MemberDefinition(name: String, target: ShapeId, traits: List[TraitApplication])
|
|
86
88
|
├─ TraitApplication(id: ShapeId, value: Option[NodeValue])
|
|
87
89
|
├─ ShapeId (namespace + name identifier)
|
|
@@ -114,6 +116,503 @@ object SmithyModel {
|
|
|
114
116
|
}
|
|
115
117
|
```
|
|
116
118
|
|
|
119
|
+
## Shape Catalog
|
|
120
|
+
|
|
121
|
+
`Shape` is a sealed trait with 20 subtypes, covering the shape categories the Smithy specification defines. Every shape carries a `Shape#name` and a list of applied `Shape#traits`; the families differ in what else they hold:
|
|
122
|
+
|
|
123
|
+
```scala
|
|
124
|
+
sealed trait Shape {
|
|
125
|
+
def name: String
|
|
126
|
+
def traits: List[TraitApplication]
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
| Family | Subtypes | What they add |
|
|
131
|
+
| --------- | -------: | ---------------------------------------- |
|
|
132
|
+
| Simple | 13 | Nothing — name and traits only |
|
|
133
|
+
| Enum | 2 | A member list of allowed values |
|
|
134
|
+
| Aggregate | 4 | Member definitions naming target shapes |
|
|
135
|
+
| Service | 3 | `ShapeId` references to other shapes |
|
|
136
|
+
|
|
137
|
+
A parsed shape is wrapped in a `ShapeDefinition`, which pairs the name with the shape. `Shape` also carries its own `Shape#name`, so the two agree and either can be read:
|
|
138
|
+
|
|
139
|
+
```scala
|
|
140
|
+
final case class ShapeDefinition(name: String, shape: Shape)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Simple Shapes
|
|
144
|
+
|
|
145
|
+
Thirteen shapes carry no structure beyond their name and traits. They differ only in which IDL keyword produces them and what the target protocol is expected to do with them:
|
|
146
|
+
|
|
147
|
+
| Type | IDL keyword | Represents |
|
|
148
|
+
| ----------------- | ------------ | --------------------------------- |
|
|
149
|
+
| `BlobShape` | `blob` | Arbitrary binary data |
|
|
150
|
+
| `BooleanShape` | `boolean` | True/false values |
|
|
151
|
+
| `StringShape` | `string` | UTF-8 text |
|
|
152
|
+
| `ByteShape` | `byte` | 8-bit signed integer |
|
|
153
|
+
| `ShortShape` | `short` | 16-bit signed integer |
|
|
154
|
+
| `IntegerShape` | `integer` | 32-bit signed integer |
|
|
155
|
+
| `LongShape` | `long` | 64-bit signed integer |
|
|
156
|
+
| `FloatShape` | `float` | Single-precision IEEE 754 |
|
|
157
|
+
| `DoubleShape` | `double` | Double-precision IEEE 754 |
|
|
158
|
+
| `BigIntegerShape` | `bigInteger` | Arbitrarily large signed integer |
|
|
159
|
+
| `BigDecimalShape` | `bigDecimal` | Arbitrary-precision decimal |
|
|
160
|
+
| `TimestampShape` | `timestamp` | A point in time |
|
|
161
|
+
| `DocumentShape` | `document` | Protocol-agnostic open content |
|
|
162
|
+
|
|
163
|
+
Because they share one shape, parsing them produces values that differ only in their type:
|
|
164
|
+
|
|
165
|
+
```scala
|
|
166
|
+
import zio.blocks.smithy._
|
|
167
|
+
|
|
168
|
+
val simpleModel = SmithyModel.parse(
|
|
169
|
+
"""$version: "2"
|
|
170
|
+
|namespace com.example
|
|
171
|
+
|blob Payload
|
|
172
|
+
|timestamp CreatedAt
|
|
173
|
+
|document Metadata
|
|
174
|
+
|""".stripMargin
|
|
175
|
+
).toOption.get
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Each definition names the shape and holds the corresponding subtype:
|
|
179
|
+
|
|
180
|
+
```scala
|
|
181
|
+
simpleModel.shapes
|
|
182
|
+
// res1: List[ShapeDefinition] = List(
|
|
183
|
+
// ShapeDefinition(
|
|
184
|
+
// name = "Payload",
|
|
185
|
+
// shape = BlobShape(name = "Payload", traits = List())
|
|
186
|
+
// ),
|
|
187
|
+
// ShapeDefinition(
|
|
188
|
+
// name = "CreatedAt",
|
|
189
|
+
// shape = TimestampShape(name = "CreatedAt", traits = List())
|
|
190
|
+
// ),
|
|
191
|
+
// ShapeDefinition(
|
|
192
|
+
// name = "Metadata",
|
|
193
|
+
// shape = DocumentShape(name = "Metadata", traits = List())
|
|
194
|
+
// )
|
|
195
|
+
// )
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`DocumentShape` is the one to reach for when a field's contents are not known at model time — it is the Smithy equivalent of an open JSON value, and no member list constrains it.
|
|
199
|
+
|
|
200
|
+
### Enum Shapes
|
|
201
|
+
|
|
202
|
+
`EnumShape` and `IntEnumShape` each hold a fixed set of permitted values. They differ in the value type and in whether the value is optional:
|
|
203
|
+
|
|
204
|
+
```scala
|
|
205
|
+
final case class EnumShape(
|
|
206
|
+
name: String,
|
|
207
|
+
traits: List[TraitApplication] = Nil,
|
|
208
|
+
members: List[EnumMember] = Nil
|
|
209
|
+
) extends Shape
|
|
210
|
+
|
|
211
|
+
final case class IntEnumShape(
|
|
212
|
+
name: String,
|
|
213
|
+
traits: List[TraitApplication] = Nil,
|
|
214
|
+
members: List[IntEnumMember] = Nil
|
|
215
|
+
) extends Shape
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
`EnumMember` carries an `Option[String]`, because the IDL allows a bare member name; `IntEnumMember` carries a required `Int`, because an integer enum has no name to fall back on:
|
|
219
|
+
|
|
220
|
+
```scala
|
|
221
|
+
final case class EnumMember(name: String, value: Option[String] = None, traits: List[TraitApplication] = Nil)
|
|
222
|
+
final case class IntEnumMember(name: String, value: Int, traits: List[TraitApplication] = Nil)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
A string enum with explicit values fills in each `value`:
|
|
226
|
+
|
|
227
|
+
```scala
|
|
228
|
+
val colorModel = SmithyModel.parse(
|
|
229
|
+
"""$version: "2"
|
|
230
|
+
|namespace com.example
|
|
231
|
+
|enum Color {
|
|
232
|
+
| RED = "red"
|
|
233
|
+
| GREEN = "green"
|
|
234
|
+
|}
|
|
235
|
+
|""".stripMargin
|
|
236
|
+
).toOption.get
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Each member pairs the declared name with the string it maps to:
|
|
240
|
+
|
|
241
|
+
```scala
|
|
242
|
+
colorModel.shapes
|
|
243
|
+
// res2: List[ShapeDefinition] = List(
|
|
244
|
+
// ShapeDefinition(
|
|
245
|
+
// name = "Color",
|
|
246
|
+
// shape = EnumShape(
|
|
247
|
+
// name = "Color",
|
|
248
|
+
// traits = List(),
|
|
249
|
+
// members = List(
|
|
250
|
+
// EnumMember(name = "RED", value = Some("red"), traits = List()),
|
|
251
|
+
// EnumMember(name = "GREEN", value = Some("green"), traits = List())
|
|
252
|
+
// )
|
|
253
|
+
// )
|
|
254
|
+
// )
|
|
255
|
+
// )
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Omitting the values leaves `value` absent rather than duplicating the name, so a consumer wanting the effective wire value reads `EnumMember#value` and falls back to `EnumMember#name`:
|
|
259
|
+
|
|
260
|
+
```scala
|
|
261
|
+
val suitModel = SmithyModel.parse(
|
|
262
|
+
"""$version: "2"
|
|
263
|
+
|namespace com.example
|
|
264
|
+
|enum Suit {
|
|
265
|
+
| CLUB
|
|
266
|
+
| HEART
|
|
267
|
+
|}
|
|
268
|
+
|""".stripMargin
|
|
269
|
+
).toOption.get
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
The distinction survives parsing, which is what lets a round trip reproduce the original document:
|
|
273
|
+
|
|
274
|
+
```scala
|
|
275
|
+
suitModel.shapes
|
|
276
|
+
// res3: List[ShapeDefinition] = List(
|
|
277
|
+
// ShapeDefinition(
|
|
278
|
+
// name = "Suit",
|
|
279
|
+
// shape = EnumShape(
|
|
280
|
+
// name = "Suit",
|
|
281
|
+
// traits = List(),
|
|
282
|
+
// members = List(
|
|
283
|
+
// EnumMember(name = "CLUB", value = None, traits = List()),
|
|
284
|
+
// EnumMember(name = "HEART", value = None, traits = List())
|
|
285
|
+
// )
|
|
286
|
+
// )
|
|
287
|
+
// )
|
|
288
|
+
// )
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
An integer enum requires a value for every member, so `IntEnumMember` holds an `Int` rather than an option:
|
|
292
|
+
|
|
293
|
+
```scala
|
|
294
|
+
val cardModel = SmithyModel.parse(
|
|
295
|
+
"""$version: "2"
|
|
296
|
+
|namespace com.example
|
|
297
|
+
|intEnum FaceCard {
|
|
298
|
+
| JACK = 11
|
|
299
|
+
| QUEEN = 12
|
|
300
|
+
|}
|
|
301
|
+
|""".stripMargin
|
|
302
|
+
).toOption.get
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Reading the members gives the integers directly:
|
|
306
|
+
|
|
307
|
+
```scala
|
|
308
|
+
cardModel.shapes
|
|
309
|
+
// res4: List[ShapeDefinition] = List(
|
|
310
|
+
// ShapeDefinition(
|
|
311
|
+
// name = "FaceCard",
|
|
312
|
+
// shape = IntEnumShape(
|
|
313
|
+
// name = "FaceCard",
|
|
314
|
+
// traits = List(),
|
|
315
|
+
// members = List(
|
|
316
|
+
// IntEnumMember(name = "JACK", value = 11, traits = List()),
|
|
317
|
+
// IntEnumMember(name = "QUEEN", value = 12, traits = List())
|
|
318
|
+
// )
|
|
319
|
+
// )
|
|
320
|
+
// )
|
|
321
|
+
// )
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Aggregate Shapes
|
|
325
|
+
|
|
326
|
+
Four shapes compose other shapes, and all of them do it through `MemberDefinition` — a name, the `ShapeId` of the target, and any traits on the member itself:
|
|
327
|
+
|
|
328
|
+
| Type | IDL keyword | Members |
|
|
329
|
+
| ---------------- | ----------- | ---------------------------------------------------- |
|
|
330
|
+
| `ListShape` | `list` | `member: MemberDefinition` |
|
|
331
|
+
| `MapShape` | `map` | `key` and `value`, both `MemberDefinition` |
|
|
332
|
+
| `StructureShape` | `structure` | `members: List[MemberDefinition]` |
|
|
333
|
+
| `UnionShape` | `union` | `members: List[MemberDefinition]`, one set at a time |
|
|
334
|
+
|
|
335
|
+
A structure's members name their targets by `ShapeId`, not by nested shape, so the model stays flat and a member's target is resolved by lookup:
|
|
336
|
+
|
|
337
|
+
```scala
|
|
338
|
+
val userModel = SmithyModel.parse(
|
|
339
|
+
"""$version: "2"
|
|
340
|
+
|namespace com.example
|
|
341
|
+
|structure User {
|
|
342
|
+
| @required
|
|
343
|
+
| id: String
|
|
344
|
+
| tags: TagList
|
|
345
|
+
|}
|
|
346
|
+
|list TagList {
|
|
347
|
+
| member: String
|
|
348
|
+
|}
|
|
349
|
+
|""".stripMargin
|
|
350
|
+
).toOption.get
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
Both shapes appear at the top level, and the `tags` member of `User` points at `TagList` by reference:
|
|
354
|
+
|
|
355
|
+
```scala
|
|
356
|
+
userModel.shapes
|
|
357
|
+
// res5: List[ShapeDefinition] = List(
|
|
358
|
+
// ShapeDefinition(
|
|
359
|
+
// name = "User",
|
|
360
|
+
// shape = StructureShape(
|
|
361
|
+
// name = "User",
|
|
362
|
+
// traits = List(),
|
|
363
|
+
// members = List(
|
|
364
|
+
// MemberDefinition(
|
|
365
|
+
// name = "id",
|
|
366
|
+
// target = ShapeId(namespace = "", name = "String"),
|
|
367
|
+
// traits = List(
|
|
368
|
+
// TraitApplication(
|
|
369
|
+
// id = ShapeId(namespace = "smithy.api", name = "required"),
|
|
370
|
+
// value = None
|
|
371
|
+
// )
|
|
372
|
+
// )
|
|
373
|
+
// ),
|
|
374
|
+
// MemberDefinition(
|
|
375
|
+
// name = "tags",
|
|
376
|
+
// target = ShapeId(namespace = "", name = "TagList"),
|
|
377
|
+
// traits = List()
|
|
378
|
+
// )
|
|
379
|
+
// )
|
|
380
|
+
// )
|
|
381
|
+
// ),
|
|
382
|
+
// ShapeDefinition(
|
|
383
|
+
// name = "TagList",
|
|
384
|
+
// shape = ListShape(
|
|
385
|
+
// name = "TagList",
|
|
386
|
+
// traits = List(),
|
|
387
|
+
// member = MemberDefinition(
|
|
388
|
+
// name = "member",
|
|
389
|
+
// target = ShapeId(namespace = "", name = "String"),
|
|
390
|
+
// traits = List()
|
|
391
|
+
// )
|
|
392
|
+
// )
|
|
393
|
+
// )
|
|
394
|
+
// )
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
:::note[`member` has no default, `traits` does]
|
|
398
|
+
`ListShape` and `MapShape` declare their `Shape#traits` parameter with a default *before* the parameters that have none, so positional construction does not work — `ListShape("TagList", member = m)` compiles while `ListShape("TagList", m)` does not. `StructureShape` and `UnionShape` default their member lists, so both forms work there.
|
|
399
|
+
:::
|
|
400
|
+
|
|
401
|
+
### Service Shapes
|
|
402
|
+
|
|
403
|
+
`ServiceShape`, `OperationShape`, and `ResourceShape` describe an API rather than a value, and all of their cross-references are `ShapeId`s:
|
|
404
|
+
|
|
405
|
+
```scala
|
|
406
|
+
final case class ServiceShape(
|
|
407
|
+
name: String,
|
|
408
|
+
traits: List[TraitApplication] = Nil,
|
|
409
|
+
version: Option[String] = None,
|
|
410
|
+
operations: List[ShapeId] = Nil,
|
|
411
|
+
resources: List[ShapeId] = Nil,
|
|
412
|
+
errors: List[ShapeId] = Nil
|
|
413
|
+
) extends Shape
|
|
414
|
+
|
|
415
|
+
final case class OperationShape(
|
|
416
|
+
name: String,
|
|
417
|
+
traits: List[TraitApplication] = Nil,
|
|
418
|
+
input: Option[ShapeId] = None,
|
|
419
|
+
output: Option[ShapeId] = None,
|
|
420
|
+
errors: List[ShapeId] = Nil
|
|
421
|
+
) extends Shape
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
`ResourceShape` is the largest shape in the module, because a Smithy resource binds identifiers, five named lifecycle operations, and three further reference lists:
|
|
425
|
+
|
|
426
|
+
| Field | Type | Meaning |
|
|
427
|
+
| ---------------------- | ---------------------- | ------------------------------------------------- |
|
|
428
|
+
| `identifiers` | `Map[String, ShapeId]` | Identifier names mapped to their target shapes |
|
|
429
|
+
| `create` | `Option[ShapeId]` | Create lifecycle operation |
|
|
430
|
+
| `read` | `Option[ShapeId]` | Read lifecycle operation |
|
|
431
|
+
| `update` | `Option[ShapeId]` | Update lifecycle operation |
|
|
432
|
+
| `delete` | `Option[ShapeId]` | Delete lifecycle operation |
|
|
433
|
+
| `list` | `Option[ShapeId]` | List lifecycle operation |
|
|
434
|
+
| `operations` | `List[ShapeId]` | Instance operations that are not lifecycle ones |
|
|
435
|
+
| `collectionOperations` | `List[ShapeId]` | Operations on the collection rather than one item |
|
|
436
|
+
| `resources` | `List[ShapeId]` | Child resources |
|
|
437
|
+
|
|
438
|
+
The five lifecycle fields are separate rather than a map, which is what makes "does this resource support deletion?" a field access instead of a lookup:
|
|
439
|
+
|
|
440
|
+
```scala
|
|
441
|
+
val resourceModel = SmithyModel.parse(
|
|
442
|
+
"""$version: "2"
|
|
443
|
+
|namespace com.example
|
|
444
|
+
|resource FooResource {
|
|
445
|
+
| identifiers: {id: FooId}
|
|
446
|
+
| read: GetFoo
|
|
447
|
+
| list: ListFoos
|
|
448
|
+
|}
|
|
449
|
+
|""".stripMargin
|
|
450
|
+
).toOption.get
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
Unset lifecycle operations stay `None`, so an absent `create` is distinguishable from one bound to an operation:
|
|
454
|
+
|
|
455
|
+
```scala
|
|
456
|
+
resourceModel.shapes
|
|
457
|
+
// res6: List[ShapeDefinition] = List(
|
|
458
|
+
// ShapeDefinition(
|
|
459
|
+
// name = "FooResource",
|
|
460
|
+
// shape = ResourceShape(
|
|
461
|
+
// name = "FooResource",
|
|
462
|
+
// traits = List(),
|
|
463
|
+
// identifiers = Map("id" -> ShapeId(namespace = "", name = "FooId")),
|
|
464
|
+
// create = None,
|
|
465
|
+
// read = Some(ShapeId(namespace = "", name = "GetFoo")),
|
|
466
|
+
// update = None,
|
|
467
|
+
// delete = None,
|
|
468
|
+
// list = Some(ShapeId(namespace = "", name = "ListFoos")),
|
|
469
|
+
// operations = List(),
|
|
470
|
+
// collectionOperations = List(),
|
|
471
|
+
// resources = List()
|
|
472
|
+
// )
|
|
473
|
+
// )
|
|
474
|
+
// )
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### Shape References
|
|
478
|
+
|
|
479
|
+
Every cross-shape reference is a `ShapeRef`, a sealed trait with exactly two cases:
|
|
480
|
+
|
|
481
|
+
```scala
|
|
482
|
+
sealed trait ShapeRef
|
|
483
|
+
|
|
484
|
+
final case class ShapeId(namespace: String, name: String) extends ShapeRef
|
|
485
|
+
|
|
486
|
+
object ShapeId {
|
|
487
|
+
final case class Member(shape: ShapeId, memberName: String) extends ShapeRef
|
|
488
|
+
def parse(s: String): Either[String, ShapeRef]
|
|
489
|
+
}
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
`ShapeRef` exists to give `ShapeId` and `ShapeId.Member` a common supertype without a Scala 3 union type, so the same signatures compile on 2.13.
|
|
493
|
+
|
|
494
|
+
Rendering follows the IDL: a shape is `namespace#name`, and a member appends `$` and the member name:
|
|
495
|
+
|
|
496
|
+
```scala
|
|
497
|
+
ShapeId("com.example", "User").toString
|
|
498
|
+
// res7: String = "com.example#User"
|
|
499
|
+
ShapeId.Member(ShapeId("com.example", "User"), "id").toString
|
|
500
|
+
// res8: String = "com.example#User$id"
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
`ShapeId.parse` reads either form back, choosing the case by whether a `$` is present:
|
|
504
|
+
|
|
505
|
+
```scala
|
|
506
|
+
ShapeId.parse("com.example#User")
|
|
507
|
+
// res9: Either[String, ShapeRef] = Right(
|
|
508
|
+
// ShapeId(namespace = "com.example", name = "User")
|
|
509
|
+
// )
|
|
510
|
+
ShapeId.parse("com.example#User$id")
|
|
511
|
+
// res10: Either[String, ShapeRef] = Right(
|
|
512
|
+
// Member(
|
|
513
|
+
// shape = ShapeId(namespace = "com.example", name = "User"),
|
|
514
|
+
// memberName = "id"
|
|
515
|
+
// )
|
|
516
|
+
// )
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
Malformed input is reported rather than thrown, and the message names the rule that failed:
|
|
520
|
+
|
|
521
|
+
```scala
|
|
522
|
+
ShapeId.parse("User")
|
|
523
|
+
// res11: Either[String, ShapeRef] = Left(
|
|
524
|
+
// "ShapeId must contain '#' separator, got: User"
|
|
525
|
+
// )
|
|
526
|
+
ShapeId.parse("com.example#User$id$extra")
|
|
527
|
+
// res12: Either[String, ShapeRef] = Left(
|
|
528
|
+
// "Member reference must have exactly one separator, got: com.example#User$id$extra"
|
|
529
|
+
// )
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
#### Resolving a Reference
|
|
533
|
+
|
|
534
|
+
A reference names a shape; it does not contain one. Resolving means looking the target up in the model, which `SmithyModel#findShape` does by **name** rather than by `ShapeId`:
|
|
535
|
+
|
|
536
|
+
```scala
|
|
537
|
+
final case class SmithyModel(...) {
|
|
538
|
+
def findShape(name: String): Option[ShapeDefinition]
|
|
539
|
+
def allShapeIds: List[ShapeId]
|
|
540
|
+
}
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
Following a structure member to its target definition is therefore a lookup on the name inside the `ShapeId`:
|
|
544
|
+
|
|
545
|
+
```scala
|
|
546
|
+
val tagsTarget = userModel.shapes
|
|
547
|
+
.collectFirst { case ShapeDefinition("User", s: StructureShape) => s }
|
|
548
|
+
.flatMap(_.members.find(_.name == "tags"))
|
|
549
|
+
.map(_.target)
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
The member's target resolves to the `list` shape declared alongside it:
|
|
553
|
+
|
|
554
|
+
```scala
|
|
555
|
+
tagsTarget
|
|
556
|
+
// res13: Option[ShapeId] = Some(ShapeId(namespace = "", name = "TagList"))
|
|
557
|
+
tagsTarget.flatMap(id => userModel.findShape(id.name))
|
|
558
|
+
// res14: Option[ShapeDefinition] = Some(
|
|
559
|
+
// ShapeDefinition(
|
|
560
|
+
// name = "TagList",
|
|
561
|
+
// shape = ListShape(
|
|
562
|
+
// name = "TagList",
|
|
563
|
+
// traits = List(),
|
|
564
|
+
// member = MemberDefinition(
|
|
565
|
+
// name = "member",
|
|
566
|
+
// target = ShapeId(namespace = "", name = "String"),
|
|
567
|
+
// traits = List()
|
|
568
|
+
// )
|
|
569
|
+
// )
|
|
570
|
+
// )
|
|
571
|
+
// )
|
|
572
|
+
```
|
|
573
|
+
|
|
574
|
+
Looking up by name rather than by `ShapeId` is not a shortcut — it matches what the parser produces. An IDL target written without a namespace prefix becomes a `ShapeId` whose namespace is the **empty string**, not the model's namespace and not `smithy.api`:
|
|
575
|
+
|
|
576
|
+
```scala
|
|
577
|
+
userModel.shapes.collect { case ShapeDefinition(_, s: ListShape) => s.member.target }
|
|
578
|
+
// res15: List[ShapeId] = List(ShapeId(namespace = "", name = "String"))
|
|
579
|
+
resourceModel.shapes.collect { case ShapeDefinition(_, s: ResourceShape) => s.identifiers }
|
|
580
|
+
// res16: List[Map[String, ShapeId]] = List(
|
|
581
|
+
// Map("id" -> ShapeId(namespace = "", name = "FooId"))
|
|
582
|
+
// )
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
Trait identifiers are the exception: the parser resolves those against the prelude, so `@required` arrives fully qualified:
|
|
586
|
+
|
|
587
|
+
```scala
|
|
588
|
+
userModel.shapes
|
|
589
|
+
.collect { case ShapeDefinition("User", s: StructureShape) => s }
|
|
590
|
+
.flatMap(_.members.flatMap(_.traits.map(_.id)))
|
|
591
|
+
// res17: List[ShapeId] = List(
|
|
592
|
+
// ShapeId(namespace = "smithy.api", name = "required")
|
|
593
|
+
// )
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
Two consequences follow. A reference to a prelude shape such as `String` has no definition in the parsed model, so resolving it yields nothing — a consumer generating code has to recognize prelude names itself:
|
|
597
|
+
|
|
598
|
+
```scala
|
|
599
|
+
userModel.findShape("String")
|
|
600
|
+
// res18: Option[ShapeDefinition] = None
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
And a `ShapeId` taken from a parsed model does not necessarily round-trip through `ShapeId.parse`, because the renderer emits the empty namespace as a bare `#` that the parser then rejects:
|
|
604
|
+
|
|
605
|
+
```scala
|
|
606
|
+
ShapeId("", "String").toString
|
|
607
|
+
// res19: String = "#String"
|
|
608
|
+
ShapeId.parse(ShapeId("", "String").toString)
|
|
609
|
+
// res20: Either[String, ShapeRef] = Left("ShapeId namespace cannot be empty")
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
:::warning[Namespaces on references are not populated]
|
|
613
|
+
Because unprefixed targets carry an empty namespace, comparing `ShapeId#namespace` on a parsed reference tells you nothing unless the IDL spelled the namespace out. `SmithyModel#findShape` matching on name alone is consistent with that, but it also means a model that uses a `use` statement to import `other.ns#User` while declaring its own `User` cannot distinguish the two by reference alone.
|
|
614
|
+
:::
|
|
615
|
+
|
|
117
616
|
## Parsing
|
|
118
617
|
|
|
119
618
|
Parse Smithy IDL text into structured models using `SmithyModel.parse`, handle errors, and validate round-trips.
|
|
@@ -50,7 +50,7 @@ DbCodec[User].columns
|
|
|
50
50
|
case class Event(eventId: Long, eventType: String)
|
|
51
51
|
object Event { implicit val schema: Schema[Event] = Schema.derived }
|
|
52
52
|
val eventCodec = DbCodec.derived[Event]
|
|
53
|
-
// eventCodec: DbCodec[Event] = zio.blocks.sql.DbCodecDeriver$$anon$
|
|
53
|
+
// eventCodec: DbCodec[Event] = zio.blocks.sql.DbCodecDeriver$$anon$10@5ff67e34
|
|
54
54
|
eventCodec.columns
|
|
55
55
|
// res1: IndexedSeq[String] = Vector("event_id", "event_type")
|
|
56
56
|
|
|
@@ -59,9 +59,9 @@ case class Widget(widgetId: Int, widgetName: String)
|
|
|
59
59
|
object Widget { implicit val schema: Schema[Widget] = Schema.derived }
|
|
60
60
|
|
|
61
61
|
val identityDeriver = DbCodecDeriver.withColumnNameMapper(SqlNameMapper.Identity)
|
|
62
|
-
// identityDeriver: DbCodecDeriver = zio.blocks.sql.DbCodecDeriver@
|
|
62
|
+
// identityDeriver: DbCodecDeriver = zio.blocks.sql.DbCodecDeriver@502cd2f2
|
|
63
63
|
val widgetCodec = Widget.schema.deriving(identityDeriver).derive
|
|
64
|
-
// widgetCodec: DbCodec[Widget] = zio.blocks.sql.DbCodecDeriver$$anon$
|
|
64
|
+
// widgetCodec: DbCodec[Widget] = zio.blocks.sql.DbCodecDeriver$$anon$10@151213be
|
|
65
65
|
widgetCodec.columns
|
|
66
66
|
// res2: IndexedSeq[String] = Vector("widgetId", "widgetName")
|
|
67
67
|
```
|