Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/j-mendez/dfirestore
a deno Firestore client
https://github.com/j-mendez/dfirestore
deno deno-firestore firebase firebase-firestore firestore firestore-client
Last synced: about 1 month ago
JSON representation
a deno Firestore client
- Host: GitHub
- URL: https://github.com/j-mendez/dfirestore
- Owner: j-mendez
- License: mit
- Created: 2021-06-27T11:02:14.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-23T15:50:18.000Z (over 2 years ago)
- Last Synced: 2024-09-16T17:11:49.636Z (2 months ago)
- Topics: deno, deno-firestore, firebase, firebase-firestore, firestore, firestore-client
- Language: TypeScript
- Homepage: https://deno.land/x/dfirestore
- Size: 37.1 KB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dfirestore
![test workflow](https://github.com/j-mendez/dfirestore/actions/workflows/test.yml/badge.svg)
[![Maintainability](https://api.codeclimate.com/v1/badges/ed5ddd5e541f49f61382/maintainability)](https://codeclimate.com/github/j-mendez/dfirestore/maintainability)a deno [Firestore](https://firebase.google.com/docs/firestore) REST client
## Usage
To get started with the package you can either setup the application with your tokens or authenticate with one of the helpers.
After you authenticate you can freely use the REST client and your access tokens will rotate before they expire.
For examples of values to use when perform creates/updates can be found at [Firestore Value Docs](https://firebase.google.com/docs/firestore/reference/rest/v1/Value)### Configuration
All pre-configuration settings are optional and can be set via env variables. You should use `setProjectID` to establish your project if you are going to use the same one for every request. Make sure to start deno with the following `--allow-env --allow-read --unstable --allow-run --allow-net=firestore.googleapis.com,identitytoolkit.googleapis.com` to allow network request to firestore.
```typescript
import {
setDatabase,
setToken,
setProjectID,
setProjectKey,
setTokenFromServiceAccount,
setTokenFromEmailPassword,
} from "https://deno.land/x/dfirestore/mod.ts";// Optional: If GoogleService-Info.plist and gcloud installed on machine run to get service token
setTokenFromServiceAccount();
// Optional: If Email and Password secret shared. Optional params when using env variables
setTokenFromEmailPassword(
{
email: "[email protected]",
password: "something",
},
true // background refresh token before expiration
);
// Optional: Manually set authentication from access token (jwt)
setToken("someidtoken");// Optional: set db
setDatabase("(default)");
// Optional: set global project id for all request - nice to use.
setProjectID("my_project_id");
// Optional: set project web key or use the env FIREBASE_PROJECT_KEY
setProjectKey("mywebprojectkey");
```### Client
Use the REST client below via the following methods to perform CRUD operations.
```typescript
import { firestore } from "https://deno.land/x/dfirestore/mod.ts";// add new document: Check firebase param values for list key types ex (stringValue).
await firestore.createDocument({
collection: "users",
id: "L0xO1Yri80WlrFSw6KxqccHhKhv2",
value: { firstname: { stringValue: "Jeff" } },
});
// get document in collection by id
await firestore.getDocument({
collection: "users",
id: "L0xO1Yri80WlrFSw6KxqccHhKhv2",
});
// get document collection list
await firestore.getDocument({
collection: "users",
pageSize: 10, // optional: page limit
pageToken: "thepagetokenfornextpage", // optional: page token to get the next page
orderBy: "desc", // optional: order desc, key, etc
showMissing: false, // optional: show missing props
mask: { fieldPaths: ["id", "name"] }, // optional: mask the object fields
});
// delete document by id
await firestore.deleteDocument({
collection: "users",
id: "L0xO1Yri80WlrFSw6KxqccHhKhv2",
});
// update document in collection by id
await firestore.updateDocument({
collection: "users",
id: "L0xO1Yri80WlrFSw6KxqccHhKhv2",
value: { firstname: { stringValue: "Jeff" } },
});
// update document in collection by id for set projectID
await firestore.updateDocument({
collection: "users",
id: "L0xO1Yri80WlrFSw6KxqccHhKhv2",
project: "someproj",
value: { firstname: { stringValue: "Jeff" } },
});
// move documents import/export may require admin account token
await firestore.moveDocuments({
collectionIds: undefined, // export all documents
outputUriPrefix: "gs://BUCKET_NAME[/NAMESPACE_PATH]", // replace with your bucket name and namespace
type: "export",
});
```## Environment Variables
The environment variables below will help setup the project defaults so you do not have to manually configure at the application level. If you are not going to setup any of the envs below you need to make sure you pass in the required params.
```
FIREBASE_AUTH_EMAIL=
FIREBASE_AUTH_PASSWORD=
FIREBASE_PROJECT_KEY=
FIREBASE_PROJECT_ID=
FIREBASE_DATABASE=(default)
FIREBASE_TOKEN=
FIREBASE_EVENT_LOG=
FIREBASE_REFRESH_RATE=
CI=
```## CLI
A CLI entrypoint that can manage the access token between steps is WIP. For now set the token prior per run.