Skip to content

Commit

Permalink
add transform fn
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouyang committed Sep 28, 2021
1 parent 30f62d5 commit e3e412e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: |
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
VERSION=$(dhall text < ./version.dhall)
./bin/dhall-docs --input ./ --base-import-url https://github.com/jcouyang/dhall-aws-cloudformation/raw/${VERSION}
./bin/dhall-docs --input ./ --base-import-url https://raw.githubusercontent.com/jcouyang/dhall-aws-cloudformation/${VERSION}
cp -r docs/* gh-pages/
cd gh-pages
git config user.name github-actions
Expand Down
48 changes: 48 additions & 0 deletions Fn.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ let JSON = (./Prelude.dhall).JSON

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

let Map = (./Prelude.dhall).Map

let _Pi =
λ(Fn : Type)
{ ImportValue : Fn Fn
Expand All @@ -16,6 +18,7 @@ let _Pi =
, Cidr : Fn Natural Natural Fn
, Select : Natural Fn Fn
, FindInMap : Fn Fn Fn
, Transform : Text Map.Type Text Fn Fn
}

let Fn/Type
Expand Down Expand Up @@ -100,6 +103,15 @@ let Ref
: (x : Fn/Type) Fn/Type
= λ(x : Fn/Type) λ(Fn : Type) λ(fn : _Pi Fn) fn.Ref (x Fn fn)

let Transform =
λ(name : Text)
λ(param : Map.Type Text Fn/Type)
λ(Fn : Type)
λ(fn : _Pi Fn)
fn.Transform
name
(Map.map Text Fn/Type Fn (λ(x : Fn/Type) x Fn fn) param)

let toJSON =
λ(x : Fn/Type)
x
Expand Down Expand Up @@ -156,6 +168,20 @@ let toJSON =
JSON.object
(toMap { `Fn::FindInMap` = JSON.array [ map, key ] })
, String = λ(x : Text) JSON.string x
, Transform =
λ(name : Text)
λ(param : Map.Type Text JSON.Type)
JSON.object
( toMap
{ `Fn::Transform` =
JSON.object
( toMap
{ Name = JSON.string name
, Parameters = JSON.object param
}
)
}
)
}

let exampleImportValue =
Expand Down Expand Up @@ -280,6 +306,28 @@ let exampleSplit =
}
''

let exampleTransform =
assert
: JSON.render
( toJSON
( Transform
"AWS::Include"
( toMap
{ Location =
String "s3://MyAmazonS3BucketName/MyFileName.json"
}
)
)
)
''
{
"Fn::Transform": {
"Name": "AWS::Include",
"Parameters": { "Location": "s3://MyAmazonS3BucketName/MyFileName.json" }
}
}
''

in { Ref
, Base64
, Cidr
Expand Down
2 changes: 1 addition & 1 deletion README.md.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ in ''
- [x] Fn::Select
- [x] Fn::Split
- [x] Fn::Sub
- [ ] Fn::Transform
- [x] Fn::Transform
- [x] Ref

### Type Safe `Fn::GetAttr`
Expand Down

0 comments on commit e3e412e

Please sign in to comment.