Skip to content

Instantly share code, notes, and snippets.

@katowulf
Created May 18, 2020 15:27
Show Gist options
  • Save katowulf/36196c88e0d5593c2021d8b5950c73af to your computer and use it in GitHub Desktop.
Save katowulf/36196c88e0d5593c2021d8b5950c73af to your computer and use it in GitHub Desktop.

Revisions

  1. Kato Richardson renamed this gist May 18, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. Kato Richardson created this gist May 18, 2020.
    21 changes: 21 additions & 0 deletions example_validate_rules.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    {
    "aListOfRecords": {
    // when querying our list, must get less than 50 at a time and be authenticated
    ".read": "auth != null && (query.limitToFirst <= 50 || query.limitToLast <= 50)",

    "$aRecordId": {
    // When fetching a single record, I must be logged in
    ".read": "auth != null",

    // When writing a record, I must be logged in
    ".write": "auth != null",

    // Validate my schema
    "aNumberField": { ".validate": "newData.isNumber() && newData.val() > -1 && newData.val() < 51" },
    "aStringField": { ".validate": "newData.isString() && newData.val().length < 4" }

    // Disallow any fields not in my schema
    "$other": { ".validate": false }
    }
    }
    }