Skip to content

Commit 3ab4ae3

Browse files
committed
Fixed bug where .getDocuments and .query didn't return Document fields. Closes #94
Added UnitTests to cover the above scenario. Added .gitattributes to handle line endings. Closes #93 Removed all GitHub domain prefixes on Markdown files. Enhances #92
1 parent cc1be09 commit 3ab4ae3

File tree

6 files changed

+35
-11
lines changed

6 files changed

+35
-11
lines changed

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto
3+
4+
# Files with crlf endings
5+
LICENSE text eol=crlf
6+
*.ts text eol=crlf
7+
*.json text eol=crlf
8+
*.md text eol=crlf
9+
*.yml text eol=crlf

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Hi! Thanks for creating a pull request.
22

3-
Please make sure you have read the [Contributing](https://github.com/grahamearley/FirestoreGoogleAppsScript/blob/main/.github/CONTRIBUTING.md) guidelines before submitting.
3+
Please make sure you have read the [Contributing](/grahamearley/FirestoreGoogleAppsScript/blob/main/.github/CONTRIBUTING.md) guidelines before submitting.
44

55
(You can delete this text).

.github/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
![GitHub release (latest by date)](https://img.shields.io/github/v/release/grahamearley/FirestoreGoogleAppsScript)
44
[![Google Apps Script](https://img.shields.io/badge/google%20apps%20script-v8-%234285f4)](https://developers.google.com/apps-script/guides/v8-runtime)
55
[![TypeScript](https://img.shields.io/badge/typescript-3.9.5-%23294E80)](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html)
6-
[![clasp](https://img.shields.io/badge/built%20with-clasp-4285f4.svg)](https://github.com/google/clasp)
7-
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
8-
[![GitHub pull requests](https://img.shields.io/github/issues-pr/grahamearley/FirestoreGoogleAppsScript)](https://github.com/grahamearley/FirestoreGoogleAppsScript/pulls)
9-
[![GitHub issues](https://img.shields.io/github/issues/grahamearley/FirestoreGoogleAppsScript)](https://github.com/grahamearley/FirestoreGoogleAppsScript/issues)
6+
[![clasp](https://img.shields.io/badge/built%20with-clasp-4285f4.svg)](/google/clasp)
7+
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](/prettier/prettier)
8+
[![GitHub pull requests](https://img.shields.io/github/issues-pr/grahamearley/FirestoreGoogleAppsScript)](/grahamearley/FirestoreGoogleAppsScript/pulls)
9+
[![GitHub issues](https://img.shields.io/github/issues/grahamearley/FirestoreGoogleAppsScript)](/grahamearley/FirestoreGoogleAppsScript/issues)
1010
![Tests](https://img.shields.io/endpoint?url=https%3A%2F%2Fscript.google.com%2Fmacros%2Fs%2FAKfycbzle3ze4mtGAcTNPlqISSFxtmPqvdcNOFauiC4Q0g%2Fexec)
1111

1212
### A Google Apps Script library for accessing Google Cloud Firestore.
@@ -152,7 +152,7 @@ See other library methods and details [in the wiki](/grahamearley/FirestoreGoogl
152152
## Contributions
153153
Contributions are welcome — send a pull request! See [here](/grahamearley/FirestoreGoogleAppsScript/blob/main/.github/CONTRIBUTING.md) for more information on contributing.
154154

155-
After cloning this repository, you can push it to your own private copy of this Google Apps Script project to test it yourself. See [here](https://github.com/google/clasp) for directions on using `clasp` to develop App Scripts locally.
155+
After cloning this repository, you can push it to your own private copy of this Google Apps Script project to test it yourself. See [here](/google/clasp) for directions on using `clasp` to develop App Scripts locally.
156156
Install all packages from `package.json` with a bare `npm install`.
157157

158158

FirestoreRead.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class FirestoreRead {
100100
// Remove missing entries
101101
documents = documents.filter((docItem: FirestoreAPI.BatchGetDocumentsResponse) => docItem.found);
102102
return documents.map((docItem: FirestoreAPI.BatchGetDocumentsResponse) => {
103-
const doc = docItem.found! as Document;
103+
const doc = new Document(docItem.found!, { readTime: docItem.readTime } as Document);
104104
doc.readTime = docItem.readTime;
105105
return doc;
106106
});

Query.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ enum UnaryFilterOps_ {
3030
* @see {@link https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery Firestore Structured Query}
3131
*/
3232
class Query implements FirestoreAPI.StructuredQuery {
33-
select: FirestoreAPI.Projection;
33+
select?: FirestoreAPI.Projection;
3434
from?: FirestoreAPI.CollectionSelector[];
3535
where?: FirestoreAPI.Filter;
3636
orderBy?: FirestoreAPI.Order[];
@@ -45,7 +45,6 @@ class Query implements FirestoreAPI.StructuredQuery {
4545
* @param {QueryCallback} callback the function that is executed with the internally compiled query
4646
*/
4747
constructor(from: string, callback: QueryCallback) {
48-
this.select = { fields: [] };
4948
this.callback = callback;
5049
if (from) {
5150
this.from = [{ collectionId: from }];
@@ -141,7 +140,9 @@ class Query implements FirestoreAPI.StructuredQuery {
141140
// Catch undefined or blank strings and return document name
142141
field = '__name__';
143142
}
144-
143+
if (!this.select) {
144+
this.select = { fields: [] };
145+
}
145146
this.select['fields']!.push(this.fieldRef_(field));
146147
return this;
147148
}

Tests.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function StoreCredentials_(): void {
1+
function StoreCredentials_(): void {
22
/** DO NOT SAVE CREDENTIALS HERE */
33
const email = 'xxx@appspot.gserviceaccount.com';
44
const key = '-----BEGIN PRIVATE KEY-----\nLine\nLine\n-----END PRIVATE KEY-----';
@@ -201,6 +201,14 @@ class Tests implements TestManager {
201201
GSUnit.assertEquals(ids.length - 1, docs.length);
202202
}
203203

204+
Test_Get_Documents_Content(): void {
205+
const path = 'Test Collection';
206+
const ids = ['New Document !@#$%^&*(),.<>?;\':"[]{}|-=_+áéíóúæÆÑ'];
207+
const docs = this.db.getDocuments(path, ids);
208+
GSUnit.assertEquals(ids.length, docs.length);
209+
GSUnit.assertObjectEquals(this.expected_, docs[0].obj);
210+
}
211+
204212
Test_Get_Documents_By_ID_Missing(): void {
205213
const path = 'Missing Collection';
206214
const ids = [
@@ -250,6 +258,12 @@ class Tests implements TestManager {
250258
GSUnit.assertArrayEquals(expected, docs);
251259
}
252260

261+
Test_Query_One(): void {
262+
const path = 'Test Collection';
263+
const docs = this.db.query(path).Where('null value', null).Execute();
264+
GSUnit.assertObjectEquals(this.expected_, docs[0].obj);
265+
}
266+
253267
Test_Query_Select_Name(): void {
254268
const path = 'Test Collection';
255269
const docs = this.db.query(path).Select().Execute();

0 commit comments

Comments
 (0)