-
Notifications
You must be signed in to change notification settings - Fork 1.1k
TypeScript-ify firestore API #1330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
"use strict"; | ||
import api = require("../api"); | ||
|
||
var api = require("../api"); | ||
|
||
var _API_ROOT = "/v1beta1/"; | ||
const _API_ROOT = "/v1beta1/"; | ||
|
||
/** | ||
* List all collection IDs. | ||
* | ||
* @param {string} project the Google Cloud project ID. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the future, feel free to remove types from the JSDocs as the types are documented in the function definitions! |
||
* @return {Promise<string[]>} a promise for an array of collection IDs. | ||
*/ | ||
var _listCollectionIds = function(project) { | ||
var url = _API_ROOT + "projects/" + project + "/databases/(default)/documents:listCollectionIds"; | ||
|
||
export async function listCollectionIds(project: string): Promise<string[]> { | ||
const url = | ||
_API_ROOT + "projects/" + project + "/databases/(default)/documents:listCollectionIds"; | ||
return api | ||
.request("POST", url, { | ||
auth: true, | ||
|
@@ -22,10 +20,10 @@ var _listCollectionIds = function(project) { | |
pageSize: 2147483647, | ||
}, | ||
}) | ||
.then(function(res) { | ||
.then((res) => { | ||
return res.body.collectionIds || []; | ||
}); | ||
}; | ||
} | ||
|
||
/** | ||
* Delete a single Firestore document. | ||
|
@@ -36,12 +34,12 @@ var _listCollectionIds = function(project) { | |
* @param {object} doc a Document object to delete. | ||
* @return {Promise} a promise for the delete operation. | ||
*/ | ||
var _deleteDocument = function(doc) { | ||
export async function deleteDocument(doc: any): Promise<void> { | ||
ryanpbrewster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return api.request("DELETE", _API_ROOT + doc.name, { | ||
auth: true, | ||
origin: api.firestoreOrigin, | ||
}); | ||
}; | ||
} | ||
|
||
/** | ||
* Delete an array of Firestore documents. | ||
|
@@ -53,33 +51,25 @@ var _deleteDocument = function(doc) { | |
* @param {object[]} docs an array of Document objects to delete. | ||
* @return {Promise<number>} a promise for the number of deleted documents. | ||
*/ | ||
var _deleteDocuments = function(project, docs) { | ||
var parent = "projects/" + project + "/databases/(default)/documents"; | ||
var url = parent + ":commit"; | ||
export async function deleteDocuments(project: string, docs: any[]): Promise<number> { | ||
const parent = "projects/" + project + "/databases/(default)/documents"; | ||
const url = parent + ":commit"; | ||
|
||
var writes = docs.map(function(doc) { | ||
const writes = docs.map((doc) => { | ||
return { | ||
delete: doc.name, | ||
}; | ||
}); | ||
|
||
var body = { | ||
writes: writes, | ||
}; | ||
const body = { writes }; | ||
|
||
return api | ||
.request("POST", _API_ROOT + url, { | ||
auth: true, | ||
data: body, | ||
origin: api.firestoreOrigin, | ||
}) | ||
.then(function(res) { | ||
.then((res) => { | ||
return res.body.writeResults.length; | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
deleteDocument: _deleteDocument, | ||
deleteDocuments: _deleteDocuments, | ||
listCollectionIds: _listCollectionIds, | ||
}; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.