Skip to content

Commit

Permalink
feat(compiler): parse roles block of contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
minenwerfer committed Feb 15, 2025
1 parent a459acc commit d95b215
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-bobcats-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aeriajs/compiler": patch
---

Parse `roles` block of contracts
1 change: 1 addition & 0 deletions packages/compiler/src/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const COLLECTION_SEARCH_KEYWORDS = [
] as const

export const CONTRACT_KEYWORDS = [
'roles',
'payload',
'query',
'response',
Expand Down
11 changes: 11 additions & 0 deletions packages/compiler/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,17 @@ export const parse = (tokens: (Token | undefined)[]) => {
while( !match(TokenType.RightBracket) ) {
const { value: keyword } = consume(TokenType.Keyword, lexer.CONTRACT_KEYWORDS)
switch( keyword ) {
case 'roles': {
if( match(TokenType.QuotedString, 'unauthenticated') ) {
node.roles = 'unauthenticated'
} else if( match(TokenType.QuotedString, 'unauthenticated-only') ) {
node.roles = 'unauthenticated-only'
} else {
const { value } = parseArrayBlock()
node.roles = value as UserRole[]
}
break
}
case 'payload': {
node.payload = parsePropertyType({
allowModifiers: true,
Expand Down

0 comments on commit d95b215

Please sign in to comment.