firestore.rules), and developers often implement custom rules alongside type validations, Typesync inserts only the necessary validator functions, without overriding your custom rules. You can specify where these validators are added within the file using the --startMarker and --endMarker options. For a detailed guide, see the full example below.
Note that these validators must adhere to the intrinsic limitations of Security Rules. For example, while it’s
feasible to verify if
x is a list with the x is list predicate, determining whether it’s a list of strings is not
possible since loop constructs are not available in Security Rules. Typesync will provide the most stringent
validation possible within these constraints.Usage
Options
string
required
The exact path or a Glob pattern to the definition file or files. Each definition file must be a YAML or JSON file containing model definitions.
- Example single file path:
definition/models.json - Example Glob pattern:
'definition/**/*.yml'
string
required
The path to the output file.
string
default:"typesync-start"
A marker that indicates the line after which the generated code should be
inserted. Make sure to use a string that is unique within the file. The line
containing the marker must be commented i.e. the marker needs to appear after
the
// (see example).string
default:"typesync-end"
A marker that indicates the line before which the generated code should be inserted. Make sure to use a string that is
unique within the file. The line containing the marker must be commented i.e. the marker needs to appear after the
// (see example).string
default:"isValid{modelName}"
The pattern that specifies how the generated type validators are named. The pattern must be a string that contains the
"{modelName}" substring (this is a literal value).Example values:"isValid{modelName}"-> produces validators likeisValidUser,isValidProject,isValidAccountetc."is{modelName}"-> produces validators likeisUser,isProject,isAccountetc.
string
default:"data"
The name of the parameter taken by each type validator.
int
default:2
Indentation or tab width for the generated code.
boolean
default:false
Whether to enable debug logs.
Example
Suppose you have a schema definition file namedmodels.yml and a Security Rules file named firestore.rules.
typesync-start and typesync-end markers in the firestore.rules file, you can run the following command:
isValidUserRole() and isValidUser() validators into the file. You can then use these validators as needed in your custom rules.
firestore.rules

