Add object1

pull/31/head
Bram 2024-06-03 15:02:35 +02:00
parent d360c561f9
commit 7b00a46ffa
4 changed files with 31 additions and 80 deletions

View File

@ -87,12 +87,12 @@ coder =
{ fieldName = "m.homeserver"
, toField = .homeserver
, coder =
Json.object2
Json.object1
{ name = "Homeserver Information"
, description =
[ "Used by clients to discover homeserver information."
]
, init = \a _ -> { baseUrl = a }
, init = HomeserverInformation
}
(Json.field.required
{ fieldName = "base_url"
@ -103,17 +103,6 @@ coder =
, coder = Json.string
}
)
(Json.field.optional.value
{ fieldName = L.field
, toField = always Nothing
, description =
[ "The Elm SDK always expects objects to have at least two fields."
, "Otherwise, what's the point of hiding the value in an object?"
, "For this reason, this empty placeholder key will always be ignored."
]
, coder = Json.value
}
)
, description =
[ "Used by clients to discover homeserver information."
]
@ -123,12 +112,12 @@ coder =
{ fieldName = "m.identity_server"
, toField = .identityServer
, coder =
Json.object2
Json.object1
{ name = "Homeserver Information"
, description =
[ "Used by clients to discover homeserver information."
]
, init = \a _ -> { baseUrl = a }
, init = IdentityServerInformation
}
(Json.field.required
{ fieldName = "base_url"
@ -139,17 +128,6 @@ coder =
, coder = Json.string
}
)
(Json.field.optional.value
{ fieldName = L.field
, toField = always Nothing
, description =
[ "The Elm SDK always expects objects to have at least two fields."
, "Otherwise, what's the point of hiding the value in an object?"
, "For this reason, this empty placeholder key will always be ignored."
]
, coder = Json.value
}
)
, description =
[ "Used by clients to discover identity server information."
]

View File

@ -888,12 +888,12 @@ disoveryInformationCoderV1 =
{ fieldName = "m.homeserver"
, toField = .homeserver
, coder =
Json.object2
Json.object1
{ name = "Homeserver Information"
, description =
[ "Used by clients to discover homeserver information."
]
, init = \a _ -> { baseUrl = a }
, init = HomeserverInformation
}
(Json.field.required
{ fieldName = "base_url"
@ -904,17 +904,6 @@ disoveryInformationCoderV1 =
, coder = Json.string
}
)
(Json.field.optional.value
{ fieldName = L.field
, toField = always Nothing
, description =
[ "The Elm SDK always expects objects to have at least two fields."
, "Otherwise, what's the point of hiding the value in an object?"
, "For this reason, this empty placeholder key will always be ignored."
]
, coder = Json.value
}
)
, description =
[ "Used by clients to discover homeserver information."
]
@ -924,12 +913,12 @@ disoveryInformationCoderV1 =
{ fieldName = "m.identity_server"
, toField = .identityServer
, coder =
Json.object2
Json.object1
{ name = "Homeserver Information"
, description =
[ "Used by clients to discover homeserver information."
]
, init = \a _ -> { baseUrl = a }
, init = HomeserverInformation
}
(Json.field.required
{ fieldName = "base_url"
@ -940,17 +929,6 @@ disoveryInformationCoderV1 =
, coder = Json.string
}
)
(Json.field.optional.value
{ fieldName = L.field
, toField = always Nothing
, description =
[ "The Elm SDK always expects objects to have at least two fields."
, "Otherwise, what's the point of hiding the value in an object?"
, "For this reason, this empty placeholder key will always be ignored."
]
, coder = Json.value
}
)
, description =
[ "Used by clients to discover identity server information."
]

View File

@ -143,26 +143,15 @@ sendMessageEventV3 { content, eventType, roomId, transactionId } =
coderV1 : Json.Coder SendMessageEventOutputV1
coderV1 =
Json.object2
Json.object1
{ name = "EventResponse"
, description =
[ "This endpoint is used to send a message event to a room. Message events allow access to historical events and pagination, making them suited for \"once-off\" activity in a room."
, "The body of the request should be the content object of the event; the fields in this object will vary depending on the type of event."
, "https://spec.matrix.org/legacy/r0.0.0/client_server.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid"
]
, init = always SendMessageEventOutputV1
, init = SendMessageEventOutputV1
}
(Json.field.optional.value
{ fieldName = L.field
, toField = always Nothing
, description =
[ "The Elm SDK always expects objects to have at least two fields."
, "Otherwise, what's the point of hiding the value in an object?"
, "For this reason, this empty placeholder key will always be ignored."
]
, coder = Json.value
}
)
(Json.field.optional.value
{ fieldName = "event_id"
, toField = .eventId
@ -174,26 +163,15 @@ coderV1 =
coderV2 : Json.Coder SendMessageEventOutputV2
coderV2 =
Json.object2
Json.object1
{ name = "EventResponse"
, description =
[ "This endpoint is used to send a message event to a room. Message events allow access to historical events and pagination, making them suited for \"once-off\" activity in a room."
, "The body of the request should be the content object of the event; the fields in this object will vary depending on the type of event."
, "https://spec.matrix.org/legacy/client_server/r0.6.1.html#put-matrix-client-r0-rooms-roomid-send-eventtype-txnid"
]
, init = always SendMessageEventOutputV2
, init = SendMessageEventOutputV2
}
(Json.field.optional.value
{ fieldName = L.field
, toField = always Nothing
, description =
[ "The Elm SDK always expects objects to have at least two fields."
, "Otherwise, what's the point of hiding the value in an object?"
, "For this reason, this empty placeholder key will always be ignored."
]
, coder = Json.value
}
)
(Json.field.required
{ fieldName = "event_id"
, toField = .eventId

View File

@ -5,7 +5,7 @@ module Internal.Tools.Json exposing
, Docs(..), RequiredField(..), toDocs
, list, listWithOne, slowDict, fastDict, fastIntDict, set, maybe
, Field, field, parser
, object2, object3, object4, object5, object6, object7, object8, object9, object10, object11
, object1, object2, object3, object4, object5, object6, object7, object8, object9, object10, object11
)
{-|
@ -62,7 +62,7 @@ first.
Once all fields are constructed, the user can create JSON objects.
@docs object2, object3, object4, object5, object6, object7, object8, object9, object10, object11
@docs object1, object2, object3, object4, object5, object6, object7, object8, object9, object10, object11
-}
@ -596,6 +596,23 @@ objectEncoder items object =
|> E.maybeObject
object1 :
Descriptive { init : a -> object }
-> Field a object
-> Coder object
object1 { name, description, init } fa =
Coder
{ encoder = objectEncoder [ toEncodeField fa ]
, decoder = D.map (Tuple.mapFirst init) (toDecoderField fa)
, docs =
DocsObject
{ name = name
, description = description
, keys = [ toDocsField fa ]
}
}
{-| Define an object with 2 keys
type alias Human =