Skip to content

Commit fdb81ad

Browse files
committed
Merge branch 'master' of github.com:firebase/firebase-js-sdk into markduckworth/public-or-queries
2 parents 0ca3c7f + 36558bd commit fdb81ad

File tree

4 files changed

+255
-1
lines changed

4 files changed

+255
-1
lines changed

.changeset/heavy-starfishes-count.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@firebase/firestore-compat": feat
3+
"@firebase/firestore": feat
4+
---
5+
6+
Relaxing query validation performed by the SDK

.changeset/perfect-colts-scream.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/database-compat": patch
3+
---
4+
5+
Solve @firebase/database-compat/standalone resolution issues with astrojs

packages/database-compat/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
},
3131
"./standalone": {
3232
"types": "./dist/database-compat/src/index.standalone.d.ts",
33-
"node": "./dist/index.standalone.js"
33+
"node": "./dist/index.standalone.js",
34+
"default": "./dist/index.standalone.js"
3435
},
3536
"./package.json": "./package.json"
3637
},

packages/firestore/test/integration/api/query.test.ts

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,248 @@ apiDescribe('Queries', (persistence: boolean) => {
18531853
);
18541854
});
18551855
});
1856+
1857+
// eslint-disable-next-line no-restricted-properties
1858+
it('supports multiple in ops', () => {
1859+
const testDocs = {
1860+
doc1: { a: 1, b: 0 },
1861+
doc2: { b: 1 },
1862+
doc3: { a: 3, b: 2 },
1863+
doc4: { a: 1, b: 3 },
1864+
doc5: { a: 1 },
1865+
doc6: { a: 2 }
1866+
};
1867+
1868+
return withTestCollection(persistence, testDocs, async coll => {
1869+
// Two IN operations on different fields with disjunction.
1870+
await checkOnlineAndOfflineResultsMatch(
1871+
query(
1872+
coll,
1873+
or(where('a', 'in', [2, 3]), where('b', 'in', [0, 2])),
1874+
orderBy('a')
1875+
),
1876+
'doc1',
1877+
'doc6',
1878+
'doc3'
1879+
);
1880+
1881+
// Two IN operations on different fields with conjunction.
1882+
await checkOnlineAndOfflineResultsMatch(
1883+
query(
1884+
coll,
1885+
and(where('a', 'in', [2, 3]), where('b', 'in', [0, 2])),
1886+
orderBy('a')
1887+
),
1888+
'doc3'
1889+
);
1890+
1891+
// Two IN operations on the same field.
1892+
// a IN [1,2,3] && a IN [0,1,4] should result in "a==1".
1893+
await checkOnlineAndOfflineResultsMatch(
1894+
query(
1895+
coll,
1896+
and(where('a', 'in', [1, 2, 3]), where('a', 'in', [0, 1, 4]))
1897+
),
1898+
'doc1',
1899+
'doc4',
1900+
'doc5'
1901+
);
1902+
1903+
// a IN [2,3] && a IN [0,1,4] is never true and so the result should be an
1904+
// empty set.
1905+
await checkOnlineAndOfflineResultsMatch(
1906+
query(
1907+
coll,
1908+
and(where('a', 'in', [2, 3]), where('a', 'in', [0, 1, 4]))
1909+
)
1910+
);
1911+
1912+
// a IN [0,3] || a IN [0,2] should union them (similar to: a IN [0,2,3]).
1913+
await checkOnlineAndOfflineResultsMatch(
1914+
query(coll, or(where('a', 'in', [0, 3]), where('a', 'in', [0, 2]))),
1915+
'doc3',
1916+
'doc6'
1917+
);
1918+
1919+
// Nested composite filter on the same field.
1920+
await checkOnlineAndOfflineResultsMatch(
1921+
query(
1922+
coll,
1923+
and(
1924+
where('a', 'in', [1, 3]),
1925+
or(
1926+
where('a', 'in', [0, 2]),
1927+
and(where('b', '>=', 1), where('a', 'in', [1, 3]))
1928+
)
1929+
)
1930+
),
1931+
'doc3',
1932+
'doc4'
1933+
);
1934+
1935+
// Nested composite filter on the different fields.
1936+
await checkOnlineAndOfflineResultsMatch(
1937+
query(
1938+
coll,
1939+
and(
1940+
where('b', 'in', [0, 3]),
1941+
or(
1942+
where('b', 'in', [1]),
1943+
and(where('b', 'in', [2, 3]), where('a', 'in', [1, 3]))
1944+
)
1945+
)
1946+
),
1947+
'doc4'
1948+
);
1949+
});
1950+
});
1951+
1952+
// eslint-disable-next-line no-restricted-properties
1953+
it('supports using in with array contains any', () => {
1954+
const testDocs = {
1955+
doc1: { a: 1, b: [0] },
1956+
doc2: { b: [1] },
1957+
doc3: { a: 3, b: [2, 7], c: 10 },
1958+
doc4: { a: 1, b: [3, 7] },
1959+
doc5: { a: 1 },
1960+
doc6: { a: 2, c: 20 }
1961+
};
1962+
1963+
return withTestCollection(persistence, testDocs, async coll => {
1964+
await checkOnlineAndOfflineResultsMatch(
1965+
query(
1966+
coll,
1967+
or(
1968+
where('a', 'in', [2, 3]),
1969+
where('b', 'array-contains-any', [0, 7])
1970+
)
1971+
),
1972+
'doc1',
1973+
'doc3',
1974+
'doc4',
1975+
'doc6'
1976+
);
1977+
1978+
await checkOnlineAndOfflineResultsMatch(
1979+
query(
1980+
coll,
1981+
and(
1982+
where('a', 'in', [2, 3]),
1983+
where('b', 'array-contains-any', [0, 7])
1984+
)
1985+
),
1986+
'doc3'
1987+
);
1988+
1989+
await checkOnlineAndOfflineResultsMatch(
1990+
query(
1991+
coll,
1992+
or(
1993+
and(where('a', 'in', [2, 3]), where('c', '==', 10)),
1994+
where('b', 'array-contains-any', [0, 7])
1995+
)
1996+
),
1997+
'doc1',
1998+
'doc3',
1999+
'doc4'
2000+
);
2001+
2002+
await checkOnlineAndOfflineResultsMatch(
2003+
query(
2004+
coll,
2005+
and(
2006+
where('a', 'in', [2, 3]),
2007+
or(where('b', 'array-contains-any', [0, 7]), where('c', '==', 20))
2008+
)
2009+
),
2010+
'doc3',
2011+
'doc6'
2012+
);
2013+
});
2014+
});
2015+
2016+
// eslint-disable-next-line no-restricted-properties
2017+
it('supports using in with array contains', () => {
2018+
const testDocs = {
2019+
doc1: { a: 1, b: [0] },
2020+
doc2: { b: [1] },
2021+
doc3: { a: 3, b: [2, 7] },
2022+
doc4: { a: 1, b: [3, 7] },
2023+
doc5: { a: 1 },
2024+
doc6: { a: 2 }
2025+
};
2026+
2027+
return withTestCollection(persistence, testDocs, async coll => {
2028+
await checkOnlineAndOfflineResultsMatch(
2029+
query(
2030+
coll,
2031+
or(where('a', 'in', [2, 3]), where('b', 'array-contains', 3))
2032+
),
2033+
'doc3',
2034+
'doc4',
2035+
'doc6'
2036+
);
2037+
2038+
await checkOnlineAndOfflineResultsMatch(
2039+
query(
2040+
coll,
2041+
and(where('a', 'in', [2, 3]), where('b', 'array-contains', 7))
2042+
),
2043+
'doc3'
2044+
);
2045+
2046+
await checkOnlineAndOfflineResultsMatch(
2047+
query(
2048+
coll,
2049+
or(
2050+
where('a', 'in', [2, 3]),
2051+
and(where('b', 'array-contains', 3), where('a', '==', 1))
2052+
)
2053+
),
2054+
'doc3',
2055+
'doc4',
2056+
'doc6'
2057+
);
2058+
2059+
await checkOnlineAndOfflineResultsMatch(
2060+
query(
2061+
coll,
2062+
and(
2063+
where('a', 'in', [2, 3]),
2064+
or(where('b', 'array-contains', 7), where('a', '==', 1))
2065+
)
2066+
),
2067+
'doc3'
2068+
);
2069+
});
2070+
});
2071+
2072+
// eslint-disable-next-line no-restricted-properties
2073+
it('supports order by equality', () => {
2074+
const testDocs = {
2075+
doc1: { a: 1, b: [0] },
2076+
doc2: { b: [1] },
2077+
doc3: { a: 3, b: [2, 7], c: 10 },
2078+
doc4: { a: 1, b: [3, 7] },
2079+
doc5: { a: 1 },
2080+
doc6: { a: 2, c: 20 }
2081+
};
2082+
2083+
return withTestCollection(persistence, testDocs, async coll => {
2084+
await checkOnlineAndOfflineResultsMatch(
2085+
query(coll, where('a', '==', 1), orderBy('a')),
2086+
'doc1',
2087+
'doc4',
2088+
'doc5'
2089+
);
2090+
2091+
await checkOnlineAndOfflineResultsMatch(
2092+
query(coll, where('a', 'in', [2, 3]), orderBy('a')),
2093+
'doc6',
2094+
'doc3'
2095+
);
2096+
});
2097+
});
18562098
});
18572099

18582100
// Reproduces https://github.com/firebase/firebase-js-sdk/issues/5873

0 commit comments

Comments
 (0)