Skip to content

Commit e3e412e

Browse files
committed
add transform fn
1 parent 30f62d5 commit e3e412e

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
run: |
4040
curl -L https://github.com/dhall-lang/dhall-haskell/releases/download/1.40.1/dhall-docs-1.0.7-x86_64-linux.tar.bz2 | tar --extract --bzip2
4141
VERSION=$(dhall text < ./version.dhall)
42-
./bin/dhall-docs --input ./ --base-import-url https://github.com/jcouyang/dhall-aws-cloudformation/raw/${VERSION}
42+
./bin/dhall-docs --input ./ --base-import-url https://raw.githubusercontent.com/jcouyang/dhall-aws-cloudformation/${VERSION}
4343
cp -r docs/* gh-pages/
4444
cd gh-pages
4545
git config user.name github-actions

Fn.dhall

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ let JSON = (./Prelude.dhall).JSON
22

33
let map = (./Prelude.dhall).List.map
44

5+
let Map = (./Prelude.dhall).Map
6+
57
let _Pi =
68
λ(Fn : Type)
79
{ ImportValue : Fn Fn
@@ -16,6 +18,7 @@ let _Pi =
1618
, Cidr : Fn Natural Natural Fn
1719
, Select : Natural Fn Fn
1820
, FindInMap : Fn Fn Fn
21+
, Transform : Text Map.Type Text Fn Fn
1922
}
2023

2124
let Fn/Type
@@ -100,6 +103,15 @@ let Ref
100103
: (x : Fn/Type) Fn/Type
101104
= λ(x : Fn/Type) λ(Fn : Type) λ(fn : _Pi Fn) fn.Ref (x Fn fn)
102105

106+
let Transform =
107+
λ(name : Text)
108+
λ(param : Map.Type Text Fn/Type)
109+
λ(Fn : Type)
110+
λ(fn : _Pi Fn)
111+
fn.Transform
112+
name
113+
(Map.map Text Fn/Type Fn (λ(x : Fn/Type) x Fn fn) param)
114+
103115
let toJSON =
104116
λ(x : Fn/Type)
105117
x
@@ -156,6 +168,20 @@ let toJSON =
156168
JSON.object
157169
(toMap { `Fn::FindInMap` = JSON.array [ map, key ] })
158170
, String = λ(x : Text) JSON.string x
171+
, Transform =
172+
λ(name : Text)
173+
λ(param : Map.Type Text JSON.Type)
174+
JSON.object
175+
( toMap
176+
{ `Fn::Transform` =
177+
JSON.object
178+
( toMap
179+
{ Name = JSON.string name
180+
, Parameters = JSON.object param
181+
}
182+
)
183+
}
184+
)
159185
}
160186

161187
let exampleImportValue =
@@ -280,6 +306,28 @@ let exampleSplit =
280306
}
281307
''
282308

309+
let exampleTransform =
310+
assert
311+
: JSON.render
312+
( toJSON
313+
( Transform
314+
"AWS::Include"
315+
( toMap
316+
{ Location =
317+
String "s3://MyAmazonS3BucketName/MyFileName.json"
318+
}
319+
)
320+
)
321+
)
322+
''
323+
{
324+
"Fn::Transform": {
325+
"Name": "AWS::Include",
326+
"Parameters": { "Location": "s3://MyAmazonS3BucketName/MyFileName.json" }
327+
}
328+
}
329+
''
330+
283331
in { Ref
284332
, Base64
285333
, Cidr

README.md.dhall

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ in ''
5353
- [x] Fn::Select
5454
- [x] Fn::Split
5555
- [x] Fn::Sub
56-
- [ ] Fn::Transform
56+
- [x] Fn::Transform
5757
- [x] Ref
5858

5959
### Type Safe `Fn::GetAttr`

0 commit comments

Comments
 (0)