izumisy / elm-firestore Goto Github PK
View Code? Open in Web Editor NEW*Experimental* A type-safe Firestore integration for Elm
Home Page: https://package.elm-lang.org/packages/IzumiSy/elm-firestore/latest/
License: MIT License
*Experimental* A type-safe Firestore integration for Elm
Home Page: https://package.elm-lang.org/packages/IzumiSy/elm-firestore/latest/
License: MIT License
I'm missing a few utility functions, that would be nice to have:
Decode.map : (a -> b) -> Field a -> Field b
- Useful if the database-field and the record-field have different typesDecode.map2 : (a -> b -> c) -> Field a -> Field b -> Field c
- Useful if your database has more fields than your record (for example encoding/decoding tuples)Decode.andThen : (a -> Field b) -> Field a -> Field b
- Useful if you want to only allow specific valuesDecode.succeed : a -> Field a
- Used in combination with andThen
Decode.fail : String -> Field a
- Used in combination with andThen
May I implement them?
Document and collection IDs should be made URL-safe
The example code is very helpful, but it looks like it's out of date with the code.
Personally I like to use a Codec instead of Decoder/Encoders. I'd suggest adding a Codec module next to the Encoder, Decoder module to provide both ways of handling json.
I'd like to work on this, if this is okey.
If you write a list of 0 length using the list
codec and then try to read it back, it fails with the error:
Problem with the value at json.arrayValue:
{}
Expecting an OBJECT with a field namedvalues
Hi again!
Thank you so much for this library π
I was able to migrate all my firestore code from JS to Elm successfully and with the documented features! π
One issue I'm having though, is that querying documents has a LIMIT of 20 documents by default (see this for reference: https://stackoverflow.com/questions/54559680/how-to-get-more-then-20-documents-in-a-get-query-using-firestore-rest-api).
I think the only solution is to pass the pageSize
query param to the GET call, I'm using list
to get all the documents, but I had not seen any option to pass this in the library.
If you point me in the right direction as where to start coding maybe I can provide a PR fixing it, would love to contribute back! π
On package.elm-lang.org, 12.0.0 exists, but it is not listed in the list of versions, and it says that 11.0.1 is the most recent version.
Using 12.0.0 does appear to work, but this state is confusing.
The current code will only support 52-bit integers because that is the size of the elm Int
type. However, the data format for firestore supports 64-bit integers, and we should preserve the serialized values.
This can be done using folkertdev/elm-int64 or malaire/elm-uint64.
Interface of this function must be like Json.Encode.Extra.maybe
.
https://package.elm-lang.org/packages/elm-community/json-extra/latest/Json-Encode-Extra#maybe
Hi!
First of all, thanks for this library!
In your example, you do this { firestore = firestore }
on your init function, but document is not set, which gives me an error from the compiler of course. π
Also, how do you handle collections within collections?
In my js app I have:
db.collection(`users/${user.uid}/readings`)
So I'm unsure how to translate that to Elm.
Thanks in advance!
Hi!
All my documents have a date : Posix
timestamp, and I would like to query firebase by a specific year, is this possible right now with firebase/elm-firestore?
My crappy solution for now of course is to download everything and do the filtering on the client side, but I'd like to avoid paginating unnecessarily in the client π
γγγγ¨γγγγΎγοΌ
In Firestore.Decode
and Firestore.Codec
, you are able to specify a decoder for a document which can decode each of its fields with the relevant decoder. However, there is no way to do this for nested objects (e.g. objects in arrays).
This would require creating a Field
similar to the way that we can create a Document
.
According to the Firestore documentation you can not have an array as an element in an array. In the spirit of making impossible states impossible, this should be prohibited by the API. This can be done by adding phantom types to the Field
types.
Sorry to open a new issue π εΎ‘ε γͺγγοΌ
Checking this: https://stackoverflow.com/questions/48884777/pagination-in-firestore-api/48889822#48889822
Even after having pageSize
the API returns 300 documents maximum, and you need to paginate with nextPageToken
to get the rest.
I think this is not currently possible with the library, please correct me if I'm wrong.
It's a pitty because I only need about 1000 documents or so, but I stumbled with this blocking issue for my project π
I just noticed that POST will generate the key of the entry for me. If I already have generated the key, then PUT is the correct command.
So
POST - Creates new document
PUT - Override existing document
PATCH - Update specific fields
Edit:
I also just noticed that PUT does not allow Cross-Origin Resource Sharing. (So it essentially only works for projects hosted on Firebase) Using PATCH instead would fix this. Not sure though if this package should use PATCH as a workaround or stick to PUT and let the user write the workaround themselves.
π€Maybe we need two functions: put
(using PUT) and override
(using PATCH)
Google's documentation indicates that there are 3 versions of the API available, v1
, v1beta1
, and v1beta2
. Currently, this library always uses v1beta1
. I think it would be good either to use v1
or to let clients choose which one they want to use.
All of the other methods identify documents by Path
. updateTx
should follow the same pattern.
The double value type appears to be unsupported. It seems like it maps straightforwardly to the elm Float
type.
Apparently, the PATCH command does not work properly in the Firebase API.
There is a workaround though:
https://stackoverflow.com/questions/49447897/firestore-update-a-document-field-using-rest-api
Example:
https://www.jeansnyman.com/posts/google-firestore-rest-api-examples/
Your current implementation of patch
does not allow to use this workaround.
For example:
-- This elm type of this path treats it as if it refers to a document, but it actually refers to a firestore (sub)collection since it contains an extra "/"
path : Path DocumentType
path =
firebase
|> Firebase.root
|> Firebase.collection "users"
|> Firebase.document "malformed/username"
This is most problematic when path components contain user-generated data, which is certainly possible in some use cases.
A complete solution would create an opaque type (e.g. PathComponent
) which would perform validation before it could be appended to a path. This would have the downside of making the API clunkier, though.
At the very least, the documentation should list the forbidden characters. Full limitations on document IDs and collection IDs are here.
Just noticed that your implementation of Encode.maybe
assume that the result will be null
. Resulting in an invalid query if you feed it anything but Nothing
.
I'm already working on the solution.
Edit: Same with Decode.maybe
When using the withAuthorization
function, the library sends a request with the "Bearer" header set to the provided value. However, the documentation says that the value should be sent via an "Authorization" header with the value "Bearer {YOUR_TOKEN}".
Here is an example that demonstrates the incorrect header value.
module Main exposing (main)
import Browser
import Firestore
import Firestore.Config
import Html
import Task
update : () -> () -> ( (), Cmd () )
update msg model =
( (), Cmd.none )
view : () -> Browser.Document ()
view model =
{ title = ""
, body = []
}
main : Program () () ()
main =
Browser.document
{ init =
always
( ()
, Firestore.Config.new { apiKey = "example_api_key", project = "example_project" }
|> Firestore.Config.withAuthorization "example_authorization"
|> Firestore.init
|> Firestore.root
|> Firestore.collection "example_collection"
|> Firestore.document "example_collection"
|> Firestore.build
|> (\pathResult ->
case pathResult of
Result.Err err ->
Cmd.none
Result.Ok path ->
path
|> Firestore.delete
|> Task.attempt (always ())
)
)
, view = view
, update = update
, subscriptions = always Sub.none
}
Hi!
I just thought that it would be nice to have a "revert" action in my App and was considering to add a delete
call to Firestore, but then I noticed there is a rollback endpoint!
Maybe I can contribute this feature if you agree that this is something you might want to add to this lib? π
Thanks in advance!
Currently, this package does not support null value coming from Firestore.
https://cloud.google.com/firestore/docs/reference/rest/v1/Value
Two functions such as Firestore.Encode.null
and Firestore.Decode.null
will be required to support it.
API keys are not required when using OAuth, and I believe providing one should not be required to create a Firestore.Config
value.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.