Parse error when dealing with
capt-pyro opened this issue · 4 comments
Im running pragma v0.3.2. I ran the entire tutorial including the data validation and transformation part. I ran into a parse error when performing the validation part.
The full code I ran is attached below (not including the js files)
import "./functions.js" as fns { runtime = "nodejs:14" }
import "./transformers.js" as transformers { runtime = "nodejs:14" }
import "./validators.js" as validators { runtime = "nodejs:14" }
config { projectName = "basic_todo_app" }
@user
@1 model User {
@1 username: String @publicCredential @primary
@2 password: String @secretCredential
@3 todos: [Todo]
}
@2 model Todo {
@1 id: String @uuid @primary
@2 title: String
@3 content: String
@4 status: TodoStatus = "TODO"
}
enum TodoStatus {
DONE
INPROGRESS
TODO
}
allow CREATE User
role User {
allow MUTATE self.todos
allow [READ, UPDATE, DELETE] self
allow UPDATE Todo if fns.selfOwnsTodo
}
@onWrite(validators.validateBook)
@1 model Book {
@1 id: String @uuid @primary
@2 title: String
@2 authors: [String]
}
@onRead(transformers.transformBook)
@1 model Book {
@1 id: String @uuid @primary
@2 title: String
@2 authors: [String]
}
Thanks for opening the issue! This is a matter of outdated documentation. Directive syntax was changed so that arguments cannot be positional (they must be named).
I've just updated the docs to fix the parser errors, but the fix is:
@onWrite(function: validators.validateBook)
Same goes for @onRead
.
thanks. Would it be possible for the parser to identify an unnamed argument and point that out?
Ohh and as a quick note in the docs, you've used the @2 index twice for both title and authors for both validation and transformation.
import "./validators.js" as validators { runtime = "nodejs:14" }
@onWrite(function: validators.validateBook)
@1 model Book {
@1 id: String @uuid @primary
@2 title: String
@2 authors: [String]
}
Oh wow. We need to automate the testing of examples.
Would it be possible for the parser to identify an unnamed argument and point that out?
Yes. In fact, there should be a rewrite of the entire parsing/validation layer down the line. It's a bit far down that line though.
I'll fix the index error immediately. Thank you so much for telling us about them!