Skip to content

Commit 37d1a28

Browse files
authored
Merge branch 'master' into mc/persist
2 parents 29be135 + 8fc7be2 commit 37d1a28

File tree

10 files changed

+66
-12
lines changed

10 files changed

+66
-12
lines changed

auth-next/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function authStateListener() {
5252
onAuthStateChanged(auth, (user) => {
5353
if (user) {
5454
// User is signed in, see docs for a list of available properties
55-
// https://firebase.google.com/docs/reference/js/firebase.User
55+
// https://firebase.google.com/docs/reference/js/v8/firebase.User
5656
const uid = user.uid;
5757
// ...
5858
} else {
@@ -72,7 +72,7 @@ function currentUser() {
7272

7373
if (user) {
7474
// User is signed in, see docs for a list of available properties
75-
// https://firebase.google.com/docs/reference/js/firebase.User
75+
// https://firebase.google.com/docs/reference/js/v8/firebase.User
7676
// ...
7777
} else {
7878
// No user is signed in.

auth/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function authStateListener() {
4343
firebase.auth().onAuthStateChanged((user) => {
4444
if (user) {
4545
// User is signed in, see docs for a list of available properties
46-
// https://firebase.google.com/docs/reference/js/firebase.User
46+
// https://firebase.google.com/docs/reference/js/v8/firebase.User
4747
var uid = user.uid;
4848
// ...
4949
} else {
@@ -60,7 +60,7 @@ function currentUser() {
6060

6161
if (user) {
6262
// User is signed in, see docs for a list of available properties
63-
// https://firebase.google.com/docs/reference/js/firebase.User
63+
// https://firebase.google.com/docs/reference/js/v8/firebase.User
6464
// ...
6565
} else {
6666
// No user is signed in.

firestore-next/test.firestore.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ describe("firestore", () => {
597597
if (docSnap.exists()) {
598598
console.log("Document data:", docSnap.data());
599599
} else {
600-
// doc.data() will be undefined in this case
600+
// docSnap.data() will be undefined in this case
601601
console.log("No such document!");
602602
}
603603
// [END get_document]
@@ -697,6 +697,18 @@ describe("firestore", () => {
697697
// [END get_multiple_all]
698698
});
699699

700+
it("should get all documents from a subcollection", async () => {
701+
// [START firestore_query_subcollection]
702+
const { collection, getDocs } = require("firebase/firestore");
703+
// Query a reference to a subcollection
704+
const querySnapshot = await getDocs(collection(db, "cities", "SF", "landmarks"));
705+
querySnapshot.forEach((doc) => {
706+
// doc.data() is never undefined for query doc snapshots
707+
console.log(doc.id, " => ", doc.data());
708+
});
709+
// [END firestore_query_subcollection]
710+
});
711+
700712
it("should listen on multiple documents #UNVERIFIED", (done) => {
701713
// [START listen_multiple]
702714
const { collection, query, where, onSnapshot } = require("firebase/firestore");

firestore/test.firestore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ describe("firestore", () => {
600600
var docRef = db.collection("cities").doc("SF");
601601

602602
// Valid options for source are 'server', 'cache', or
603-
// 'default'. See https://firebase.google.com/docs/reference/js/firebase.firestore.GetOptions
603+
// 'default'. See https://firebase.google.com/docs/reference/js/v8/firebase.firestore.GetOptions
604604
// for more information.
605605
var getOptions = {
606606
source: 'cache'

firestore/test.solution-counters.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function createCounter(ref, num_shards) {
2222
// [END create_counter]
2323

2424
// [START increment_counter]
25-
function incrementCounter(db, ref, num_shards) {
25+
function incrementCounter(ref, num_shards) {
2626
// Select a shard of the counter at random
2727
const shard_id = Math.floor(Math.random() * num_shards).toString();
2828
const shard_ref = ref.collection('shards').doc(shard_id);
@@ -67,15 +67,15 @@ describe("firestore-solution-counters", () => {
6767
// Create a counter, then increment it
6868
const ref = db.collection('counters').doc();
6969
return createCounter(ref, 10).then(() => {
70-
return incrementCounter(db, ref, 10);
70+
return incrementCounter(ref, 10);
7171
});
7272
});
7373

7474
it("should get the count of a counter", () => {
7575
// Create a counter, increment it, then get the count
7676
const ref = db.collection('counters').doc();
7777
return createCounter(ref, 10).then(() => {
78-
return incrementCounter(db, ref, 10);
78+
return incrementCounter(ref, 10);
7979
}).then(() => {
8080
return getCount(ref);
8181
});

scripts/separate-snippets.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ const RE_END_SNIPPET = /\[END\s+([A-Za-z_]+)\s*\]/;
1818
// TODO: Handle multiline imports?
1919
const RE_REQUIRE = /const {(.+?)} = require\((.+?)\)/;
2020

21+
// Regex for ref docs URLs
22+
// eg. "https://firebase.google.com/docs/reference/js/v8/firebase.User"
23+
const RE_REF_DOCS = /https:\/\/firebase\.google\.com\/docs\/reference\/js\/(.*)/;
24+
25+
// Maps v8 ref docs URLs to their v9 counterpart
26+
const REF_DOCS_MAPPINGS: { [key: string]: string } = {
27+
"v8/firebase.User" : "auth.user"
28+
};
29+
2130
type SnippetsConfig = {
2231
enabled: boolean;
2332
suffix: string;
@@ -30,6 +39,23 @@ function isBlank(line: string) {
3039
return line.trim().length === 0;
3140
}
3241

42+
/**
43+
* Replace all v8 ref doc urls with their v9 counterpart.
44+
*/
45+
function replaceRefDocsUrls(lines: string[]) {
46+
const outputLines = [];
47+
for (const line of lines) {
48+
if (line.match(RE_REF_DOCS)) {
49+
outputLines.push(line.replace(RE_REF_DOCS, (match: string, p1?: string) => {
50+
return p1 ? `https://firebase.google.com/docs/reference/js/${REF_DOCS_MAPPINGS[p1]}` : match;
51+
}));
52+
} else {
53+
outputLines.push(line);
54+
}
55+
}
56+
return outputLines;
57+
}
58+
3359
/**
3460
* Replace all const { foo } = require('bar') with import { foo } from 'bar';
3561
*/
@@ -119,6 +145,7 @@ function processSnippet(
119145
outputLines = addSuffixToSnippetNames(outputLines, snippetSuffix);
120146
outputLines = adjustIndentation(outputLines);
121147
outputLines = removeFirstLineAfterComments(outputLines);
148+
outputLines = replaceRefDocsUrls(outputLines);
122149

123150
// Add a preamble to every snippet
124151
const preambleLines = [

snippets/auth-next/index/auth_current_user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const user = auth.currentUser;
1212

1313
if (user) {
1414
// User is signed in, see docs for a list of available properties
15-
// https://firebase.google.com/docs/reference/js/firebase.User
15+
// https://firebase.google.com/docs/reference/js/auth.user
1616
// ...
1717
} else {
1818
// No user is signed in.

snippets/auth-next/index/auth_state_listener.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const auth = getAuth();
1111
onAuthStateChanged(auth, (user) => {
1212
if (user) {
1313
// User is signed in, see docs for a list of available properties
14-
// https://firebase.google.com/docs/reference/js/firebase.User
14+
// https://firebase.google.com/docs/reference/js/auth.user
1515
const uid = user.uid;
1616
// ...
1717
} else {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// This snippet file was generated by processing the source file:
2+
// ./firestore-next/test.firestore.js
3+
//
4+
// To update the snippets in this file, edit the source and then run
5+
// 'npm run snippets'.
6+
7+
// [START firestore_query_subcollection_modular]
8+
import { collection, getDocs } from "firebase/firestore";
9+
// Query a reference to a subcollection
10+
const querySnapshot = await getDocs(collection(db, "cities", "SF", "landmarks"));
11+
querySnapshot.forEach((doc) => {
12+
// doc.data() is never undefined for query doc snapshots
13+
console.log(doc.id, " => ", doc.data());
14+
});
15+
// [END firestore_query_subcollection_modular]

snippets/firestore-next/test-firestore/get_document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const docSnap = await getDoc(docRef);
1313
if (docSnap.exists()) {
1414
console.log("Document data:", docSnap.data());
1515
} else {
16-
// doc.data() will be undefined in this case
16+
// docSnap.data() will be undefined in this case
1717
console.log("No such document!");
1818
}
1919
// [END get_document_modular]

0 commit comments

Comments
 (0)