Skip to content

Commit bf65598

Browse files
authored
[ACTION] Get Firebase Document (#16269)
1 parent f15cf0d commit bf65598

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import common from "../common/base.mjs";
2+
3+
export default {
4+
...common,
5+
key: "firebase_admin_sdk-get-document",
6+
name: "Get Document",
7+
description: "Retrieves a document from a Firestore collection. [See the documentation](https://firebase.google.com/docs/firestore/query-data/get-data#get_a_document)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
...common.props,
12+
collection: {
13+
propDefinition: [
14+
common.props.firebase,
15+
"collection",
16+
(c) => ({
17+
region: c.databaseRegion,
18+
}),
19+
],
20+
},
21+
document: {
22+
propDefinition: [
23+
common.props.firebase,
24+
"document",
25+
(c) => ({
26+
collection: c.collection,
27+
region: c.databaseRegion,
28+
}),
29+
],
30+
},
31+
},
32+
methods: {
33+
...common.methods,
34+
async getResponse() {
35+
const docRef = this.firebase.getDocument({
36+
collection: this.collection,
37+
document: this.document,
38+
});
39+
const snapshot = await docRef.get();
40+
41+
if (!snapshot.exists) {
42+
return {
43+
exists: false,
44+
id: this.document,
45+
};
46+
}
47+
48+
return {
49+
exists: true,
50+
id: snapshot.id,
51+
data: snapshot.data(),
52+
createTime: snapshot.createTime?.toDate(),
53+
updateTime: snapshot.updateTime?.toDate(),
54+
readTime: snapshot.readTime?.toDate(),
55+
ref: snapshot.ref.path,
56+
};
57+
},
58+
emitSummary($, response) {
59+
if (!response.exists) {
60+
$.export("$summary", `Document ${this.document} not found in collection ${this.collection}`);
61+
return;
62+
}
63+
$.export("$summary", `Successfully retrieved document ${this.document} from collection ${this.collection}`);
64+
},
65+
},
66+
};

components/firebase_admin_sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/firebase_admin_sdk",
3-
"version": "0.0.10",
3+
"version": "0.1.0",
44
"description": "Pipedream Firebase Admin SDK Components",
55
"main": "firebase_admin_sdk.app.mjs",
66
"keywords": [

pnpm-lock.yaml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)