Common interface for admin & regular SDKs? #4651
Replies: 2 comments 4 replies
-
Have you tried typesaurus? It seems to solve your use case where you want to share code between server and client. The admin SDK is unlikely to adopt the same API as the new client SDK, because size is not a concern on server side and we don't want to sacrifice usability (e.g. method chaining) for no benefits. So I think it will be hard to share types between the 2 SDKs as their APIs diverge. At the moment, I think your best bet is use third party solutions built on top of firebase SDKs, like typesaurus. |
Beta Was this translation helpful? Give feedback.
-
I'd like to add that the similarities between JS and Admin Node.js SDKs are limited to just RTDB and Firestore. Even in those cases there are minor but important differences. Our other product API surfaces (e.g. Auth, FCM, ML etc) are vastly different, and have nearly zero overlap across JS and Admin SDKs. Generally speaking, these 2 SDKs are meant for very different use cases, and therefore sharing typings across them is often infeasible.
IMO it's the other way around. These 2 SDKs have mostly incompatible API surfaces, with Firestore and RTDB being the only exceptions where there's some degree of compatibility.
It's actually the specific product use cases that define the APIs. Our SDKs are aimed at developers that implement very different (but often complementary) use cases. Taking Auth as an example, on frontends we want to support use cases like sign-in and sign-out. On backends we want to support use cases like creating custom tokens and assigning users roles. It kind of makes sense why the JS and Admin API surfaces for RTDB and Firestore ended up being mostly similar. It's because they are database products. And as database products there's a set of use cases we'd want them to support regardless of the environment (queries, updates, transactions etc). But IMO this similarity is the exception rather than the norm. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR: substitutability of the 2 Firebase JS SDKs would be valuable for JS/TS monorepos
I noticed the Firebase team is doing a major refactor to make the Firebase SDK treeshakable. This might be the best opportunity to align the 2 JS SDKs, so I thought I'd throw the idea out... Can the types be moved up to a shared package, which both SDKs implement?
Motivation
Most of my projects have 3 frontend modules & 1 shared module:
I have a Dao package in
common
. My dao objects depend onfirestore
. However, my various frontends use different versions of the Firebase SDK:The 2 SDKs (at least for firestore) are very nearly aligned, but not quite. In fact I can attest to how similar they are; blindly type asserting that the admin SDK is the client SDK appears to be "working" within my project (I realise this is not sensible -- hence this suggestion to do it properly).
Concept (arrow = depends on)
Incremental
If desired, I think this could be built product-by-product, eg. starting by only extracting Firestore types. I picked Firestore because I already have a use case in my projects. Though I'm also starting to see the same for Storage & probably the issue is general.
Exclusions
I am not suggesting interoperability between the 2 SDKs. I would not expect necessarily, for example, that the admin-SDK implementation of FieldValue should work with a client-SDK query.
I'm only suggesting that the API surface expose the same types, so that I could inject either implementation (not both together) into my common code.
fingers crossed
Beta Was this translation helpful? Give feedback.
All reactions