Repository navigation
·
21 commits
to main
since this release
Immutable
release. Only release title and notes can be modified.
Hosts can now serve modules and resources under their own URI schemes, either in process or through Pkl external reader processes. This release also fixes four evaluation bugs and the build on 32-bit targets without 64-bit atomics.
Added
- Module and resource readers for custom URI schemes (#495) @jdx. A host can register a reader for its own scheme. Configs can then
import,amendsandread()from that scheme without writing files to disk.pklr::EvaluatorBuilder::new() .module_reader("myapp", |uri: &str| -> pklr::Result<Option<String>> { Ok(match uri { "myapp:/Config.pkl" => Some(include_str!("Config.pkl").to_string()), _ => None, }) }) // A config can now `amends "myapp:/Config.pkl"`. .eval_to_json(std::path::Path::new("config.pkl"))
EvaluatorBuilder::module_readerandresource_readeraccept aModuleReaderorResourceReader, and closures work too.Evaluator::set_module_readerandset_resource_readerdo the same on an existing evaluator.- Module URIs must be hierarchical (
myapp:/a/b.pkl). Relative imports, triple-dot imports, dot-segment normalization, the module allowlist and the import cache all work as they do for files. Opaque URIs such asmyapp:Configare rejected with an error that shows the hierarchical form. - Resource reader schemes are added to the default allowed resources, as in Pkl. If you set
allowed_resourcesyourself, your list is used as is. - Built-in schemes can't be replaced. If a reader is registered for an invalid scheme, every evaluation fails with a clear error.
- With the new opt-in
external-readersfeature,external_module_reader(scheme, exe, args)andexternal_resource_reader(...)run a reader process that speaks Pkl's message passing protocol. The process starts on first use and is shared by one command.pklr::external_readeralso provides the message codec (Message,read_message,write_message), so you can write a reader thatpkl eval --external-module-readercan also run. The codec has been checked against the spec but not yet against the realpklCLI.
Fixed
- Undeclared properties are now rejected on every amendment of a non-open class (#496) @jdx. A typo such as
aprove = trueused to appear in the output without an error when it was set in a typedMapping<String, N>entry, an amend expression(a) { ... }, a nested body, or an amending module. These cases now fail withcannot add property 'aprove' to non-open class N, the same error thatnew N { ... }already gave. Open classes,Dynamic, untyped values, and inherited,hiddenandlocalmembers are still accepted. Compatibility note: configs that relied on this silent acceptance now fail. Declare the property on the class or remove it. - List elements repeated through
amendschains (#497) @jdx. If a module amended aMappingentry's listing (for examplem { ["a"] { also { "x"; "y" } } }), a module that amended it again repeated the elements: three times through one wrapper module and five times through two. The elements now appear once at every depth. A listing that reads a member overridden by a later module now uses the override. read?of a missing resource could return another reader's cached value (#498) @jdx. A missing resource now always reads asnull.- Hidden members assigned inside a
whengenerator showed up in the output (#499) @jdx. Withclass C { hidden h: Int = 1; y: Int = h },new C { when (true) { h = 5 } }rendered{"h": 5, "y": 1}. It now renders{"y": 5}, the same asnew C { h = 5 }. - Build failure on 32-bit targets without 64-bit atomics (#486) @jdx. pklr now compiles on targets such as 32-bit PowerPC and MIPS. The build failure was reported while building hk through MacPorts. The
FetchBudgetAPI and its behavior are unchanged.
Full Changelog: v6.0.4...v6.1.0