diff --git a/firestore/README.md b/firestore/README.md index 9b14383..edaa7e2 100644 --- a/firestore/README.md +++ b/firestore/README.md @@ -7,7 +7,7 @@ dependencies: url: https://github.com/tekartik/firebase_firestore.dart path: firestore ref: dart3a - version: '>=0.8.0' + version: '>=1.1.4' ``` ## Utilities: diff --git a/firestore/lib/firestore.dart b/firestore/lib/firestore.dart index 8e4ce34..1689dab 100644 --- a/firestore/lib/firestore.dart +++ b/firestore/lib/firestore.dart @@ -20,7 +20,8 @@ export 'package:tekartik_firebase_firestore/src/firestore_path.dart' firestoreDocPathGetParent, firestorePathGetChild, firestorePathGetGenericPath, - firestorePathReplaceId; + firestorePathReplaceId, + firestorePathGetId; export 'package:tekartik_firebase_firestore/src/timestamp.dart' show Timestamp; export 'src/document_reference.dart' diff --git a/firestore/lib/src/firestore_path.dart b/firestore/lib/src/firestore_path.dart index 991a34c..42fc3dd 100644 --- a/firestore/lib/src/firestore_path.dart +++ b/firestore/lib/src/firestore_path.dart @@ -15,6 +15,9 @@ String? firestoreCollPathGetParent(String path) => getParentPathOrNull(path); String firestorePathGetChild(String path, String child) => url.join(path, child); +/// Id from path +String firestorePathGetId(String path) => url.basename(path); + /// Replace last path segment String firestorePathReplaceId(String path, String id) { var parent = firestorePathGetParent(path); diff --git a/firestore/pubspec.yaml b/firestore/pubspec.yaml index 16b45c8..1104a14 100644 --- a/firestore/pubspec.yaml +++ b/firestore/pubspec.yaml @@ -1,6 +1,6 @@ name: tekartik_firebase_firestore description: Firebase firestore core -version: 1.1.3 +version: 1.1.4 publish_to: none environment: diff --git a/firestore/test/firestore_test.dart b/firestore/test/firestore_test.dart index 5bca9a1..edeba8a 100644 --- a/firestore/test/firestore_test.dart +++ b/firestore/test/firestore_test.dart @@ -250,11 +250,18 @@ void main() { expect(firestorePathGetGenericPath('a'), 'a'); expect(firestorePathGetGenericPath('a/1'), 'a/*'); expect(firestorePathGetGenericPath('a/1/b/2'), 'a/*/b/*'); + expect(firestorePathGetGenericPath(''), ''); expect(firestorePathGetChild('a', 'b'), 'a/b'); expect(firestorePathReplaceId('a/b', 'c'), 'a/c'); expect(firestorePathReplaceId('a/b/c', 'd'), 'a/b/d'); expect(firestorePathReplaceId('a', 'b'), 'b'); + expect(firestorePathReplaceId('', 'b'), 'b'); + + expect(firestorePathGetId('a/b/c'), 'c'); + expect(firestorePathGetId('a/b'), 'b'); + expect(firestorePathGetId('a'), 'a'); + expect(firestorePathGetId(''), ''); }); }); }