diff --git a/app_dart/lib/src/model/firestore/account.dart b/app_dart/lib/src/model/firestore/account.dart index 50d82b6a3a..db39ad7223 100644 --- a/app_dart/lib/src/model/firestore/account.dart +++ b/app_dart/lib/src/model/firestore/account.dart @@ -59,5 +59,5 @@ final class Account extends AppDocument { Account.fromDocument(super.document); /// Email address of the account. - String get email => p.posix.basename(name!); + String get email => p.posix.basename(documentName!); } diff --git a/app_dart/lib/src/model/firestore/base.dart b/app_dart/lib/src/model/firestore/base.dart index 95eca98982..30e20ca1c9 100644 --- a/app_dart/lib/src/model/firestore/base.dart +++ b/app_dart/lib/src/model/firestore/base.dart @@ -98,7 +98,7 @@ final class AppDocumentMetadata> { abstract class AppDocument> implements g.Document { AppDocument([g.Document? from]) : _fields = from?.fields ?? {}, - name = from?.name, + documentName = from?.name, createTime = from?.createTime, updateTime = from?.updateTime; @@ -116,7 +116,21 @@ abstract class AppDocument> implements g.Document { final Map _fields; @override - String? name; + String? get name { + throw UnsupportedError( + 'Accessing name is not allowed. Use documentName instead.', + ); + } + + @override + set name(String? value) { + throw UnsupportedError( + 'Setting name is not allowed. Use documentName instead.', + ); + } + + /// The name of the document corresponding to `name` in [g.Document]. + String? documentName; @override String? updateTime; @@ -130,7 +144,7 @@ abstract class AppDocument> implements g.Document { return { 'fields': fields, if (createTime != null) 'createTime': createTime!, - if (name != null) 'name': name!, + if (documentName != null) 'documentName': documentName!, if (updateTime != null) 'updateTime': updateTime!, }; } diff --git a/app_dart/lib/src/model/firestore/ci_staging.dart b/app_dart/lib/src/model/firestore/ci_staging.dart index 323d98d6d5..7e99821ab3 100644 --- a/app_dart/lib/src/model/firestore/ci_staging.dart +++ b/app_dart/lib/src/model/firestore/ci_staging.dart @@ -114,7 +114,7 @@ final class CiStaging extends AppDocument { /// Create [CiStaging] from a Commit Document. CiStaging.fromDocument(Document other) { this - ..name = other.name + ..documentName = other.name ..fields = {...?other.fields} ..createTime = other.createTime ..updateTime = other.updateTime; @@ -128,7 +128,7 @@ final class CiStaging extends AppDocument { } // Read it from the document name. - final [owner, repo, _, _] = p.posix.basename(name!).split('_'); + final [owner, repo, _, _] = p.posix.basename(documentName!).split('_'); return RepositorySlug(owner, repo); } @@ -140,7 +140,7 @@ final class CiStaging extends AppDocument { } // Read it from the document name. - final [_, _, sha, _] = p.posix.basename(name!).split('_'); + final [_, _, sha, _] = p.posix.basename(documentName!).split('_'); return sha; } @@ -152,7 +152,7 @@ final class CiStaging extends AppDocument { } // Read it from the document name. - final [_, _, _, stageName] = p.posix.basename(name!).split('_'); + final [_, _, _, stageName] = p.posix.basename(documentName!).split('_'); return CiStage.values.firstWhereOrNull((e) => e.name == stageName); } diff --git a/app_dart/lib/src/model/firestore/commit.dart b/app_dart/lib/src/model/firestore/commit.dart index 7030cd9880..af1d2c2d6e 100644 --- a/app_dart/lib/src/model/firestore/commit.dart +++ b/app_dart/lib/src/model/firestore/commit.dart @@ -73,7 +73,7 @@ final class Commit extends AppDocument { final documentName = p.join(kDatabase, 'documents', collectionId, sha); try { final document = await firestore.getDocument(documentName); - return Commit._(document.fields!, name: document.name!); + return Commit._(document.fields!, documentName: document.name!); } on DetailedApiRequestError catch (e) { if (e.status == HttpStatus.notFound) { return null; @@ -99,7 +99,7 @@ final class Commit extends AppDocument { fieldMessage: message.toValue(), fieldRepositoryPath: repositoryPath.toValue(), fieldSha: sha.toValue(), - }, name: p.posix.join(kDatabase, 'documents', collectionId, sha)); + }, documentName: p.posix.join(kDatabase, 'documents', collectionId, sha)); } /// Creates a Cocoon commit from a Github-authored [commit] on a [branch]. @@ -133,13 +133,13 @@ final class Commit extends AppDocument { } factory Commit.fromDocument(Document document) { - return Commit._(document.fields!, name: document.name!); + return Commit._(document.fields!, documentName: document.name!); } - Commit._(Map fields, {required String name}) { + Commit._(Map fields, {required String documentName}) { this ..fields = fields - ..name = name; + ..documentName = documentName; } /// The timestamp (in milliseconds since the Epoch) of when the commit diff --git a/app_dart/lib/src/model/firestore/github_build_status.dart b/app_dart/lib/src/model/firestore/github_build_status.dart index 1dd39ac9c1..22dfa7f027 100644 --- a/app_dart/lib/src/model/firestore/github_build_status.dart +++ b/app_dart/lib/src/model/firestore/github_build_status.dart @@ -85,7 +85,7 @@ final class GithubBuildStatus extends AppDocument { /// Create [GithubBuildStatus] from a GithubBuildStatus Document. GithubBuildStatus.fromDocument(Document other) { this - ..name = other.name + ..documentName = other.name ..fields = {...?other.fields} ..createTime = other.createTime ..updateTime = other.updateTime; diff --git a/app_dart/lib/src/model/firestore/pr_check_runs.dart b/app_dart/lib/src/model/firestore/pr_check_runs.dart index 51379f2d77..eea654f567 100644 --- a/app_dart/lib/src/model/firestore/pr_check_runs.dart +++ b/app_dart/lib/src/model/firestore/pr_check_runs.dart @@ -53,7 +53,7 @@ final class PrCheckRuns extends AppDocument { static PrCheckRuns fromDocument(Document prCheckRunsDoc) { return PrCheckRuns() ..fields = prCheckRunsDoc.fields! - ..name = prCheckRunsDoc.name!; + ..documentName = prCheckRunsDoc.name!; } /// The json string of the pullrequest belonging to this document. diff --git a/app_dart/lib/src/model/firestore/task.dart b/app_dart/lib/src/model/firestore/task.dart index 736533aef4..898a1e0e3c 100644 --- a/app_dart/lib/src/model/firestore/task.dart +++ b/app_dart/lib/src/model/firestore/task.dart @@ -178,7 +178,7 @@ final class Task extends AppDocument { fieldTestFlaky: testFlaky.toValue(), fieldAttempt: currentAttempt.toValue(), }, - name: p.posix.join( + documentName: p.posix.join( kDatabase, 'documents', kTaskCollectionId, @@ -189,7 +189,7 @@ final class Task extends AppDocument { /// Create [Task] from a task Document. factory Task.fromDocument(Document document) { - return Task._(document.fields!, name: document.name!); + return Task._(document.fields!, documentName: document.name!); } factory Task.initialFromTarget(Target target, {required fs.Commit commit}) { @@ -207,10 +207,10 @@ final class Task extends AppDocument { ); } - Task._(Map fields, {required String name}) { + Task._(Map fields, {required String documentName}) { this ..fields = fields - ..name = name; + ..documentName = documentName; } /// Returns a Firestore [Write] that patches the [status] field for [id]. @@ -336,7 +336,7 @@ final class Task extends AppDocument { } // Read the attempts from the document name. - final documentId = p.basename(name!); + final documentId = p.basename(documentName!); return TaskId.parse(documentId).currentAttempt; } @@ -404,7 +404,7 @@ final class Task extends AppDocument { void resetAsRetry({int? attempt, DateTime? now}) { attempt ??= currentAttempt + 1; - name = p.posix.join( + documentName = p.posix.join( kDatabase, 'documents', kTaskCollectionId, diff --git a/app_dart/test/model/firestore/commit_test.dart b/app_dart/test/model/firestore/commit_test.dart index c2b05ff1af..8752d77d39 100644 --- a/app_dart/test/model/firestore/commit_test.dart +++ b/app_dart/test/model/firestore/commit_test.dart @@ -26,7 +26,7 @@ void main() { firestoreService, sha: storedCommit.sha, ); - expect(resultedCommit.name, storedCommit.name); + expect(resultedCommit.documentName, storedCommit.documentName); expect(resultedCommit.fields, storedCommit.fields); }); } diff --git a/app_dart/test/model/firestore/github_build_status_test.dart b/app_dart/test/model/firestore/github_build_status_test.dart index 2a6bf267d5..44e4a65296 100644 --- a/app_dart/test/model/firestore/github_build_status_test.dart +++ b/app_dart/test/model/firestore/github_build_status_test.dart @@ -24,9 +24,12 @@ void main() { final resultedGithubBuildStatus = await GithubBuildStatus.fromFirestore( firestoreService: firestoreService, - documentName: githubBuildStatus.name!, + documentName: githubBuildStatus.documentName!, + ); + expect( + resultedGithubBuildStatus.documentName, + githubBuildStatus.documentName, ); - expect(resultedGithubBuildStatus.name, githubBuildStatus.name); expect(resultedGithubBuildStatus.fields, githubBuildStatus.fields); }); } diff --git a/app_dart/test/model/firestore/github_gold_status_test.dart b/app_dart/test/model/firestore/github_gold_status_test.dart index 48c3fb3863..80afd6b76e 100644 --- a/app_dart/test/model/firestore/github_gold_status_test.dart +++ b/app_dart/test/model/firestore/github_gold_status_test.dart @@ -24,9 +24,12 @@ void main() { final resultedGithubGoldStatus = await GithubGoldStatus.fromFirestore( firestoreService: firestoreService, - documentName: githubGoldStatus.name!, + documentName: githubGoldStatus.documentName!, + ); + expect( + resultedGithubGoldStatus.documentName, + githubGoldStatus.documentName, ); - expect(resultedGithubGoldStatus.name, githubGoldStatus.name); expect(resultedGithubGoldStatus.fields, githubGoldStatus.fields); }); } diff --git a/app_dart/test/model/firestore/task_test.dart b/app_dart/test/model/firestore/task_test.dart index 5caa0a25e0..d6bab6db99 100644 --- a/app_dart/test/model/firestore/task_test.dart +++ b/app_dart/test/model/firestore/task_test.dart @@ -86,7 +86,7 @@ void main() { firestoreService, TaskId(commitSha: 'abc123', taskName: 'test', currentAttempt: 1), ); - expect(resultedTask.name, firestoreTask.name); + expect(resultedTask.documentName, firestoreTask.documentName); expect(resultedTask.fields, firestoreTask.fields); }); }); @@ -100,7 +100,7 @@ void main() { ); task.resetAsRetry(); - expect(int.parse(task.name!.split('_').last), 2); + expect(int.parse(task.documentName!.split('_').last), 2); expect(task.status, Task.statusNew); expect(task.testFlaky, false); });