From f2b058d4741fd3c8904d09193f811f9cc2ca8a09 Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Tue, 7 May 2024 05:12:58 -0500 Subject: [PATCH] update with latest tinyping schema --- tests/cmd/tinyping.in/elm-duet.yaml | 63 +++++---- tests/cmd/tinyping.out/src/Main/Flags.elm | 6 +- tests/cmd/tinyping.out/src/Main/Ports.elm | 156 +++++++++++----------- 3 files changed, 115 insertions(+), 110 deletions(-) diff --git a/tests/cmd/tinyping.in/elm-duet.yaml b/tests/cmd/tinyping.in/elm-duet.yaml index 9afe296..4ab3d65 100644 --- a/tests/cmd/tinyping.in/elm-duet.yaml +++ b/tests/cmd/tinyping.in/elm-duet.yaml @@ -1,13 +1,37 @@ definitions: notificationPermission: + metadata: + name: NotificationPermission enum: - default - denied - granted + notification: + metadata: + name: Notification + properties: + title: + type: string + options: + optionalProperties: + badge: + type: string + body: + type: string + icon: + type: string + lang: + type: string + requireInteraction: + type: boolean + silent: + type: boolean + tag: + type: string + # name/prefix policy: all versioned objects have a `versioned` constructor - # prefix to avoid conflicts. Current versions of types don't have a version - # suffix, but previous versions do. + # prefix to avoid conflicts. doc: metadata: @@ -16,7 +40,7 @@ definitions: mapping: v1: metadata: - name: Doc + name: DocV1 properties: pings: elements: @@ -26,13 +50,12 @@ definitions: settings: metadata: - name: DocumentSettings constructorPrefix: versioned discriminator: version mapping: v1: metadata: - name: Settings + name: SettingsV1 properties: minutesPerPing: type: int32 @@ -44,7 +67,7 @@ definitions: mapping: v1: metadata: - name: Ping + name: PingV1 properties: time: type: int32 @@ -60,7 +83,7 @@ modules: flags: properties: currentTimeMillis: - type: float64 + type: int32 notificationPermission: ref: notificationPermission ports: @@ -77,15 +100,15 @@ modules: SetMinutesPerPing: properties: value: - type: float64 + type: uint32 AddNewPingAt: properties: value: - type: float64 + type: uint32 SetTagForPing: properties: index: - type: float64 + type: uint32 value: type: string nullable: true @@ -101,22 +124,4 @@ modules: notify: metadata: direction: ElmToJs - properties: - title: - type: string - options: - optionalProperties: - badge: - type: string - body: - type: string - icon: - type: string - lang: - type: string - requireInteraction: - type: boolean - silent: - type: boolean - tag: - type: string + ref: notification diff --git a/tests/cmd/tinyping.out/src/Main/Flags.elm b/tests/cmd/tinyping.out/src/Main/Flags.elm index 6c84a81..d46c7e1 100644 --- a/tests/cmd/tinyping.out/src/Main/Flags.elm +++ b/tests/cmd/tinyping.out/src/Main/Flags.elm @@ -49,7 +49,7 @@ encodeNotificationPermission notificationPermission_ = type alias Flags = - { currentTimeMillis : Float + { currentTimeMillis : Int , notificationPermission : NotificationPermission } @@ -57,13 +57,13 @@ type alias Flags = flagsDecoder : Json.Decode.Decoder Flags flagsDecoder = Json.Decode.succeed Flags - |> Json.Decode.Pipeline.required "currentTimeMillis" Json.Decode.float + |> Json.Decode.Pipeline.required "currentTimeMillis" Json.Decode.int |> Json.Decode.Pipeline.required "notificationPermission" notificationPermissionDecoder encodeFlags : Flags -> Json.Encode.Value encodeFlags flags_ = Json.Encode.object - [ ( "currentTimeMillis", Json.Encode.float flags_.currentTimeMillis ) + [ ( "currentTimeMillis", Json.Encode.int flags_.currentTimeMillis ) , ( "notificationPermission", encodeNotificationPermission flags_.notificationPermission ) ] diff --git a/tests/cmd/tinyping.out/src/Main/Ports.elm b/tests/cmd/tinyping.out/src/Main/Ports.elm index 07f70e5..c137e00 100644 --- a/tests/cmd/tinyping.out/src/Main/Ports.elm +++ b/tests/cmd/tinyping.out/src/Main/Ports.elm @@ -10,45 +10,45 @@ import Json.Encode type alias AddNewPingAt = - { value : Float + { value : Int } addNewPingAtDecoder : Json.Decode.Decoder AddNewPingAt addNewPingAtDecoder = Json.Decode.succeed AddNewPingAt - |> Json.Decode.Pipeline.required "value" Json.Decode.float + |> Json.Decode.Pipeline.required "value" Json.Decode.int encodeAddNewPingAt : AddNewPingAt -> Json.Encode.Value encodeAddNewPingAt addNewPingAt_ = Json.Encode.object - [ ( "value", Json.Encode.float addNewPingAt_.value ) + [ ( "value", Json.Encode.int addNewPingAt_.value ) , ( "tag", Json.Encode.string "AddNewPingAt" ) ] type alias SetMinutesPerPing = - { value : Float + { value : Int } setMinutesPerPingDecoder : Json.Decode.Decoder SetMinutesPerPing setMinutesPerPingDecoder = Json.Decode.succeed SetMinutesPerPing - |> Json.Decode.Pipeline.required "value" Json.Decode.float + |> Json.Decode.Pipeline.required "value" Json.Decode.int encodeSetMinutesPerPing : SetMinutesPerPing -> Json.Encode.Value encodeSetMinutesPerPing setMinutesPerPing_ = Json.Encode.object - [ ( "value", Json.Encode.float setMinutesPerPing_.value ) + [ ( "value", Json.Encode.int setMinutesPerPing_.value ) , ( "tag", Json.Encode.string "SetMinutesPerPing" ) ] type alias SetTagForPing = - { index : Float + { index : Int , value : Maybe String } @@ -56,14 +56,14 @@ type alias SetTagForPing = setTagForPingDecoder : Json.Decode.Decoder SetTagForPing setTagForPingDecoder = Json.Decode.succeed SetTagForPing - |> Json.Decode.Pipeline.required "index" Json.Decode.float + |> Json.Decode.Pipeline.required "index" Json.Decode.int |> Json.Decode.Pipeline.required "value" (Json.Decode.nullable Json.Decode.string) encodeSetTagForPing : SetTagForPing -> Json.Encode.Value encodeSetTagForPing setTagForPing_ = Json.Encode.object - [ ( "index", Json.Encode.float setTagForPing_.index ) + [ ( "index", Json.Encode.int setTagForPing_.index ) , ( "value" , case setTagForPing_.value of Just value -> @@ -129,40 +129,40 @@ encodeChangeDocument changeDocument_ = Json.Encode.list (/value -> encodeChangeDocumentElements value) changeDocument_ -type alias Ping = +type alias PingV1 = { custom : Dict String String , tag : Maybe String , time : Int } -pingDecoder : Json.Decode.Decoder Ping -pingDecoder = - Json.Decode.succeed Ping +pingV1Decoder : Json.Decode.Decoder PingV1 +pingV1Decoder = + Json.Decode.succeed PingV1 |> Json.Decode.Pipeline.required "custom" (Json.Decode.dict Json.Decode.string) |> Json.Decode.Pipeline.required "tag" (Json.Decode.nullable Json.Decode.string) |> Json.Decode.Pipeline.required "time" Json.Decode.int -encodePing : Ping -> Json.Encode.Value -encodePing ping_ = +encodePingV1 : PingV1 -> Json.Encode.Value +encodePingV1 pingV1_ = Json.Encode.object - [ ( "custom", Json.Encode.dict identity (/value -> Json.Encode.string value) ping_.custom ) + [ ( "custom", Json.Encode.dict identity (/value -> Json.Encode.string value) pingV1_.custom ) , ( "tag" - , case ping_.tag of + , case pingV1_.tag of Just value -> Json.Encode.string value Nothing -> Json.Encode.null ) - , ( "time", Json.Encode.int ping_.time ) + , ( "time", Json.Encode.int pingV1_.time ) , ( "version", Json.Encode.string "v1" ) ] type PingsElements - = VersionedPingsElementsV1 Ping + = VersionedPingsElementsV1 PingV1 pingsElementsDecoder : Json.Decode.Decoder PingsElements @@ -171,7 +171,7 @@ pingsElementsDecoder = (/tag -> case tag of "v1" -> - Json.Decode.map VersionedPingsElementsV1 pingDecoder + Json.Decode.map VersionedPingsElementsV1 pingV1Decoder unknown -> Json.Decode.fail ("Unknown value `" ++ unknown ++ "`") @@ -183,39 +183,39 @@ encodePingsElements : PingsElements -> Json.Encode.Value encodePingsElements pingsElements_ = case pingsElements_ of VersionedPingsElementsV1 versionedPingsElementsV1 -> - encodePing versionedPingsElementsV1 + encodePingV1 versionedPingsElementsV1 -type alias Settings = +type alias SettingsV1 = { minutesPerPing : Int } -settingsDecoder : Json.Decode.Decoder Settings -settingsDecoder = - Json.Decode.succeed Settings +settingsV1Decoder : Json.Decode.Decoder SettingsV1 +settingsV1Decoder = + Json.Decode.succeed SettingsV1 |> Json.Decode.Pipeline.required "minutesPerPing" Json.Decode.int -encodeSettings : Settings -> Json.Encode.Value -encodeSettings settings_ = +encodeSettingsV1 : SettingsV1 -> Json.Encode.Value +encodeSettingsV1 settingsV1_ = Json.Encode.object - [ ( "minutesPerPing", Json.Encode.int settings_.minutesPerPing ) + [ ( "minutesPerPing", Json.Encode.int settingsV1_.minutesPerPing ) , ( "version", Json.Encode.string "v1" ) ] -type DocumentSettings - = VersionedDocumentSettingsV1 Settings +type Settings + = VersionedSettingsV1 SettingsV1 -documentSettingsDecoder : Json.Decode.Decoder DocumentSettings -documentSettingsDecoder = +settingsDecoder : Json.Decode.Decoder Settings +settingsDecoder = Json.Decode.andThen (/tag -> case tag of "v1" -> - Json.Decode.map VersionedDocumentSettingsV1 settingsDecoder + Json.Decode.map VersionedSettingsV1 settingsV1Decoder unknown -> Json.Decode.fail ("Unknown value `" ++ unknown ++ "`") @@ -223,37 +223,37 @@ documentSettingsDecoder = (Json.Decode.field "version" Json.Decode.string) -encodeDocumentSettings : DocumentSettings -> Json.Encode.Value -encodeDocumentSettings documentSettings_ = - case documentSettings_ of - VersionedDocumentSettingsV1 versionedDocumentSettingsV1 -> - encodeSettings versionedDocumentSettingsV1 +encodeSettings : Settings -> Json.Encode.Value +encodeSettings settings_ = + case settings_ of + VersionedSettingsV1 versionedSettingsV1 -> + encodeSettingsV1 versionedSettingsV1 -type alias Doc = +type alias DocV1 = { pings : List PingsElements - , settings : DocumentSettings + , settings : Settings } -docDecoder : Json.Decode.Decoder Doc -docDecoder = - Json.Decode.succeed Doc +docV1Decoder : Json.Decode.Decoder DocV1 +docV1Decoder = + Json.Decode.succeed DocV1 |> Json.Decode.Pipeline.required "pings" (Json.Decode.list pingsElementsDecoder) - |> Json.Decode.Pipeline.required "settings" documentSettingsDecoder + |> Json.Decode.Pipeline.required "settings" settingsDecoder -encodeDoc : Doc -> Json.Encode.Value -encodeDoc doc_ = +encodeDocV1 : DocV1 -> Json.Encode.Value +encodeDocV1 docV1_ = Json.Encode.object - [ ( "pings", Json.Encode.list (/value -> encodePingsElements value) doc_.pings ) - , ( "settings", encodeDocumentSettings doc_.settings ) + [ ( "pings", Json.Encode.list (/value -> encodePingsElements value) docV1_.pings ) + , ( "settings", encodeSettings docV1_.settings ) , ( "version", Json.Encode.string "v1" ) ] type DocFromAutomerge - = VersionedDocFromAutomergeV1 Doc + = VersionedDocFromAutomergeV1 DocV1 docFromAutomergeDecoder : Json.Decode.Decoder DocFromAutomerge @@ -262,7 +262,7 @@ docFromAutomergeDecoder = (/tag -> case tag of "v1" -> - Json.Decode.map VersionedDocFromAutomergeV1 docDecoder + Json.Decode.map VersionedDocFromAutomergeV1 docV1Decoder unknown -> Json.Decode.fail ("Unknown value `" ++ unknown ++ "`") @@ -274,28 +274,28 @@ encodeDocFromAutomerge : DocFromAutomerge -> Json.Encode.Value encodeDocFromAutomerge docFromAutomerge_ = case docFromAutomerge_ of VersionedDocFromAutomergeV1 versionedDocFromAutomergeV1 -> - encodeDoc versionedDocFromAutomergeV1 + encodeDocV1 versionedDocFromAutomergeV1 -type GotNewNotificationsPermission - = GotNewNotificationsPermissionDefault - | GotNewNotificationsPermissionDenied - | GotNewNotificationsPermissionGranted +type NotificationPermission + = NotificationPermissionDefault + | NotificationPermissionDenied + | NotificationPermissionGranted -gotNewNotificationsPermissionDecoder : Json.Decode.Decoder GotNewNotificationsPermission -gotNewNotificationsPermissionDecoder = +notificationPermissionDecoder : Json.Decode.Decoder NotificationPermission +notificationPermissionDecoder = Json.Decode.andThen (/tag -> case tag of "default" -> - Json.Decode.succeed GotNewNotificationsPermissionDefault + Json.Decode.succeed NotificationPermissionDefault "denied" -> - Json.Decode.succeed GotNewNotificationsPermissionDenied + Json.Decode.succeed NotificationPermissionDenied "granted" -> - Json.Decode.succeed GotNewNotificationsPermissionGranted + Json.Decode.succeed NotificationPermissionGranted unknown -> Json.Decode.fail ("Unknown value `" ++ unknown ++ "`") @@ -303,16 +303,16 @@ gotNewNotificationsPermissionDecoder = Json.Decode.string -encodeGotNewNotificationsPermission : GotNewNotificationsPermission -> Json.Encode.Value -encodeGotNewNotificationsPermission gotNewNotificationsPermission_ = - case gotNewNotificationsPermission_ of - GotNewNotificationsPermissionDefault -> +encodeNotificationPermission : NotificationPermission -> Json.Encode.Value +encodeNotificationPermission notificationPermission_ = + case notificationPermission_ of + NotificationPermissionDefault -> Json.Encode.string "default" - GotNewNotificationsPermissionDenied -> + NotificationPermissionDenied -> Json.Encode.string "denied" - GotNewNotificationsPermissionGranted -> + NotificationPermissionGranted -> Json.Encode.string "granted" @@ -353,24 +353,24 @@ encodeOptions options_ = |> Json.Encode.object -type alias Notify = +type alias Notification = { options : Options , title : String } -notifyDecoder : Json.Decode.Decoder Notify -notifyDecoder = - Json.Decode.succeed Notify +notificationDecoder : Json.Decode.Decoder Notification +notificationDecoder = + Json.Decode.succeed Notification |> Json.Decode.Pipeline.required "options" optionsDecoder |> Json.Decode.Pipeline.required "title" Json.Decode.string -encodeNotify : Notify -> Json.Encode.Value -encodeNotify notify_ = +encodeNotification : Notification -> Json.Encode.Value +encodeNotification notification_ = Json.Encode.object - [ ( "options", encodeOptions notify_.options ) - , ( "title", Json.Encode.string notify_.title ) + [ ( "options", encodeOptions notification_.options ) + , ( "title", Json.Encode.string notification_.title ) ] @@ -407,17 +407,17 @@ subscribeToDocFromAutomerge toMsg = port gotNewNotificationsPermission : (Json.Decode.Value -> msg) -> Sub msg -subscribeToGotNewNotificationsPermission : (Result Json.Decode.Error GotNewNotificationsPermission -> msg) -> Sub msg +subscribeToGotNewNotificationsPermission : (Result Json.Decode.Error NotificationPermission -> msg) -> Sub msg subscribeToGotNewNotificationsPermission toMsg = - gotNewNotificationsPermission (Json.Decode.decodeValue gotNewNotificationsPermissionDecoder >> toMsg) + gotNewNotificationsPermission (Json.Decode.decodeValue notificationPermissionDecoder >> toMsg) port notify : Json.Decode.Value -> Cmd msg -sendNotify : Notify -> Cmd msg +sendNotify : Notification -> Cmd msg sendNotify = - encodeNotify >> notify + encodeNotification >> notify port requestNotificationsPermission : Json.Decode.Value -> Cmd msg