Skip to content

Commit

Permalink
Using the utils functions from instant-firestore-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmyles committed Dec 18, 2018
1 parent b0c4c18 commit 102c773
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 353 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Instant Firestore

Firebase Firestore wrapper to ease common tasks, including creating, finding, updating and deleting documents.
Firebase Firestore ORM to ease common tasks, such as creating, finding, updating and deleting documents.

_**Please note:** This is an unofficial Firestore package, designed to assist with common Firestore tasks._

Expand Down
10 changes: 9 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "instant-firestore",
"version": "1.0.7",
"version": "1.0.8",
"description": "Firebase Firestore wrapper to ease common tasks, including creating, finding, updating and deleting documents.",
"main": "lib/index.js",
"scripts": {
Expand All @@ -19,6 +19,7 @@
"author": "Craig Myles",
"license": "MIT",
"dependencies": {
"instant-firestore-utils": "^1.0.3",
"instant-utils": "0.0.1"
},
"devDependencies": {
Expand Down
21 changes: 11 additions & 10 deletions src/classes/FirestoreCollection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import Default from './Default';
import { asyncForEach } from 'instant-utils';
import { getCollection, getDocument, deserialize } from '../utils';
import {
getCollection,
getDocument,
deserialize,
} from 'instant-firestore-utils';
import Default from './Default';

// Note the difference between `Firestore Document` and `document` in the comments - the latter is a serialized representation of the former

Expand Down Expand Up @@ -33,10 +37,7 @@ export default class FirestoreCollection extends Default {
}
const docRef = await this.colRef.add(attributes);
if (docRef.id) {
return {
...attributes,
id: docRef.id,
};
return await this.findById(docRef.id, options);
}
} catch (error) {
throw error;
Expand All @@ -50,14 +51,14 @@ export default class FirestoreCollection extends Default {
*/
async createMany(arr, options = {}) {
try {
let ids = [];
let docs = [];
const batch = this.db.batch();
await asyncForEach(arr, async attributes => {
const id = await this.create(attributes, options);
ids.push(id);
const doc = await this.create(attributes, options);
docs.push(doc);
});
batch.commit();
return ids;
return docs;
} catch (error) {
throw error;
}
Expand Down
4 changes: 2 additions & 2 deletions src/classes/FirestoreDocument.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getDocument, deserialize } from 'instant-firestore-utils';
import Default from './Default';
import { getDocument, deserialize } from '../utils';

// Note the difference between `Firestore Document` and `document` in the comments - the latter is a serialized representation of the former

Expand Down Expand Up @@ -74,7 +74,7 @@ export default class FirestoreDocument extends Default {
try {
const id = this.docRef.id;
await this.docRef.delete();
return { id };
return this.docRef.exists;
} catch (error) {
throw error;
}
Expand Down
2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export * from './utils';

export { default as FirestoreCollection } from './classes/FirestoreCollection';
export { default as FirestoreDocument } from './classes/FirestoreDocument';
export { default as FirestoreRepository } from './classes/FirestoreRepository';
268 changes: 0 additions & 268 deletions src/utils.js

This file was deleted.

Loading

0 comments on commit 102c773

Please sign in to comment.