SPICE-0024: Annotation converters (#1333)

This enables defining declarative key and/or value transformations in
cases where neither `Class`- nor path-based converters can be applied
gracefully. It is also the only way to express transforming the
resulting property names in `Typed` objects without applying a converter
to the entire containing type, which is cumbersome at best.

SPICE: https://github.com/apple/pkl-evolution/pull/26
This commit is contained in:
Jen Basch
2026-01-23 12:44:41 -08:00
committed by GitHub
parent ed0cad668f
commit 73264e8fd1
51 changed files with 773 additions and 141 deletions
+12
View File
@@ -32,6 +32,11 @@
module pkl.pklbinary
/// Render values as `pkl-binary`.
///
/// The `pkl-binary` renderer disables all [ConvertProperty] annotation converters by default
/// because `pkl-binary` data is intended to closely represent native Pkl types and data.
/// This behavior may be overridden for [ConvertProperty] or its subclasses by adding an entry to
/// [Renderer.convertPropertyTransformers].
class Renderer extends BytesRenderer {
/// Renders [value] as `pkl-binary`.
external function renderValue(value: Any): Bytes
@@ -40,4 +45,11 @@ class Renderer extends BytesRenderer {
///
/// Every `pkl-binary` value is also a valid document.
external function renderDocument(value: Any): Bytes
convertPropertyTransformers {
// disable all property conversions by default
[ConvertProperty] {
render = (property, _) -> property
}
}
}