Skip to content

Commit

Permalink
add pathGetId
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Nov 21, 2023
1 parent abbf995 commit e65e672
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion firestore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion firestore/lib/firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 3 additions & 0 deletions firestore/lib/src/firestore_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion firestore/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: tekartik_firebase_firestore
description: Firebase firestore core
version: 1.1.3
version: 1.1.4
publish_to: none

environment:
Expand Down
7 changes: 7 additions & 0 deletions firestore/test/firestore_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(''), '');
});
});
}

0 comments on commit e65e672

Please sign in to comment.