DataRules class final

The rules, schemas, composite indexes and write roles of a project's collections.

Annotations

Constructors

DataRules({Map<String, DataRule> collections = const {}, Map<String, CollectionSchema> schemas = const {}, Map<String, Set<String>> indexes = const {}, Map<String, String> roles = const {}, Map<String, List<String>> ownerFields = const {}, Map<String, String> expiry = const {}})
const

Properties

collections → Map<String, DataRule>
Top-level collection → rule; unlisted collections are DataRule.app.
final
expiry → Map<String, String>
Top-level collection → the field holding each document's expiry time (ISO-8601 UTC text, as the SDK writes dates; neverExpires when it doesn't expire). App users never read a document past it (the rules allow up to 10 minutes for device clocks), and they can't read a document without it. Queries filter field > now, which the SDK adds; a scheduled function deletes documents a week past their expiry.
final
hashCode → int
The hash code for this object.
no setteroverride
indexes → Map<String, Set<String>>
Collection name → keys of the composite indexes it has (field:asc,other:desc).
final
ownerFields → Map<String, List<String>>
Collection name → the fields the owner of a document may change in a DataRule.ownerRead collection (e.g. [read, readAt]). Never ownerField, audienceField or the expiry field. Empty: the owner changes nothing.
final
roles → Map<String, String>
Collection name → the role a user needs to write it (DataRule.roleWrite).
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
schemas → Map<String, CollectionSchema>
Collection name → its fields.
final

Methods

expiryFieldFor(String path) → String?
The expiry field of the documents under path (set on its top-level collection, like the rule), or null when they don't expire.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
ownerFieldsFor(String path) → List<String>
The fields an owner may change in the documents under path.
readyIndexesFor(String path) → Set<String>
The composite indexes ready for the collection path names.
ruleFor(String path) → DataRule
The rule for documents under path.
schemaFor(String path) → CollectionSchema?
The schema of the collection path names, else of its top collection.
toJson() → Json
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
override

Static Methods

audienceOf(String uid, {String? role, bool signedIn = false}) → List<String>
What a reader matches in audienceField: everyone, the user, their role when known, and signed-in users when signedIn. A reader whose role is unknown leaves it out (the rules accept a subset).
collectionName(String path) → String?
The collection path names: its last collection (tasks for users/u1/tasks). ${...} counts as one segment.
fromJson(Object? json) → DataRules
roleAudience(String role) → String
In audienceField: the users with role.
topCollection(String path) → String
The top-level collection of path, which rules are set on.
userAudience(String uid) → String
In audienceField: the user uid.

Constants

audienceField → const String
The list field of an DataRule.audience document: who reads it.
everyone → const String
In audienceField: everyone using the app, signed in or not.
neverExpires → const String
An expiry value that never comes: documents of an expiring collection carry it when they don't expire.
ownerField → const String
The field holding the uid of the user who owns a document.
signedInUsers → const String
In audienceField: every signed-in (not anonymous) user.