Overview
Comment: | Add json decoder for PackageMetadata. Missing validation of key values in dependencies field, and should probably clean up the code a little before continuing. |
---|---|
Timelines: | family | ancestors | descendants | both | modules |
Files: | files | file ages | folders |
SHA3-256: |
38d406f888952900fcac4881d40b8974 |
User & Date: | robin.hansen on 2021-02-14 11:47:04 |
Other Links: | branch diff | manifest | tags |
Context
2021-02-15
| ||
09:38 | Refactor code to improve readability. Also validate key entries of dependencies field in play.json. check-in: b5d7173dee user: robin.hansen tags: modules | |
2021-02-14
| ||
11:47 | Add json decoder for PackageMetadata. Missing validation of key values in dependencies field, and sh... check-in: 38d406f888 user: robin.hansen tags: modules | |
10:59 | SemanticVersion now returns descriptive error messages. check-in: 635fab0eeb user: robin.hansen tags: modules | |
Changes
Modified src/Play/Data/PackageMetadata.elm from [fa02e88a13] to [291107f608].
1
2
3
4
5
6
7
8
9
10
..
11
12
13
14
15
16
17
|
module Play.Data.PackageMetadata exposing (PackageMetadata) import Dict exposing (Dict) import Play.Data.ModuleName as ModuleName exposing (ModuleName) import Play.Data.PackageName as PackageName exposing (PackageName) import Play.Data.PackagePath as PackagePath exposing (PackagePath) import Play.Data.SemanticVersion as SemanticVersion exposing (SemanticVersion) type alias PackageMetadata = ................................................................................ { name : PackageName , version : SemanticVersion , compatibleLanguageVersion : SemanticVersion , exposedModules : List ModuleName , dependencies : Dict String SemanticVersion , packagePaths : List PackagePath } |
|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
..
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
module Play.Data.PackageMetadata exposing ( PackageMetadata , decoder ) import Dict exposing (Dict) import Json.Decode as Json import Play.Data.ModuleName as ModuleName exposing (ModuleName) import Play.Data.PackageName as PackageName exposing (PackageName) import Play.Data.PackagePath as PackagePath exposing (PackagePath) import Play.Data.SemanticVersion as SemanticVersion exposing (SemanticVersion) type alias PackageMetadata = ................................................................................ { name : PackageName , version : SemanticVersion , compatibleLanguageVersion : SemanticVersion , exposedModules : List ModuleName , dependencies : Dict String SemanticVersion , packagePaths : List PackagePath } decoder : Json.Decoder PackageMetadata decoder = Json.map6 PackageMetadata (Json.field "name" Json.string |> Json.andThen (resultDecodeAdapt << PackageName.fromString)) (Json.field "version" Json.string |> Json.andThen (resultDecodeAdapt << SemanticVersion.fromString)) (Json.field "language-version" Json.string |> Json.andThen (resultDecodeAdapt << SemanticVersion.fromString)) (Json.field "exposed-modules" (Json.list (Json.string |> Json.andThen (resultDecodeAdapt << ModuleName.fromString)))) (Json.field "dependencies" (Json.dict (Json.string |> Json.andThen (resultDecodeAdapt << SemanticVersion.fromString)))) (Json.field "package-paths" (Json.list (Json.string |> Json.map PackagePath.fromString))) resultDecodeAdapt : Result err ok -> Json.Decoder ok resultDecodeAdapt result = case result of Ok value -> Json.succeed value Err err -> Json.fail "Something went wrong" |
Modified src/Play/PackageLoader.elm from [0c8dfd49f9] to [9106e2c582].
1
2
3
4
5
6
7
8
9
10
..
11
12
13
14
15
16
17
18
19
20
|
module Play.PackageLoader exposing (init) import Json.Decode as Json type Problem = InvalidPackageMetadata String String type alias State = ................................................................................ () type SideEffect = NoOp init : String -> Json.Value -> Result Problem ( State, SideEffect ) init jsonFilePath json = Err <| InvalidPackageMetadata jsonFilePath "todo" |
>
|
>
>
>
>
>
|
|
1
2
3
4
5
6
7
8
9
10
11
..
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
module Play.PackageLoader exposing (init) import Json.Decode as Json import Play.Data.PackageMetadata as PackageMetadata type Problem = InvalidPackageMetadata String String type alias State = ................................................................................ () type SideEffect = NoOp init : String -> String -> Result Problem ( State, SideEffect ) init jsonFilePath json = case Json.decodeString PackageMetadata.decoder json of Ok metadata -> Ok ( (), NoOp ) Err err -> Err <| InvalidPackageMetadata jsonFilePath (Json.errorToString err) |
Modified tests/Test/Data/PackagePath.elm from [ac067ac9fd] to [156de36d36].
1 2 3 4 5 6 7 8 9 10 11 12 13 |
module Test.Data.PackagePath exposing (suite)
import Expect
import Play.Data.PackagePath as PackagePath
import Test exposing (Test, describe, test)
import Test.PlayExpect as PlayExpect
suite : Test
suite =
describe "PackagePath"
[ test "Any path not ending in * is a directory" <|
\_ ->
|
< |
1 2 3 4 5 6 7 8 9 10 11 12 |
module Test.Data.PackagePath exposing (suite) import Expect import Play.Data.PackagePath as PackagePath import Test exposing (Test, describe, test) suite : Test suite = describe "PackagePath" [ test "Any path not ending in * is a directory" <| \_ -> |
Added tests/Test/PackageLoader.elm version [393af2926c].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
module Test.PackageLoader exposing (suite) import Expect import Fuzz import Play.PackageLoader as PackageLoader import Test exposing (Test, describe, fuzz, test) import Test.PlayExpect as PlayExpect suite : Test suite = describe "PackageLoader" [ test "Passes the load package metadata step" <| \_ -> PackageLoader.init "play.json" """ { "name": "robheghan/fnv", "version": "1.0.0", "language-version": "0.2.0", "exposed-modules": [ "fnv" ], "dependencies": { "template_string": "1.2.0" }, "package-paths": [ "lib/*" ] } """ |> Expect.ok ] |