
Product
Announcing Precomputed Reachability Analysis in Socket
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
firebase-admin-rest
Advanced tools
npm i firebase-admin-rest@latest
// firebase-admin
const db = app.firestore();
const docs = await db.collection(`users`).limit(10).get()
// firebase-admin-rest
const db = await initFirebaseRest().firestore();
const docRef = await db.doc<User>(`users`).limit(10).page(2).get();
Typesafe + helper functions like pagination!
npm i firebase-admin-rest@latest
FAR_PROJECT_ID="PROJECT_ID"
FAR_CLIENT_EMAIL="SERVICE_ACCOUNT_CLIENT_EMAIL"
FAR_PRIVATE_KEY="SERVICE_ACCOUNT_PRIVATE_KEY"
const db = await initFirebaseRest().firestore();
const docRef = await db.doc(`users/test_1`).get();
console.log(docRef.data())
const db = await initFirebaseRest({
serviceAccount: serviceAccountObject, // service acccount config
databaseId: '(default)', // change it to a custom db
}).firestore();
const docRef = await db.doc(`users/test_1`).get();
console.log(docRef.data())
async function getDoc() {
const db = await initFirebaseRest().firestore();
const docRef = await db.doc(`users/test_1`).get();
console.log(docRef.data())
}
getDoc();
async function getDocs() {
const db = await initFirebaseRest().firestore();
const docsRef = await db.collection('users').limit(10).get();
docsRef.docs.forEach(element => {
console.log(element.data())
});
}
getDocs()
async function queryDocs1() {
const db = await initFirebaseRest().firestore();
const docsRef = await db.collection<any>('users').where('age', '>', 25).get();
docsRef.docs.forEach(element => {
const user = element.data();
console.log(user?.name)
});
}
queryDocs1()
By default if a query requires an index to be created we also handle error handling and output the URL to create the index right away during development.
async function queryDocs2() {
const db = await initFirebaseRest().firestore();
const docsRef = await db.collection<any>('users').where('name', '==', 'John Doe').orderBy('age', 'desc').get();
// outputs an error if index is not created..
docsRef.docs.forEach(element => {
const user = element.data();
console.log(user?.name)
});
}
queryDocs2()
Out of the box you can simply call .page and you can paginate the results where every page will have the limit you specifed.
async function queryDocs3() {
const db = await initFirebaseRest().firestore();
const docsRef = await db.collection<any>('users').where('age', '>', 25).orderBy('age', 'desc').limit(5).page(3).get(); // 5 items per page
docsRef.docs.forEach(element => {
const user = element.data();
console.log(user?.name)
});
}
async function collectionToDocs() {
const db = await initFirebaseRest().firestore();
const docsRef = await db.collection<any>('big_data').todocs(
Array(50_000).fill(null).map((item, index) => {
return {
id: `${Math.random().toString(36).substring(7)}`,
name: `John Doe ${index}`,
age: 30,
email: `atoot@gmail.com`,
}
})
);
console.log(`Done`, docsRef)
}
collectionToDocs()
async function collectionToJson(){
const db = await initFirebaseRest().firestore();
const docsRef = await db.collection(`big_data`).tojson();
// this will return a JSON object with the same structure as the collection
// each document read has 1MB of data, so this is a good way to store large data without querying hundreds or thousands of documents
// storing on a bucket is also an option, but the bandwidth is expensive and will add up
console.log(docsRef.docReads)
}
collectionToJson()
Actively maintained by @Moe03 since I'm using it all the time on edge functions, cloudflare workers and will definitely support more firebase services soon.
Contribute however you'd like :)
MIT
Lib built with bun and generated by: https://github.com/wobsoriano/bun-lib-starter/generate
FAQs
Tiny Typesafe Firebase Admin REST API wrapper that works on Vercel Edge functions, Bun, Cloudflare workers, Deno or any JS runtime.
The npm package firebase-admin-rest receives a total of 92 weekly downloads. As such, firebase-admin-rest popularity was classified as not popular.
We found that firebase-admin-rest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s precomputed reachability slashes false positives by flagging up to 80% of vulnerabilities as irrelevant, with no setup and instant results.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.