mirror of
https://github.com/apple/pkl.git
synced 2026-01-13 15:13:38 +01:00
Reference<T>: Type safe "deferred" references
#269
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @HT154 on GitHub (Jan 28, 2025).
One common pattern in infrastructure-as-code systems like Terraform and Pulumi is "references". A reference provides a way to refer to a resource (or a property thereof) that exists at a time after Pkl evaluation completes.
Example: The pulumi aws-yaml-static-website example creates a
aws:s3:BucketV2and creates aaws:s3:BucketPolicythat both directly references the bucket and a property of the bucket (itsarn). In the case of the Pulumi YAML runtime, references are rendered as String sequences beginning with${and ending with}.It would be useful for a Pkl module representing the
aws:s3:BucketPolicyresource to define itsbucketlike so:There should be an API within the standard library for representing and producing such references. How a reference is rendered or otherwise consumed would be module-dependent. At minimum, the
ReferenceAPI should look something like this:Referenceshould also exhibit covariance: given aclass Tand a subclassclass U extends T,Reference<U>should be a subtype ofReference<T>.It may also be beneficial to add syntax sugar for producing references, so these two expressions would be equivalent:
This requires a SPICE to be written to iterate on the design.
@bioball commented on GitHub (Jan 28, 2025):
Thanks for getting the ball rolling.
The basic idea here is that a
Reference<T>would have the same property accessors asT, except all accessors continue to give you aReference.Users would use output converters when rendering this. For example, maybe something like:
Produces: