Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .eslintrc.json

This file was deleted.

9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ jobs:
strategy:
matrix:
node-version:
- 14.x
- 20.x
- 22.x
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v5
- uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}

- name: Cache npm
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package.json') }}
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ tsconfig.json
dist/
.DS_Store
.idea
pnpm-lock.yaml
14 changes: 14 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import { defineConfig } from "eslint/config";
import js from "@eslint/js";

export default defineConfig([
js.configs.recommended,
{
rules: {
"no-unused-vars": "off",
"no-undef": "off",
"no-redeclare": "off"
},
},
]);
12 changes: 6 additions & 6 deletions firestore-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
},
"license": "Apache-2.0",
"dependencies": {
"firebase": "^10.0.0",
"geofire-common": "^5.1.0"
"firebase": "^12.4.0",
"geofire-common": "^6.0.0"
},
"devDependencies": {
"@types/chai": "^4.2.12",
"@types/mocha": "^8.0.3",
"chai": "^4.2.0",
"mocha": "^8.1.3"
"@types/chai": "^5.2.3",
"@types/mocha": "^10.0.10",
"chai": "^6.2.0",
"mocha": "^11.7.4"
}
}
74 changes: 73 additions & 1 deletion firestore-next/test.firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// [SNIPPETS_SEPARATION enabled]

const { expect } = require('chai');
import { or } from "firebase/firestore";

// [START city_custom_object]
class City {
Expand Down Expand Up @@ -892,7 +893,7 @@ describe("firestore", () => {
const { query, where } = require("firebase/firestore");

const q = query(citiesRef,
where('regions', 'array-contains-any', ['west_coast', 'east_coast']));
where('regions', 'array-contains-any', [['west_coast'], ['east_coast']]));
// [END array_contains_any_filter]
});

Expand Down Expand Up @@ -1102,6 +1103,77 @@ describe("firestore", () => {
limit(25));
// [END paginate]
});

it("should handle OR queries", async () => {
const { collection, query, where, and } = require("firebase/firestore");
// [START or_query]
const q = query(collection(db, "cities"), and(
where('state', '==', 'CA'),
or(
where('capital', '==', true),
where('population', '>=', 1000000)
)
));
// [END or_query]
});

it("should allow for 30 or fewer disjunctions", async () => {
const { collection, query, where, and } = require("firebase/firestore");
const collectionRef = collection(db, "cities");
// [START one_disjunction]
query(collectionRef, where("a", "==", 1));
// [END one_disjunction]

// [START two_disjunctions]
query(collectionRef, or( where("a", "==", 1), where("b", "==", 2) ));
// [END two_disjunctions]

// [START four_disjunctions]
query(collectionRef,
or( and( where("a", "==", 1), where("c", "==", 3) ),
and( where("a", "==", 1), where("d", "==", 4) ),
and( where("b", "==", 2), where("c", "==", 3) ),
and( where("b", "==", 2), where("d", "==", 4) )
)
);
// [END four_disjunctions]

// [START four_disjunctions_compact]
query(collectionRef,
and( or( where("a", "==", 1), where("b", "==", 2) ),
or( where("c", "==", 3), where("d", "==", 4) )
)
);
// [END four_disjunctions_compact]

expect(() => {
// [START 50_disjunctions]
query(collectionRef,
and( where("a", "in", [1, 2, 3, 4, 5]),
where("b", "in", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
)
);
// [END 50_disjunctions]
}).to.throw;

// [START 20_disjunctions]
query(collectionRef,
or( where("a", "in", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
where("b", "in", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
)
);
// [END 20_disjunctions]

// [START 10_disjunctions]
query(collectionRef,
and( where("a", "in", [1, 2, 3, 4, 5]),
or( where("b", "==", 2),
where("c", "==", 3)
)
)
);
// [END 10_disjunctions]
});
});

describe('collectionGroup(landmarks)', () => {
Expand Down
5 changes: 5 additions & 0 deletions firestore-next/test.solution-geoqueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ async function addHash(done) {
done();
}

// tsc complains `center` can have more or fewer than 2 elements, but
// since this is a js file there's no way of more accurately specifying
// `center`'s type.
async function queryHashes(done) {
// [START fs_geo_query_hashes]
const { collection, query, orderBy, startAt, endAt, getDocs } = require('firebase/firestore');
Expand All @@ -40,6 +43,7 @@ async function queryHashes(done) {
// Each item in 'bounds' represents a startAt/endAt pair. We have to issue
// a separate query for each pair. There can be up to 9 pairs of bounds
// depending on overlap, but in most cases there are 4.
// @ts-ignore
const bounds = geofire.geohashQueryBounds(center, radiusInM);
const promises = [];
for (const b of bounds) {
Expand All @@ -63,6 +67,7 @@ async function queryHashes(done) {

// We have to filter out a few false positives due to GeoHash
// accuracy, but most will match
// @ts-ignore
const distanceInKm = geofire.distanceBetween([lat, lng], center);
const distanceInM = distanceInKm * 1000;
if (distanceInM <= radiusInM) {
Expand Down
2 changes: 1 addition & 1 deletion firestore/test.firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ describe("firestore", () => {
const citiesRef = db.collection('cities');
// [START array_contains_any_filter]
citiesRef.where('regions', 'array-contains-any',
['west_coast', 'east_coast']);
[['west_coast'], ['east_coast']]);
// [END array_contains_any_filter]
});

Expand Down
4 changes: 3 additions & 1 deletion installations/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "installations",
"version": "1.0.0",
"scripts": {},
"scripts": {
"compile": "echo 'Installations build temporarily disabled'"
},
"license": "Apache 2.0",
"dependencies": {
"firebase": "^8.10.0"
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{
"name": "snippets-web",
"version": "1.0.0",
"type": "module",
"scripts": {
"snippets": "rimraf snippets && ts-node scripts/separate-snippets.ts",
"snippets": "rimraf snippets && node --loader ts-node/esm scripts/separate-snippets.ts",
"lint": "git ls-files | grep -v 'snippets/' | grep '.js$' | xargs npx eslint",
"format": "npm run lint -- --fix",
"bootstrap": "pnpm recursive install",
"compile": "pnpm recursive run compile --workspace-concurrency=4"
"bootstrap": "find . -type f -name package.json -not -path '*/node_modules/*' -exec bash -c 'cd $(dirname {}) && npm install' \\;",
"compile": "bash scripts/compile.sh"
},
"license": "Apache-2.0",
"devDependencies": {
"@types/node": "^16.7.10",
"eslint": "^7.32.0",
"pnpm": "^6.14.6",
"rimraf": "^3.0.2",
"ts-node": "^10.2.1",
"typescript": "^4.4.2"
"@eslint/js": "^9.38.0",
"@types/node": "^24.9.1",
"eslint": "^9.38.0",
"rimraf": "^5.0.10",
"ts-node": "^10.9.2",
"typescript": "^5.9.0"
}
}
2 changes: 1 addition & 1 deletion scripts/checkdirty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ if [[ $(git diff --stat HEAD) != '' ]]; then
echo 'Error: git diff is dirty ... did you forget to run "npm run snippets" after adding snippets?'
exit 1
else
echo 'Succes: git diff is clean'
echo 'Success: git diff is clean'
fi
33 changes: 33 additions & 0 deletions scripts/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

# Runs `npm run compile` across all snippet directories.

echo "Starting package compilation search..."

# Iterate over all direct subdirectories (ending with /)
# The glob pattern '*/' ensures we only look at directories at this level.
for dir in */; do
# Strip the trailing slash for cleaner output and directory path usage
subdir="${dir%/}"

# Check if a package.json file exists in the current subdirectory
if [[ -f "$subdir/package.json" && "$subdir" != "scripts" ]]; then
echo "--> Found package.json in '$subdir'. Running 'npm run compile'..."

# Use a subshell (parentheses) for the 'cd' command.
# This executes 'cd' and 'npm run compile' in a separate process,
# ensuring the main script's working directory doesn't change,
# and the loop continues correctly from the parent path.
if (cd "$subdir" && npm run compile); then
echo "Successfully compiled '$subdir'."
else
echo "ERROR: Compilation failed for '$subdir'. Check the output above."
exit 1
fi

else
: # skip directories like snippets and .github
fi
done

echo "Package compilation search complete."
1 change: 1 addition & 0 deletions scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "scripts",
"version": "1.0.0",
"type": "module",
"description": "Internal repo scripts",
"scripts": {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import { query, where } from "firebase/firestore";

const q = query(citiesRef,
where('regions', 'array-contains-any', ['west_coast', 'east_coast']));
where('regions', 'array-contains-any', [['west_coast'], ['east_coast']]));
// [END array_contains_any_filter_modular]
15 changes: 15 additions & 0 deletions snippets/firestore-next/test-firestore/four_disjunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This snippet file was generated by processing the source file:
// ./firestore-next/test.firestore.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.

// [START four_disjunctions_modular]
query(collectionRef,
or( and( where("a", "==", 1), where("c", "==", 3) ),
and( where("a", "==", 1), where("d", "==", 4) ),
and( where("b", "==", 2), where("c", "==", 3) ),
and( where("b", "==", 2), where("d", "==", 4) )
)
);
// [END four_disjunctions_modular]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This snippet file was generated by processing the source file:
// ./firestore-next/test.firestore.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.

// [START four_disjunctions_compact_modular]
query(collectionRef,
and( or( where("a", "==", 1), where("b", "==", 2) ),
or( where("c", "==", 3), where("d", "==", 4) )
)
);
// [END four_disjunctions_compact_modular]
9 changes: 9 additions & 0 deletions snippets/firestore-next/test-firestore/one_disjunction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This snippet file was generated by processing the source file:
// ./firestore-next/test.firestore.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.

// [START one_disjunction_modular]
query(collectionRef, where("a", "==", 1));
// [END one_disjunction_modular]
15 changes: 15 additions & 0 deletions snippets/firestore-next/test-firestore/or_query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This snippet file was generated by processing the source file:
// ./firestore-next/test.firestore.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.

// [START or_query_modular]
const q = query(collection(db, "cities"), and(
where('state', '==', 'CA'),
or(
where('capital', '==', true),
where('population', '>=', 1000000)
)
));
// [END or_query_modular]
9 changes: 9 additions & 0 deletions snippets/firestore-next/test-firestore/two_disjunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This snippet file was generated by processing the source file:
// ./firestore-next/test.firestore.js
//
// To update the snippets in this file, edit the source and then run
// 'npm run snippets'.

// [START two_disjunctions_modular]
query(collectionRef, or( where("a", "==", 1), where("b", "==", 2) ));
// [END two_disjunctions_modular]
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const radiusInM = 50 * 1000;
// Each item in 'bounds' represents a startAt/endAt pair. We have to issue
// a separate query for each pair. There can be up to 9 pairs of bounds
// depending on overlap, but in most cases there are 4.
// @ts-ignore
const bounds = geofire.geohashQueryBounds(center, radiusInM);
const promises = [];
for (const b of bounds) {
Expand All @@ -37,6 +38,7 @@ for (const snap of snapshots) {

// We have to filter out a few false positives due to GeoHash
// accuracy, but most will match
// @ts-ignore
const distanceInKm = geofire.distanceBetween([lat, lng], center);
const distanceInM = distanceInKm * 1000;
if (distanceInM <= radiusInM) {
Expand Down