Skip to content

Commit

Permalink
Initial UUIDv5 Support (#1162) (#1163)
Browse files Browse the repository at this point in the history
* adding uuid files, not working need to rebase

* removed uuid literal, added parse, tests, need to encode result

* removing extra comments, added documentation for parse

* catching up to push

* ignoring workflows for now

* removing workflows for now

* adding back git workflows

* whitespace

Co-authored-by: Tyler Davis <tylrdvs96@gmail.com>
  • Loading branch information
DamianReeves and tylerd96 committed May 16, 2024
1 parent 79c16e5 commit 4f31014
Show file tree
Hide file tree
Showing 18 changed files with 418 additions and 85 deletions.
82 changes: 0 additions & 82 deletions .github/workflows/nodejs.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ docs.json
/.coverage/
tests-integration/reference-model/Dockerfile

.scala-build/
.scala-build/
2 changes: 2 additions & 0 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"Morphir.SDK.Dict",
"Morphir.SDK.ResultList",
"Morphir.SDK.LocalTime",
"Morphir.SDK.UUID",
"Morphir.IR.Name",
"Morphir.IR.NodeId",
"Morphir.IR.Decoration",
Expand Down Expand Up @@ -55,6 +56,7 @@
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"TSFoster/elm-uuid": "4.2.0 <= v < 5.0.0",
"chain-partners/elm-bignum": "1.0.1 <= v < 2.0.0",
"cmditch/elm-bigint": "1.0.1 <= v < 2.0.0",
"cuducos/elm-format-number": "8.1.4 <= v < 9.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/Morphir/IR/Literal.elm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Morphir.IR.Literal exposing (Literal(..), boolLiteral, charLiteral, strin
-}
import Morphir.SDK.Decimal exposing (Decimal)
import Morphir.SDK.UUID exposing (UUID)



Expand Down
1 change: 1 addition & 0 deletions src/Morphir/IR/Literal/Codec.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Json.Decode as Decode
import Json.Encode as Encode
import Morphir.IR.Literal exposing (Literal(..))
import Morphir.SDK.Decimal as Decimal
import Morphir.SDK.UUID as UUID


encodeLiteral : Literal -> Encode.Value
Expand Down
1 change: 1 addition & 0 deletions src/Morphir/IR/Literal/CodecV1.elm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Json.Decode as Decode
import Json.Encode as Encode
import Morphir.IR.Literal exposing (Literal(..))
import Morphir.SDK.Decimal as Decimal
import Morphir.SDK.UUID as UUID


encodeLiteral : Literal -> Encode.Value
Expand Down
2 changes: 2 additions & 0 deletions src/Morphir/IR/SDK.elm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import Morphir.IR.SDK.StatefulApp as StatefulApp
import Morphir.IR.SDK.String as String
import Morphir.IR.SDK.Tuple as Tuple
import Morphir.Value.Native as Native
import Morphir.IR.SDK.UUID as UUID


packageName : PackageName
Expand Down Expand Up @@ -75,6 +76,7 @@ packageSpec =
, ( [ [ "number" ] ], Number.moduleSpec )
, ( [ [ "key" ] ], Key.moduleSpec )
, ( [ [ "aggregate" ] ], Aggregate.moduleSpec )
, ( [ [ "uuid" ] ], UUID.moduleSpec)
]
}

Expand Down
111 changes: 111 additions & 0 deletions src/Morphir/IR/SDK/UUID.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
module Morphir.IR.SDK.UUID exposing (..)

import Dict
import Morphir.IR.Documented exposing (Documented)
import Morphir.IR.Module as Module exposing (ModuleName)
import Morphir.IR.Path as Path
import Morphir.IR.Name as Name
import Morphir.IR.Type exposing (Specification(..), Type(..))
import Morphir.IR.Literal exposing (Literal(..))
import Morphir.IR.Documented exposing (Documented)
import Morphir.IR.Value as Value exposing (Value)
import Morphir.IR.SDK.Common exposing (vSpec)
import Morphir.IR.SDK.String exposing (stringType)
import Morphir.IR.SDK.Common exposing (toFQName)
import Morphir.IR.SDK.Result exposing (resultType)
import Morphir.IR.SDK.Basics exposing (intType, orderType, boolType)
import Morphir.Value.Native as Native
import Morphir.Value.Native exposing (eval1, eval2)
import Morphir.SDK.UUID as UUID
import Morphir.Value.Native exposing (decodeLiteral, encodeLiteral, stringLiteral, intLiteral, encodeMaybe)
import Morphir.Value.Native exposing (eval0)
import Morphir.Value.Native exposing (encodeUUID, encodeUUID2)
import Morphir.IR.SDK.Maybe exposing (maybeType)
import Morphir.Value.Native exposing (decodeUUID)
import Morphir.Value.Native.Comparable exposing (compareValue)

moduleName : ModuleName
moduleName =
Path.fromString "UUID"

moduleSpec : Module.Specification ()
moduleSpec =
{ types =
Dict.fromList
[ (Name.fromString "UUID", OpaqueTypeSpecification [] |> Documented "Type that represents a UUID v5")
]
, values =
Dict.fromList
[ vSpec "parse" [ ("s", stringType () ) ] (resultType () (errorType ()) (uuidType ()))
, vSpec "fromString" [ ("s", stringType() ) ] (maybeType () (uuidType ()))
, vSpec "forName" [ ("s", stringType () ), ("uuid", uuidType () ) ] (uuidType ())
, vSpec "toString" [ ("uuid", uuidType () ) ] (stringType ())
, vSpec "version" [ ("uuid", uuidType () ) ] (intType ())
, vSpec "compare" [ ("uuid1", uuidType () ), ("uuid2", uuidType () ) ] (orderType ())
, vSpec "nilString" [] (stringType ())
, vSpec "isNilString" [ ("s", stringType () ) ] (boolType())
, vSpec "dnsNamespace" [] (uuidType ())
, vSpec "urlNamespace" [] (uuidType ())
, vSpec "oidNamespace" [] (uuidType ())
, vSpec "x500Namespace" [] (uuidType ())
]
, doc = Just "The UUID type and associated functions"
}

uuidType : a -> Type a
uuidType attributes =
Reference attributes (toFQName moduleName "UUID") []

errorType: a -> Type a
errorType attributes =
Reference attributes (toFQName moduleName "Error") []

nativeFunctions : List ( String, Native.Function )
nativeFunctions =
[ ( "forName"
, eval2 UUID.forName (decodeLiteral stringLiteral) decodeUUID (encodeUUID))
, ( "parse"
, eval1 UUID.parse (decodeLiteral stringLiteral) (encodeUUID2))
, ( "fromString"
, eval1 UUID.fromString (decodeLiteral stringLiteral) (encodeMaybe encodeUUID))
, ( "toString"
, eval1 UUID.toString decodeUUID (encodeLiteral StringLiteral))
, ( "version"
, eval1 UUID.version decodeUUID (encodeLiteral WholeNumberLiteral))
, ( "nilString"
, eval0 UUID.nilString (encodeLiteral StringLiteral))
, ( "isNilString"
, eval1 UUID.isNilString (decodeLiteral stringLiteral) (encodeLiteral BoolLiteral))
, ( "compare"
, Native.binaryStrict
(\arg1 arg2 ->
compareValue arg1 arg2
|> Result.map encodeOrder
)
)
, ( "dnsNamespace"
, eval0 UUID.dnsNamespace (encodeUUID))
, ( "urlNamespace"
, eval0 UUID.urlNamespace (encodeUUID))
, ( "oidNamespace"
, eval0 UUID.oidNamespace (encodeUUID))
, ( "x500Namespace"
, eval0 UUID.x500Namespace (encodeUUID))
]

encodeOrder : Order -> Value () ()
encodeOrder =
\order ->
let
val =
case order of
GT ->
"GT"

LT ->
"LT"

EQ ->
"EQ"
in
Value.Constructor () (toFQName moduleName val)
2 changes: 2 additions & 0 deletions src/Morphir/IR/Value.elm
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ import Morphir.IR.Name as Name exposing (Name)
import Morphir.IR.Path as Path
import Morphir.IR.Type as Type exposing (Type)
import Morphir.SDK.Decimal as Decimal
import Morphir.SDK.UUID exposing (UUID)
import Morphir.SDK.ResultList as ListOfResults
import Set exposing (Set)

Expand Down Expand Up @@ -2039,6 +2040,7 @@ toString value =
DecimalLiteral decimal ->
Decimal.toString decimal


patternToString : Pattern va -> String
patternToString pattern =
case pattern of
Expand Down
Loading

0 comments on commit 4f31014

Please sign in to comment.