Skip to content

Commit cc879fd

Browse files
committed
Add ARCtrl.Yaml:
- Uses YAMLicious - tries to mirror ARCtrl.Json - Encoder/Decoder logic for ValidatioNpackages type model
1 parent c59b883 commit cc879fd

5 files changed

Lines changed: 175 additions & 0 deletions

File tree

src/Yaml/ARCtrl.Yaml.fsproj

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Compile Include="Encode.fs" />
9+
<Compile Include="Decode.fs" />
10+
<Compile Include="ValidationPackage.fs" />
11+
<Compile Include="ValidationPackagesConfig.fs" />
12+
<None Include="../../build/logo.png" Pack="true" PackagePath="\" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<PackageReference Include="YAMLicious" Version="0.0.1-alpha" />
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ProjectReference Include="..\Core\ARCtrl.Core.fsproj" />
19+
<ProjectReference Include="..\ValidationPackages\ARCtrl.ValidationPackages.fsproj" />
20+
</ItemGroup>
21+
<PropertyGroup>
22+
<Authors>nfdi4plants</Authors>
23+
<Description>ARC helper functions for Common workflow language.</Description>
24+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
25+
<PackageIcon>logo.png</PackageIcon>
26+
<PackageTags>ARC F# FSharp dotnet .Net bioinformatics biology fable-library datascience dataplant nfdi metadata</PackageTags>
27+
<PackageProjectUrl>https://github.com/nfdi4plants/ARCtrl/tree/main/src/CWL</PackageProjectUrl>
28+
<RepositoryUrl>https://github.com/nfdi4plants/ARCtrl</RepositoryUrl>
29+
<RepositoryType>git</RepositoryType>
30+
</PropertyGroup>
31+
</Project>

src/Yaml/Decode.fs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
namespace Arctrl.Yaml
2+
3+
module Decode =
4+
5+
// yamlicious equivalents for this?
6+
7+
//let helpers =
8+
// #if FABLE_COMPILER_PYTHON
9+
// Thoth.Json.Python.Decode.helpers
10+
// #endif
11+
// #if FABLE_COMPILER_JAVASCRIPT
12+
// Thoth.Json.JavaScript.Decode.helpers
13+
// #endif
14+
// #if !FABLE_COMPILER
15+
// Thoth.Json.Newtonsoft.Decode.helpers
16+
// #endif
17+
18+
//let inline fromJsonString (decoder : Decoder<'a>) (s : string) : 'a =
19+
// #if FABLE_COMPILER_PYTHON
20+
// match Thoth.Json.Python.Decode.fromString decoder s with
21+
// #endif
22+
// #if FABLE_COMPILER_JAVASCRIPT
23+
// match Thoth.Json.JavaScript.Decode.fromString decoder s with
24+
// #endif
25+
// #if !FABLE_COMPILER
26+
// match Thoth.Json.Newtonsoft.Decode.fromString decoder s with
27+
// #endif
28+
// | Ok a -> a
29+
// | Error e -> failwith (sprintf "Error decoding string: %O" e)
30+
31+
open YAMLicious
32+
open YAMLicious.YAMLiciousTypes
33+
open YAMLicious.Reader
34+
35+
let inline fromYamlString (decoder : YAMLElement -> 'a) (s : string) : 'a =
36+
read s |> decoder

src/Yaml/Encode.fs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Arctrl.Yaml
2+
3+
module Encode =
4+
5+
open YAMLicious
6+
open YAMLicious.YAMLiciousTypes
7+
open YAMLicious.Writer
8+
9+
let DefaultWhitespace = 2
10+
11+
let defaultWhitespace spaces = defaultArg spaces DefaultWhitespace
12+
13+
let inline toYamlString whitespace (element : YAMLElement) =
14+
write element (Some (fun c -> {c with Whitespace = whitespace}))

src/Yaml/ValidationPackage.fs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
namespace ARCtrl.Yaml
2+
3+
open ARCtrl.ValidationPackages
4+
open YAMLicious
5+
open YAMLicious.YAMLiciousTypes
6+
7+
module ValidationPackage =
8+
9+
let encoder (validationpackage : ValidationPackage) =
10+
[
11+
"name", Encode.string validationpackage.Name
12+
Encode.tryInclude "version" Encode.string (validationpackage.Version)
13+
]
14+
|> Encode.choose
15+
|> Encode.object
16+
17+
let decoder : (YAMLElement -> ValidationPackage) =
18+
Decode.object (fun get ->
19+
ValidationPackage(
20+
name = get.Required.Field "name" Decode.string,
21+
?version = get.Optional.Field "version" Decode.string
22+
)
23+
)
24+
25+
[<AutoOpen>]
26+
module ValidationPackageExtensions =
27+
28+
open Arctrl.Yaml
29+
type ValidationPackage with
30+
31+
static member fromYamlString (s:string) =
32+
Decode.fromYamlString ValidationPackage.decoder s
33+
34+
static member toYamlString(?whitespace) =
35+
fun (vp:ValidationPackage) ->
36+
ValidationPackage.encoder vp
37+
|> Encode.toYamlString (Encode.defaultWhitespace whitespace)
38+
39+
member this.toYamlString(?whitespace) =
40+
ValidationPackage.toYamlString(?whitespace=whitespace) this
41+
42+
//let fromFile (path : string) =
43+
// File.ReadAllText path
44+
// |> fromString
45+
46+
//let toFile (path : string) (c:Comment) =
47+
// File.WriteAllText(path,toString c)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
namespace ARCtrl.Yaml
2+
3+
open ARCtrl.ValidationPackages
4+
open YAMLicious
5+
open YAMLicious.YAMLiciousTypes
6+
7+
module ValidationPackagesConfig =
8+
9+
let encoder (validationpackage : ValidationPackagesConfig) =
10+
[
11+
"validation_packages", Encode.array ValidationPackage.encoder validationpackage.ValidationPackages
12+
Encode.tryInclude "arc_specification" Encode.string (validationpackage.ARCSpecification)
13+
]
14+
|> Encode.choose
15+
|> Encode.object
16+
17+
let decoder : (YAMLElement -> ValidationPackagesConfig) =
18+
Decode.object (fun get ->
19+
ValidationPackagesConfig(
20+
validation_packages = get.Required.Field "validation_packages" (Decode.array ValidationPackage.decoder),
21+
?arc_specification = get.Optional.Field "arc_specification" Decode.string
22+
)
23+
)
24+
25+
[<AutoOpen>]
26+
module ValidationPackageConfigExtensions =
27+
28+
open Arctrl.Yaml
29+
type ValidationPackagesConfig with
30+
31+
static member fromYamlString (s:string) =
32+
Decode.fromYamlString ValidationPackagesConfig.decoder s
33+
34+
static member toYamlString(?whitespace) =
35+
fun (vp:ValidationPackagesConfig) ->
36+
ValidationPackagesConfig.encoder vp
37+
|> Encode.toYamlString (Encode.defaultWhitespace whitespace)
38+
39+
member this.toYamlString(?whitespace) =
40+
ValidationPackagesConfig.toYamlString(?whitespace=whitespace) this
41+
42+
//let fromFile (path : string) =
43+
// File.ReadAllText path
44+
// |> fromString
45+
46+
//let toFile (path : string) (c:Comment) =
47+
// File.WriteAllText(path,toString c)

0 commit comments

Comments
 (0)