-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port expiration compiler changes into composableschemadsl #2240
Conversation
96f054c
to
74cb714
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment
{ | ||
"expiration trait", | ||
`use expiration | ||
|
||
definition document{ | ||
relation viewer: user with expiration | ||
relation editor: user with somecaveat and expiration | ||
}`, | ||
`use expiration | ||
|
||
definition document { | ||
relation viewer: user with expiration | ||
relation editor: user with somecaveat and expiration | ||
}`, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this does not port in the expiration caveat tests, as we treat expiration
as a reserved keyword in composable schema and treat it only as a trait.
c192152
to
22e351c
Compare
22e351c
to
de11d99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
@@ -111,11 +129,12 @@ func Compile(schema InputSchema, prefix ObjectPrefixOption, opts ...Option) (*Co | |||
return nil, err | |||
} | |||
|
|||
compiled, err := translate(translationContext{ | |||
compiled, err := translate(&translationContext{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making this a reference allows us to mutate the enabledFlags
field, which allows us to detect duplicate use
directives.
{ | ||
"duplicate use pragmas", | ||
withTenantPrefix, | ||
` | ||
use expiration | ||
use expiration | ||
|
||
definition simple { | ||
relation viewer: user with expiration | ||
}`, | ||
`found duplicate use flag`, | ||
[]SchemaDefinition{}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a net-new test. We also excluded the relation with expiration caveat
test from this set, since we want to reserve expiration
under the new composable schema syntax.
case dslshape.NodeTypeUseFlag: | ||
err := translateUseFlag(tctx, topLevelNode) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Translating the use
flag is basically only for detecting duplicate flags. All of the handling/usage is down at the lexer and parser level.
if !slices.Contains(tctx.enabledFlags, "expiration") { | ||
return nil, typeRefNode.Errorf("expiration flag is not enabled; add `use expiration` to top of file") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also net new.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a direct port.
// NOTE: a duplicate use statement should be an error at the level | ||
// of the compiler, but should not be an error at the level | ||
// of the parser. | ||
{"duplicate use statement test", "duplicate_use_statement"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a parsing test to verify that multiple use statements get parsed correctly. This was mostly a debugging tool in doing this work, but also describes desired behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is asserting that duplicate use statements pass parsing. The error states happen in the compiler.
end-rune = 37 | ||
error-message = `use` expressions must be declared before any definition | ||
input-source = use after definition | ||
start-rune = 38 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding more context to this parsing error.
Is it an issue that the start rune is after the end rune?
@@ -107,7 +107,7 @@ func Compile(schema InputSchema, prefix ObjectPrefixOption, opts ...Option) (*Co | |||
return nil, err | |||
} | |||
|
|||
compiled, err := translate(translationContext{ | |||
compiled, err := translate(&translationContext{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making the same changes to schemadsl to support erroring on duplicate use
expressions.
@@ -1,28 +1,28 @@ | |||
package lexer | |||
|
|||
// FlaggableLexler wraps a lexer, automatically translating tokens based on flags, if any. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same typo changes
de11d99
to
a708397
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Part of getting expiration support into composable schema.
Changes
Testing
Review. See that things are green.