Firestore mapper - expected (plain | mongo) in argument?
See original GitHub issueI’m trying to build a classToFirestore and firestoreToClass mapping, however the call for deleteExcludedPropertiesFor
only takes “mongo” or “plain” target, and this constraint extends to exclude
. So I’m not sure how best to wrangle this, other than to drop the deleteExcludedPropertiesFor
, which would mean all the excluded fields would be retained.
Or forking the whole project?
Advice would be really appreciated!
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
javascript Map to Firestore -> Error: Value for argument "data ...
It fails with error - Error: Value for argument "data" is not a valid Firestore document. Input is not a plain JavaScript object...
Read more >Value for argument "data" is not a valid Firestore document ...
Error: Value for argument "data" is not a valid Firestore document. Detected an object of type "DocumentReference" that doesn't match the expected instance....
Read more >How is MongoDB different from Firestore? - Quora
To query documents in Couchbase, you define a view with the columns of the document you are interested in (called the map); and...
Read more >metricbeat.reference.yml - Elastic
Defaults to PLAIN when `username` and `password` are configured. ... #timeout: 90 # metricbeat expects Elasticsearch to be the same version or newer...
Read more >Parquet schema - Hackolade
Apache Parquet is a binary file format that stores data in a columnar fashion for compressed, efficient columnar data representation in the Hadoop...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@leandro-manifesto sorry, forgot to answer you.
Yes, you can do it like that.
Only if the firestore driver itself returns different types and that need to be translated to JS types. I guess the driver returns boolean already as Boolean, number as Number etc, so nothing to do here.
It’s done, we got massive performance improvements and I decoupled a lot of stuff. I’m actually very happy about that 😃
The way you add new serialization targets is now easier as well. You have to write basically for every type that needs to be casted a little compiler template. Here is all what is needed for MongoDB support:
https://github.com/marcj/marshal.ts/blob/master/packages/mongo/src/compiler-templates.ts
See documentation about the used functions here: https://github.com/marcj/marshal.ts/blob/master/packages/core/src/compiler-registry.ts
You see code like
This code registers a new compiler template for serialization from class to firebase for the type
moment
. Since firebase does not have Moment.js support, you need this compiler as well for example. You need a couple of those, especially forarrayBuffer
and all typed arrays. Mongo stores those asBinary
, and firebase has probably a custom binary abstraction. See how mongo did it for examples.For
class
you can take the default compiler:Here’s a list of types you probably want to cover, depending on which types the firebase driver supports
moment
arrayBuffer
(maybe firebase driver supports ArrayBuffer already, dunno)class
(use ready to use compiler)uuid
(only if firebase supports binary uuids, otherwise just ignore it, it will stored as string)In best case you have only 4 compilers registered (2x
moment
and 2xclass
).Please only define
registerConverterCompiler('firebase', 'class', type, ...
andregisterConverterCompiler('class', 'firebase', type, ...
. plainToFirebase and firebaseToPlain should work through classToFirebase and firebaseToClass. For example how mongo did it:It’s faster to do it so than manually specifying every compiler template possible for plain -> firebase.
You can then provide little wrapper functions around the core to make autoloading of your compiler-templates possible and give users a clear API. Here’s how the mongo implementation is doing it:
https://github.com/marcj/marshal.ts/blob/master/packages/marshal-mongo/src/mapping.ts
Your wrapper function would look like these: