@react-native-firebase/firestore 16.5.0 → 16.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/android/src/reactnative/java/io/invertase/firebase/firestore/ReactNativeFirebaseFirestoreQuery.java +13 -4
- package/ios/RNFBFirestore/RNFBFirestoreQuery.m +15 -4
- package/lib/FirestoreDocumentSnapshot.js +9 -3
- package/lib/FirestoreQuery.js +1 -1
- package/lib/FirestoreQueryModifiers.js +13 -7
- package/lib/utils/index.js +4 -4
- package/lib/version.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
### [16.5.1](https://github.com/invertase/react-native-firebase/compare/v16.5.0...v16.5.1) (2023-01-20)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **firestore:** correct handling of nested `FieldPath` in `orderBy` clauses ([#6814](https://github.com/invertase/react-native-firebase/issues/6814)) ([84d7bbe](https://github.com/invertase/react-native-firebase/commit/84d7bbe241241c331b7c540bf089adcf603c199e))
|
|
11
|
+
|
|
6
12
|
## [16.5.0](https://github.com/invertase/react-native-firebase/compare/v16.4.6...v16.5.0) (2022-12-16)
|
|
7
13
|
|
|
8
14
|
**Note:** Version bump only for package @react-native-firebase/firestore
|
|
@@ -127,12 +127,21 @@ public class ReactNativeFirebaseFirestoreQuery {
|
|
|
127
127
|
List<Object> ordersList = toArrayList(orders);
|
|
128
128
|
|
|
129
129
|
for (Object o : ordersList) {
|
|
130
|
-
Map<String,
|
|
130
|
+
Map<String, Object> order = (Map) o;
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
if (order.get("fieldPath") instanceof List) {
|
|
133
|
+
ArrayList fieldPathArray = (ArrayList) order.get("fieldPath");
|
|
134
|
+
String[] segmentArray = (String[]) fieldPathArray.toArray(new String[0]);
|
|
135
|
+
FieldPath fieldPath = FieldPath.of(segmentArray);
|
|
136
|
+
String direction = (String) order.get("direction");
|
|
134
137
|
|
|
135
|
-
|
|
138
|
+
query = query.orderBy(Objects.requireNonNull(fieldPath), Query.Direction.valueOf(direction));
|
|
139
|
+
} else {
|
|
140
|
+
String fieldPath = (String) order.get("fieldPath");
|
|
141
|
+
String direction = (String) order.get("direction");
|
|
142
|
+
|
|
143
|
+
query = query.orderBy(Objects.requireNonNull(fieldPath), Query.Direction.valueOf(direction));
|
|
144
|
+
}
|
|
136
145
|
}
|
|
137
146
|
}
|
|
138
147
|
|
|
@@ -82,11 +82,22 @@
|
|
|
82
82
|
|
|
83
83
|
- (void)applyOrders {
|
|
84
84
|
for (NSDictionary *order in _orders) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
if ([order[@"fieldPath"] isKindOfClass:[NSArray class]]) {
|
|
86
|
+
NSArray *fieldPathArray = order[@"fieldPath"];
|
|
87
|
+
NSString *direction = order[@"direction"];
|
|
88
|
+
bool isDescending = [direction isEqualToString:@"DESCENDING"];
|
|
88
89
|
|
|
89
|
-
|
|
90
|
+
FIRFieldPath *fieldPath = [[FIRFieldPath alloc] initWithFields:fieldPathArray];
|
|
91
|
+
|
|
92
|
+
_query = [_query queryOrderedByFieldPath:fieldPath descending:isDescending];
|
|
93
|
+
|
|
94
|
+
} else {
|
|
95
|
+
NSString *fieldPath = order[@"fieldPath"];
|
|
96
|
+
NSString *direction = order[@"direction"];
|
|
97
|
+
bool isDescending = [direction isEqualToString:@"DESCENDING"];
|
|
98
|
+
|
|
99
|
+
_query = [_query queryOrderedByField:fieldPath descending:isDescending];
|
|
100
|
+
}
|
|
90
101
|
}
|
|
91
102
|
}
|
|
92
103
|
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { isString } from '@react-native-firebase/app/lib/common';
|
|
18
|
+
import { isArray, isString } from '@react-native-firebase/app/lib/common';
|
|
19
19
|
import FirestoreDocumentReference, {
|
|
20
20
|
provideDocumentSnapshotClass,
|
|
21
21
|
} from './FirestoreDocumentReference';
|
|
@@ -78,9 +78,13 @@ export default class FirestoreDocumentSnapshot {
|
|
|
78
78
|
get(fieldPath) {
|
|
79
79
|
// TODO: ehesp: How are SnapshotOptions handled?
|
|
80
80
|
|
|
81
|
-
if (
|
|
81
|
+
if (
|
|
82
|
+
!isString(fieldPath) &&
|
|
83
|
+
!(fieldPath instanceof FirestoreFieldPath) &&
|
|
84
|
+
!Array.isArray(fieldPath)
|
|
85
|
+
) {
|
|
82
86
|
throw new Error(
|
|
83
|
-
"firebase.firestore() DocumentSnapshot.get(*) 'fieldPath' expected type string or FieldPath.",
|
|
87
|
+
"firebase.firestore() DocumentSnapshot.get(*) 'fieldPath' expected type string, array or FieldPath.",
|
|
84
88
|
);
|
|
85
89
|
}
|
|
86
90
|
|
|
@@ -92,6 +96,8 @@ export default class FirestoreDocumentSnapshot {
|
|
|
92
96
|
} catch (e) {
|
|
93
97
|
throw new Error(`firebase.firestore() DocumentSnapshot.get(*) 'fieldPath' ${e.message}.`);
|
|
94
98
|
}
|
|
99
|
+
} else if (isArray(fieldPath)) {
|
|
100
|
+
path = new FirestoreFieldPath(...fieldPath);
|
|
95
101
|
} else {
|
|
96
102
|
// Is already field path
|
|
97
103
|
path = fieldPath;
|
package/lib/FirestoreQuery.js
CHANGED
|
@@ -23,10 +23,10 @@ import {
|
|
|
23
23
|
isUndefined,
|
|
24
24
|
} from '@react-native-firebase/app/lib/common';
|
|
25
25
|
import NativeError from '@react-native-firebase/app/lib/internal/NativeFirebaseError';
|
|
26
|
+
import { FirestoreAggregateQuery } from './FirestoreAggregate';
|
|
26
27
|
import FirestoreDocumentSnapshot from './FirestoreDocumentSnapshot';
|
|
27
28
|
import FirestoreFieldPath, { fromDotSeparatedString } from './FirestoreFieldPath';
|
|
28
29
|
import FirestoreQuerySnapshot from './FirestoreQuerySnapshot';
|
|
29
|
-
import { FirestoreAggregateQuery } from './FirestoreAggregate';
|
|
30
30
|
import { parseSnapshotArgs } from './utils';
|
|
31
31
|
|
|
32
32
|
let _id = 0;
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import { isNumber } from '@react-native-firebase/app/lib/common';
|
|
19
|
+
import FirestoreFieldPath, { DOCUMENT_ID } from './FirestoreFieldPath';
|
|
19
20
|
import { buildNativeArray, generateNativeData } from './utils/serialize';
|
|
20
|
-
import { DOCUMENT_ID } from './FirestoreFieldPath';
|
|
21
21
|
|
|
22
22
|
const OPERATORS = {
|
|
23
23
|
'==': 'EQUAL',
|
|
@@ -74,11 +74,17 @@ export default class FirestoreQueryModifiers {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
get filters() {
|
|
77
|
-
return this._filters.map(f => ({
|
|
77
|
+
return this._filters.map(f => ({
|
|
78
|
+
...f,
|
|
79
|
+
fieldPath: f.fieldPath instanceof FirestoreFieldPath ? f.fieldPath._toArray() : f.fieldPath,
|
|
80
|
+
}));
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
get orders() {
|
|
81
|
-
return this._orders
|
|
84
|
+
return this._orders.map(f => ({
|
|
85
|
+
...f,
|
|
86
|
+
fieldPath: f.fieldPath instanceof FirestoreFieldPath ? f.fieldPath._toArray() : f.fieldPath,
|
|
87
|
+
}));
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
get options() {
|
|
@@ -337,7 +343,7 @@ export default class FirestoreQueryModifiers {
|
|
|
337
343
|
|
|
338
344
|
orderBy(fieldPath, directionStr) {
|
|
339
345
|
const order = {
|
|
340
|
-
fieldPath: fieldPath
|
|
346
|
+
fieldPath: fieldPath,
|
|
341
347
|
direction: directionStr ? DIRECTIONS[directionStr.toLowerCase()] : DIRECTIONS.asc,
|
|
342
348
|
};
|
|
343
349
|
|
|
@@ -348,7 +354,7 @@ export default class FirestoreQueryModifiers {
|
|
|
348
354
|
validateOrderBy() {
|
|
349
355
|
// Ensure order hasn't been called on the same field
|
|
350
356
|
if (this._orders.length > 1) {
|
|
351
|
-
const orders = this._orders.map($ => $.fieldPath);
|
|
357
|
+
const orders = this._orders.map($ => $.fieldPath._toPath());
|
|
352
358
|
const set = new Set(orders);
|
|
353
359
|
|
|
354
360
|
if (set.size !== orders.length) {
|
|
@@ -371,7 +377,7 @@ export default class FirestoreQueryModifiers {
|
|
|
371
377
|
const orderFieldPath = order.fieldPath;
|
|
372
378
|
if (filter.operator === OPERATORS['==']) {
|
|
373
379
|
// Any where() fieldPath parameter cannot match any orderBy() parameter when '==' operand is invoked
|
|
374
|
-
if (filterFieldPath === orderFieldPath) {
|
|
380
|
+
if (filterFieldPath === orderFieldPath._toPath()) {
|
|
375
381
|
throw new Error(
|
|
376
382
|
`Invalid query. Query.orderBy() parameter: ${orderFieldPath} cannot be the same as your Query.where() fieldPath parameter: ${filterFieldPath}`,
|
|
377
383
|
);
|
|
@@ -386,7 +392,7 @@ export default class FirestoreQueryModifiers {
|
|
|
386
392
|
|
|
387
393
|
if (INEQUALITY[filter.operator]) {
|
|
388
394
|
// Initial orderBy() parameter has to match every where() fieldPath parameter when inequality operator is invoked
|
|
389
|
-
if (filterFieldPath !== this._orders[0].fieldPath) {
|
|
395
|
+
if (filterFieldPath !== this._orders[0].fieldPath._toPath()) {
|
|
390
396
|
throw new Error(
|
|
391
397
|
`Invalid query. Initial Query.orderBy() parameter: ${orderFieldPath} has to be the same as the Query.where() fieldPath parameter(s): ${filterFieldPath} when an inequality operator is invoked `,
|
|
392
398
|
);
|
package/lib/utils/index.js
CHANGED
|
@@ -26,18 +26,18 @@ import {
|
|
|
26
26
|
} from '@react-native-firebase/app/lib/common';
|
|
27
27
|
import FirestoreFieldPath, { fromDotSeparatedString } from '../FirestoreFieldPath';
|
|
28
28
|
|
|
29
|
-
export function extractFieldPathData(data,
|
|
29
|
+
export function extractFieldPathData(data, segments) {
|
|
30
30
|
if (!isObject(data)) {
|
|
31
31
|
return undefined;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const pathValue = data[
|
|
34
|
+
const pathValue = data[segments[0]];
|
|
35
35
|
|
|
36
|
-
if (
|
|
36
|
+
if (segments.length === 1) {
|
|
37
37
|
return pathValue;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
return extractFieldPathData(pathValue,
|
|
40
|
+
return extractFieldPathData(pathValue, segments.slice(1));
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function parseUpdateArgs(args) {
|
package/lib/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Generated by genversion.
|
|
2
|
-
module.exports = '16.5.
|
|
2
|
+
module.exports = '16.5.1';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-firebase/firestore",
|
|
3
|
-
"version": "16.5.
|
|
3
|
+
"version": "16.5.1",
|
|
4
4
|
"author": "Invertase <oss@invertase.io> (http://invertase.io)",
|
|
5
5
|
"description": "React Native Firebase - Cloud Firestore is a NoSQL cloud database to store and sync data between your React Native application and Firebase's database. The API matches the Firebase Web SDK whilst taking advantage of the native SDKs performance and offline capabilities.",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"firestore"
|
|
28
28
|
],
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@react-native-firebase/app": "16.5.
|
|
30
|
+
"@react-native-firebase/app": "16.5.1"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "fafaf580f384e8c4b47788adfab0b29ee2cfd5c0"
|
|
36
36
|
}
|