pheekus / svarog Goto Github PK
View Code? Open in Web Editor NEWGenerate Cloud Firestore helper functions for schema validation using JSON Schema.
License: MIT License
Generate Cloud Firestore helper functions for schema validation using JSON Schema.
License: MIT License
Hi 👋🏻
First, I want to say thank you for putting this library together, it's already proved super useful to me, and makes me sleep better at night 🙏🏻
I've recently been running into what I think might be a limitation of svarog though, and wanted to check if it was one indeed, or if there simply was an issue between the chair and the keyboard.
It seems that array of objects definitions ignore the required
properties. I've looked into the currently described limitations, but couldn't figure out if it was the expected behavior in the current state of the tool.
For instance, validating:
{
"stuffed": [
{
"foo": "hello, I'm Pierrot le foo"
}
]
}
with the following schema
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "Stuff",
"type": "object",
"properties": {
"stuffed": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"foo": {
"type": "string"
},
"bar": {
"type": "string"
}
},
"required": [
"foo",
"bar"
]
}
}
},
In the context of this security rules
match /stuff/{stuffID} {
allow create: if isValid("Stuff");
I would expect the isValid("Stuff")
call to fail, and the security rules making the document creation also fail as a result, because bar
was not present. It is the behavior shown by external JSON Schema validators. Is it Svarog's expected behavior? Is it a known limitation? How can I contribute to make this behavior supported if that's the case?
Cheers!
Support for Timestamp, Bytes, LatLng and Path is currently missing. v1 must have at least basic support for these types using the following syntax:
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "FirestoreTypes",
"type": "object",
"definitions": {
"Timestamp": {},
"Bytes": {},
"LatLng": {},
"Path": {}
},
"properties": {
"date": { "$ref": "#/definitions/Timestamp" },
"bytes": { "$ref": "#/definitions/Bytes" },
"location": { "$ref": "#/definitions/LatLng" },
"document": { "$ref": "#/definitions/Path" }
}
}
Compiler could look for $ref
in property declaration and add basic type checking based on the provided value. This way only refs defined as shown above would work, but that'd be enough until a better approach is found.
Docs would need to be updated for this as well.
Looks like request.resource.data
now includes all document fields on update, even if only a subset of them was passed to the update function (see the screenshot below: the request doesn't include visibility field, but it's there anyway). So it's kind of like getAfter()
now, but right in the request
.
No need to check if the field is present in the resource anymore => smaller svarog snippet => more space for custom rules.
Accessing unexistent object.key
throws Property key is undefined on object.
in Firestore. Such assertions are a part of loose checks that Svarog applies on update
operation.
As it turns out, simply running tsc -b
is not enough in the CircleCI environment to build the project, and I can't figure out why. To make things worse, everything works fine locally.
Here's what happening: running npm run build
on CircleCI, which executes tsc -p tsconfig.json
, outputs a single package.json file in the /lib
folder. No errors or warnings, just the empty output. tsc -b
gives the same result. Searching for similar issues didn't help much.
Until this is resolved, the workaround is to clone the repo and npm link
it for global usage.
master
branch failed. 🚨I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.
You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.
Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.
Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master
branch. You can also manually restart the failed CI job that runs semantic-release.
If you are not sure how to resolve this, here is some links that can help you:
If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.
The npm token configured in the NPM_TOKEN
environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/
.
If you are using Two-Factor Authentication, make configure the auth-only
level is supported. semantic-release cannot publish with the default auth-and-writes
level.
Please make sure to set the NPM_TOKEN
environment variable in your CI with the exact value of the npm token.
Good luck with your project ✨
Your semantic-release bot 📦🚀
This proposal introduces a new Svarog API for Security Rules. At the moment, when we want to validate the resource, we use the following function call format:
match /posts/{postId} {
allow create: if isPostValid(request.resource.data, true);
allow update: if isPostValid(request.resource.data, false);
}
This is fine as long as we don't need to perform additional assertions, where condition expression quickly becomes cluttered:
match /posts/{postId} {
allow create: if
isPostValid(request.resource.data, true) &&
isSomeOtherConditionMet() &&
isEveryoneOkayWithThis() &&
isItEvenAppropriateToProposeThatKindOfChange();
}
Since request.resource.data
as well as request.method
are both available globally, we can create a wrapper function that would pass them internally for us:
function isValid(schema) {
return
(schema == "Post" && isPostValid(request.resource.data, request.method == 'create')) ||
(schema == "Task" && isTaskValid(request.resource.data, request.method == 'create'));
}
Also, to make the output code a bit less verbose, there could be a proxy function that would shorten the parameters:
function isValid(schema) {
return _isValid(schema, request.resource.data, request.method == 'create');
}
function _isValid(n, d, s) {
return (n == "Post" && isPostValid(d, s)) || (n == "Task" && isTaskValid(d, s));
}
Finally, to make using arbitrary $id
possible, we could replace meaningful function names with minified identifiers like s1
, s2
etc. since they are supposed to be internal anyway:
function isValid(n){return svv(n,request.resource.data,(request.method=="create"))}
function sv(n,d,s){return ((n=="Post")&&s0(d, s))||((n=="Task")&&s1(d,s))}
New syntax after this issue is closed:
match /posts/{postId} {
allow write: if isValid("Post");
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.