Code Monkey home page Code Monkey logo

elm-firestore's People

Contributors

dependabot[bot] avatar izumisy avatar orasund avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kutyel orasund

elm-firestore's Issues

Utility functions for Decode

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 types
  • Decode.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 values
  • Decode.succeed : a -> Field a - Used in combination with andThen
  • Decode.fail : String -> Field a - Used in combination with andThen

May I implement them?

Adding A Codec

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.

list codec decode fails on empty list

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 named values

Allow to pass GET parameters to requests!

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! πŸ˜„

Document default value on init

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!

List querying by timestamp

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 πŸ˜‰

γ‚γ‚ŠγŒγ¨γ”γ–γ„γΎγ™οΌ

Add support for decoding nested objects

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.

Disallow nested arrays in codecs

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.

Allow to paginate 300+ documents

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 πŸ˜“

Add a PUT command

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)

Use non-beta firestore API

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.

Support double values

The double value type appears to be unsupported. It seems like it maps straightforwardly to the elm Float type.

It is possible to create invalid paths if path segments contain `/`

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.

Encode.maybe only works for Nothing

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

Authorization headers incorrect

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
        }

Add ROLLBACK command

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!

Make api keys optional

API keys are not required when using OAuth, and I believe providing one should not be required to create a Firestore.Config value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.