Skip to content

Commit

Permalink
Merge pull request #154 from dalenguyen/dev
Browse files Browse the repository at this point in the history
update packages & refactors implementation
  • Loading branch information
dalenguyen authored Jul 30, 2023
2 parents 0827c67 + 91316f3 commit 235de03
Show file tree
Hide file tree
Showing 9 changed files with 992 additions and 739 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
> - :nail_care: [Polish]
---
## [1.4.0] - 2023-07-30

#### - :boom: [Breaking Change]

- passing firestore as a parameter (#153)

#### - :nail_care: [Polish]

- update packages

## [1.3.7] - 2023-04-15

Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ const options = {
// Initiate Firebase App
// appName is optional, you can omit it.
const appName = '[DEFAULT]'
initializeFirebaseApp(serviceAccount, appName, options)
const firestore = initializeFirebaseApp(serviceAccount, appName, options)

// the appName & options are OPTIONAL
// you can initalize the app without them
// initializeFirebaseApp(serviceAccount)
// you can initialize the app without them
// const firestore = initializeFirebaseApp(serviceAccount)
```

### Export data from firestore
Expand All @@ -74,7 +74,7 @@ const options = {
const { backup } = require('firestore-export-import')

// Start exporting your data
backup('collection-name', options).then((data) =>
backup(firestore, 'collection-name', options).then((data) =>
console.log(JSON.stringify(data))
)
```
Expand All @@ -85,7 +85,7 @@ Backup a document with sub collections

```javascript
// you can pass options as a third option - optional
backupFromDoc('collection-name', 'document-id').then((data) =>
backupFromDoc(firestore, 'collection-name', 'document-id').then((data) =>
console.log(JSON.stringify(data))
)
```
Expand All @@ -103,7 +103,7 @@ The result is an object of collection's data.
```javascript
const { backups } = require('firestore-export-import')

backups(['collectionName1', 'collectionName2']) // Array of collection's name is OPTIONAL
backups(firestore, ['collectionName1', 'collectionName2']) // Array of collection's name is OPTIONAL
.then((collections) => {
// You can do whatever you want with collections
console.log(JSON.stringify(collections))
Expand All @@ -118,7 +118,7 @@ You are can back update based on query criteria. In this example, I am backing u
const queryByName = (collectionRef) =>
collectionRef.where('name', '==', 'Dale Nguyen').get()

const users = await backup('users', {
const users = await backup(firestore, 'users', {
queryCollection: queryByName,
})
```
Expand Down Expand Up @@ -187,11 +187,11 @@ const serviceAccount = require('./serviceAccountKey.json')
// Initiate Firebase App
// appName is optional, you can omit it.
const appName = '[DEFAULT]'
initializeFirebaseApp(serviceAccount, databaseURL, appName)
const firestore = initializeFirebaseApp(serviceAccount, databaseURL, appName)
// Start importing your data
// The array of date, location and reference fields are optional
restore('your-file-path.json', {
restore(firestore, 'your-file-path.json', {
dates: ['date1', 'date1.date2', 'date1.date2.date3'],
geos: ['location', 'locations'],
refs: ['refKey', 'arrayRef'],
Expand All @@ -204,13 +204,13 @@ restore('your-file-path.json', {
import request from 'request-promise';
...
const backupData = await request('JSON-URL');
const status = await restore(JSON.parse(backupData), {
const status = await restore(firestore, JSON.parse(backupData), {
dates: ['date'],
geos: ['location']
});
```
The JSON is formated as below. The collection name is **test**. **first-key** and **second-key** are document ids.
The JSON is formatted as below. The collection name is **test**. **first-key** and **second-key** are document ids.
```json
{
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firestore-export-import",
"version": "1.3.6",
"version": "1.4.0",
"description": "NPM package for backup and restore Firebase Firestore",
"main": "./dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -34,22 +34,22 @@
},
"homepage": "https://github.com/dalenguyen/firestore-backup-restore#readme",
"devDependencies": {
"@types/chai": "^4.3.4",
"@types/chai": "^4.3.5",
"@types/expect": "^24.3.0",
"@types/mocha": "^10.0.1",
"@types/node": "^18.15.11",
"@types/node": "^20.4.5",
"chai": "^4.3.7",
"jsmin": "^1.0.1",
"minimist": "1.2.8",
"mocha": "^10.2.0",
"request": "^2.88.2",
"request-promise": "^4.2.6",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
"typescript": "^5.1.6"
},
"dependencies": {
"firebase-admin": "^11.6.0",
"google-gax": "^3.6.0",
"firebase-admin": "^11.10.1",
"google-gax": "^4.0.3",
"uuid": "^9.0.0"
},
"resolutions": {
Expand Down
Loading

0 comments on commit 235de03

Please sign in to comment.