Feature Request: Be able to reference map keys in validation rules
See original GitHub issueI’m having trouble with a DB structure that looks like this:
{
"post-flag": {
"-KvXU5eiR4oZM-vBihib": {
"6t5KEJjAOSYbf8dleabDlTyxhux2": 1507542071604,
"6t5KEJjAOSYbf8dleabDlTyxhux3": 1507542071605
}
}
}
I’d like to validate that the data is valid and that the keys follow a certain format.
I’ve tried several variations of the following, but none of them really work.
path /post-flag is Map<PushID, Map<UserID, UnixTimestamp>>;
path /post-flag/{post}/{user} is UnixTimestamp {
write() {
return isCurrentUser(user) && root.post[post] != null
}
}
type PushID extends String {
validate() { return this.test(/^[-_0-9a-zA-Z]{20}$/); }
}
type UserID extends String {
validate() { return this.test(/^[0-9a-zA-Z]{27}[0-9]$/); }
}
type UnixTimestamp extends Number {
validate() { return this >= 0; }
}
For the example above I get the following JSON:
{
"rules": {
"post-flag": {
"$key1": {
".validate": "newData.hasChildren() && $key1.matches(/^[-_0-9a-zA-Z]{20}$/)",
"$key2": {
".validate": "$key2.matches(/^[0-9a-zA-Z]{27}[0-9]$/) && newData.isNumber() && newData.val() >= 0"
}
},
".validate": "newData.hasChildren()",
"$post": {
"$user": {
".validate": "newData.isNumber() && newData.val() >= 0",
".write": "auth != null && auth.uid == $user && newData.parent().parent().parent().child('post').child($post).val() != null"
}
}
}
}
}
Which yields the following error in Firebase simulator:
Cannot have multiple default rules (‘$key1’ and ‘$post’).
I’m not sure if I’m writing my rules wrongly or if this is a limitation of Bolt.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Validation Rules - Salesforce Help
Validation rules verify that the data a user enters in a record meets the standards you specify before the user can save the...
Read more >How to Use Validation Rules in Salesforce (+ Examples)
Validation Rules in Salesforce verify that the data entered by a user meets certain criteria before the user can save the record.
Read more >Enable request validation in API Gateway - AWS Documentation
To enable basic validation, you specify validation rules in a request validator, add the validator to the API's map of request validators, and...
Read more >GitHub - bufbuild/protoc-gen-validate
This plugin adds support to protoc-generated code to validate such constraints. ... map fields with message values, setting this rule to true disallows...
Read more >Error Messages | Maps JavaScript API - Google Developers
The API key included in the script element that loads the API is not found. Please make sure you are using a correct...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll have a go at it. 😄
Currently there is not, but feel free to open a PR 😄