Add Elm Timeline to elm.json

pull/17/head
Bram 2024-03-25 08:52:55 +01:00
parent 1940b1d51f
commit 421e1f6ce7
5 changed files with 125 additions and 7 deletions

View File

@ -23,6 +23,7 @@
"Internal.Values.Event", "Internal.Values.Event",
"Internal.Values.Settings", "Internal.Values.Settings",
"Internal.Values.StateManager", "Internal.Values.StateManager",
"Internal.Values.Timeline",
"Internal.Values.Vault", "Internal.Values.Vault",
"Matrix", "Matrix",
"Matrix.Event", "Matrix.Event",

View File

@ -1,5 +1,5 @@
module Internal.Config.Text exposing module Internal.Config.Text exposing
( docs, failures, fields ( docs, failures, fields, mappings
, accessTokenFoundLocally, accessTokenExpired, accessTokenInvalid , accessTokenFoundLocally, accessTokenExpired, accessTokenInvalid
, versionsFoundLocally, versionsReceived, versionsFailedToDecode , versionsFoundLocally, versionsReceived, versionsFailedToDecode
, unsupportedVersionForEndpoint , unsupportedVersionForEndpoint
@ -27,7 +27,7 @@ You should only do this if you know what you're doing.
## Type documentation ## Type documentation
@docs docs, failures, fields @docs docs, failures, fields, mappings
## API Authentication ## API Authentication
@ -347,6 +347,19 @@ leakingValueFound leaking_value =
"Found leaking value : " ++ leaking_value "Found leaking value : " ++ leaking_value
{-| Function descriptions
-}
mappings : { itokenPTR : TypeDocs }
mappings =
{ itokenPTR =
{ name = "ITokenPTR init"
, description =
[ "Converts an optional string to an Itoken pointer."
]
}
}
{-| The Matrix homeserver can specify how it wishes to communicate, and the Elm {-| The Matrix homeserver can specify how it wishes to communicate, and the Elm
SDK aims to communicate accordingly. This may fail in some scenarios, however, SDK aims to communicate accordingly. This may fail in some scenarios, however,
in which case it will throw this error. in which case it will throw this error.

View File

@ -3,7 +3,7 @@ module Internal.Tools.Json exposing
, Encoder, encode, Decoder, decode, Value , Encoder, encode, Decoder, decode, Value
, succeed, fail, andThen, lazy, map , succeed, fail, andThen, lazy, map
, Docs(..), RequiredField(..), toDocs , Docs(..), RequiredField(..), toDocs
, list, slowDict, fastDict, maybe , list, slowDict, fastDict, set, maybe
, Field, field , Field, field
, object2, object3, object4, object5, object6, object7, object8, object9, object10, object11 , object2, object3, object4, object5, object6, object7, object8, object9, object10, object11
) )
@ -49,7 +49,7 @@ module to build its encoders and decoders.
## Data types ## Data types
@docs list, slowDict, fastDict, maybe @docs list, slowDict, fastDict, set, maybe
## Objects ## Objects
@ -73,6 +73,7 @@ import Internal.Tools.DecodeExtra as D
import Internal.Tools.EncodeExtra as E import Internal.Tools.EncodeExtra as E
import Json.Decode as D import Json.Decode as D
import Json.Encode as E import Json.Encode as E
import Set exposing (Set)
{-| A field of type `a` as a subtype of an object `object`. {-| A field of type `a` as a subtype of an object `object`.
@ -155,6 +156,7 @@ type Docs
) )
| DocsOptional Docs | DocsOptional Docs
| DocsRiskyMap (Descriptive { content : Docs, failure : List String }) | DocsRiskyMap (Descriptive { content : Docs, failure : List String })
| DocsSet Docs
| DocsString | DocsString
| DocsValue | DocsValue
@ -1079,6 +1081,27 @@ object11 { name, description, init } fa fb fc fd fe ff fg fh fi fj fk =
} }
{-| Define a set.
-}
set : Coder comparable -> Coder (Set comparable)
set (Coder data) =
Coder
{ encoder = E.set data.encoder
, decoder =
data.decoder
|> D.list
|> D.map
(\items ->
( items
|> List.map Tuple.first
|> Set.fromList
, items
|> List.concatMap Tuple.second
)
)
, docs = DocsSet data.docs
}
{-| Define a slow dict from the `elm/core` library. {-| Define a slow dict from the `elm/core` library.
-} -}
slowDict : Coder value -> Coder (SlowDict.Dict String value) slowDict : Coder value -> Coder (SlowDict.Dict String value)

View File

@ -61,7 +61,7 @@ events!
## JSON coder ## JSON coder
@docs encode, decoder @docs coder, encode, decoder
-} -}
@ -70,6 +70,7 @@ import Internal.Filter.Timeline as Filter exposing (Filter)
import Internal.Tools.Hashdict as Hashdict exposing (Hashdict) import Internal.Tools.Hashdict as Hashdict exposing (Hashdict)
import Internal.Tools.Iddict as Iddict exposing (Iddict) import Internal.Tools.Iddict as Iddict exposing (Iddict)
import Internal.Tools.Json as Json import Internal.Tools.Json as Json
import Internal.Config.Text as Text
import Json.Decode as D import Json.Decode as D
import Json.Encode as E import Json.Encode as E
import Recursion import Recursion
@ -79,6 +80,9 @@ import Set exposing (Set)
{-| A batch is a batch of events that is placed onto the Timeline. Functions {-| A batch is a batch of events that is placed onto the Timeline. Functions
that require an insertion, generally require this data type. that require an insertion, generally require this data type.
If the `start` value is `Nothing`, it is either the start of the timeline or the
start of the timeline part that the user is allowed to view.
-} -}
type alias Batch = type alias Batch =
{ events : List String { events : List String
@ -164,6 +168,83 @@ type Timeline
type alias TokenValue = type alias TokenValue =
String String
coderIBatchPTR : Json.Coder IBatchPTR
coderIBatchPTR =
Json.map
{ name = Debug.todo "Add name"
, description = Debug.todo "Add description"
, back = IBatchPTR
, forth = (\(IBatchPTR value) -> value)
}
coderIBatchPTRValue
coderIBatchPTRValue : Json.Coder IBatchPTRValue
coderIBatchPTRValue = Json.int
coderIToken : Json.Coder IToken
coderIToken =
Json.object5
{ name = "IToken"
, description = Debug.todo "TODO: Add description"
, init = IToken
}
( Json.field.required
{ fieldName = "name"
, toField = .name
, description = Debug.todo "TODO: Add description"
, coder = coderTokenValue
}
)
( Json.field.optional.withDefault
{ fieldName = "starts"
, toField = .starts
, description = Debug.todo "TODO: Add description"
, coder = Json.set coderIBatchPTRValue
, default = ( Set.empty, [] )
, defaultToString = always "[]"
}
)
( Json.field.optional.withDefault
{ fieldName = "ends"
, toField = .ends
, description = Debug.todo "TODO: Add description"
, coder = Json.set coderIBatchPTRValue
, default = ( Set.empty, [] )
, defaultToString = always "[]"
}
)
coderITokenPTR : Json.Coder ITokenPTR
coderITokenPTR =
Json.maybe coderITokenPTRValue
|> Json.map
{ name = Text.mappings.itokenPTR.name
, description = Text.mappings.itokenPTR.description
, back =
(\itokenptr ->
case itokenptr of
ITokenPTR name ->
Just name
StartOfTimeline ->
Nothing
)
, forth =
(\value ->
case value of
Just name ->
ITokenPTR name
Nothing ->
StartOfTimeline
)
}
coderITokenPTRValue : Json.Coder ITokenPTRValue
coderITokenPTRValue = Json.string
coderTokenValue : Json.Coder TokenValue
coderTokenValue = Json.string
{-| Append a token at the end of a batch. {-| Append a token at the end of a batch.
-} -}

View File

@ -170,7 +170,7 @@ suite =
] ]
, describe "Gaps" , describe "Gaps"
[ fuzz TestFilter.fuzzer [ fuzz TestFilter.fuzzer
"Gap leaves behind old events" "Gaps leave behind old events"
(\filter -> (\filter ->
Timeline.empty Timeline.empty
|> Timeline.insert |> Timeline.insert
@ -189,7 +189,7 @@ suite =
|> Expect.equal [ [ "d", "e", "f" ] ] |> Expect.equal [ [ "d", "e", "f" ] ]
) )
, fuzz TestFilter.fuzzer , fuzz TestFilter.fuzzer
"Gap can be bridged" "Gaps can be bridged"
(\filter -> (\filter ->
Timeline.empty Timeline.empty
|> Timeline.insert |> Timeline.insert