Skip to content

Commit

Permalink
Add contract handling for validation_packages.yml to top-level ARC API
Browse files Browse the repository at this point in the history
  • Loading branch information
kMutagene committed Jul 15, 2024
1 parent b510ab2 commit 9c70c5d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
37 changes: 36 additions & 1 deletion src/ARCtrl/ARC.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace ARCtrl

open ARCtrl.ValidationPackages
open ARCtrl.FileSystem
open ARCtrl.Contract
open ARCtrl
Expand Down Expand Up @@ -60,7 +61,8 @@ module ARCAux =
let tree =
FileSystemTree.createRootFolder [|workflows;runs|]
|> FileSystem.create
fs.Union(tree)
fs.Union(tree)


[<AttachMembers>]
type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSystem) =
Expand Down Expand Up @@ -570,6 +572,39 @@ type ARC(?isa : ArcInvestigation, ?cwl : CWL.CWL, ?fs : FileSystem.FileSystem) =
ARCtrl.Json.ARC.ROCrate.encoder (Option.get obj.ISA)
|> ARCtrl.Json.Encode.toJsonString (ARCtrl.Json.Encode.defaultSpaces spaces)

/// <summary>
/// Returns the write contract for the input ValidationPackagesConfig object.
///
/// This will mutate the ARC file system to include the `.arc/validation_packages.yml` file if it is not already included.
/// </summary>
/// <param name="vpc">the config to write</param>
member this.GetValidationPackagesConfigWriteContract(vpc: ValidationPackagesConfig) =
let paths = this.FileSystem.Tree.ToFilePaths()
if not (Array.contains ValidationPackagesConfigHelper.ConfigFilePath paths) then
Array.append [|ValidationPackagesConfigHelper.ConfigFilePath|] paths
|> this.SetFilePaths
ValidationPackagesConfig.toCreateContract vpc

/// <summary>
/// Returns the delete contract for `.arc/validation_packages.yml`
/// </summary>
/// <param name="vpc"></param>
member this.GetValidationPackagesConfigDeleteContract(vpc) =
ValidationPackagesConfig.toDeleteContract vpc

/// <summary>
/// Returns the read contract for `.arc/validation_packages.yml`
/// </summary>
member this.GetValidationPackagesConfigReadContract() =
ValidationPackagesConfigHelper.ReadContract

/// <summary>
/// Returns the ValidationPackagesConfig object from the given read contract if possible, otherwise returns None/null.
/// </summary>
/// <param name="contract">the input contract that contains the config in it's DTO</param>
member this.GetValidationPackagesConfigFromReadContract(contract) =
ValidationPackagesConfig.tryFromReadContract contract

//-Pseudo code-//
//// Option 1
//let fs, readcontracts = ARC.FSFromFilePaths filepaths
Expand Down
25 changes: 12 additions & 13 deletions src/Contract/ValidationPackagesConfig.fs
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
namespace ARCtrl.Contract

open ARCtrl.FileSystem
open ARCtrl.ArcPathHelper
open ARCtrl.Path
open ARCtrl
open ARCtrl.Yaml
open ARCtrl.Helper
open ARCtrl.ValidationPackages

module ValidationPackagesConfigHelper =

let ConfigFilePath = [|ARCConfigFolderName; ValidationPackagesYamlFileName|] |> ARCtrl.Path.combineMany

let ReadContract : Contract = {Operation = READ; DTOType = Some DTOType.YAML; Path = ConfigFilePath; DTO = None}


[<AutoOpen>]
module ValidationPackagesConfigExtensions =

let (|ValidationPackagesYamlPath|_|) (input) =
match input with
| [|ARCConfigFolderName; ValidationPackagesYamlFileName|] ->
let path = ARCtrl.ArcPathHelper.combineMany input
let path = ARCtrl.Path.combineMany input
Some path
| _ -> None

let internal config_file_path = [|ARCConfigFolderName; ValidationPackagesYamlFileName|] |> ARCtrl.ArcPathHelper.combineMany

type ValidationPackagesConfig with

member this.ToCreateContract () =
Contract.createCreate(config_file_path, DTOType.YAML, DTO.Text (this |> ValidationPackagesConfig.toYamlString()))

member this.ToUpdateContract () =
Contract.createUpdate(config_file_path, DTOType.YAML, DTO.Text (this |> ValidationPackagesConfig.toYamlString()))
Contract.createCreate(ValidationPackagesConfigHelper.ConfigFilePath, DTOType.YAML, DTO.Text (this |> ValidationPackagesConfig.toYamlString()))

member this.ToDeleteContract () =
Contract.createDelete(config_file_path)
Contract.createDelete(ValidationPackagesConfigHelper.ConfigFilePath)

static member toDeleteContract (config: ValidationPackagesConfig) : Contract =
config.ToDeleteContract()

static member toCreateContract (config: ValidationPackagesConfig) : Contract =
config.ToCreateContract()

static member toUpdateContract (config: ValidationPackagesConfig) : Contract =
config.ToUpdateContract()

static member tryFromReadContract (c:Contract) =
match c with
| {Operation = READ; DTOType = Some DTOType.YAML; DTO = Some (DTO.Text yaml)} ->
| {Operation = READ; DTOType = Some DTOType.YAML; Path = p; DTO = Some (DTO.Text yaml)} when p = ValidationPackagesConfigHelper.ConfigFilePath ->
yaml
|> ValidationPackagesConfig.fromYamlString
|> Some
Expand Down

0 comments on commit 9c70c5d

Please sign in to comment.