Skip to content

Commit

Permalink
fix: resolve issue with improperly detecting a valid model as invalid (
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh authored Dec 14, 2023
2 parents 8dfc3b8 + 0a764e6 commit cca4c43
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ on:
- 'pkg/go/**'
- 'OpenFGAParser.g4'
- 'OpenFGALexer.g4'
- 'tests'
pull_request:
paths:
- 'pkg/go/**'
- 'OpenFGAParser.g4'
- 'OpenFGALexer.g4'
- 'tests'

permissions:
contents: read
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/main-js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ on:
- 'pkg/js/**'
- 'OpenFGAParser.g4'
- 'OpenFGALexer.g4'
- 'tests'
pull_request:
paths:
- 'pkg/js/**'
- 'OpenFGAParser.g4'
- 'OpenFGALexer.g4'
- 'tests'

permissions:
contents: read
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ OpenFGA is designed to make it easy for application builders to model their perm
## About This Repo
This repo contains everything needed to interact with the OpenFGA Authorization Models schema versions 1.1+, in multiple languages (currently, Go and JS are supported).

| Feature | Implemented in ANTLR |
|------------|-----------------------------|
| Basic DSL ||
| Nesting | ❌ (planned) |
| Conditions | ❌ (planned) |
| Feature | Implemented in ANTLR |
|------------|----------------------|
| Basic DSL | |
| Nesting | ✅ (partial, see #113 |
| Conditions | |

| Feature | Go | JS |
|-------------------------------------------------------|-------------|-------------|
Expand Down
16 changes: 15 additions & 1 deletion pkg/js/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
# Changelog

## v0.2.0-beta.7

### [v0.2.0-beta.7](https://github.com/openfga/language/releases/tag/vv0.2.0-beta.6...v0.2.0-beta.7) (2023-12-13)

Fixed:
- Issue in validating entrypoint or loop with some models (#120)

## v0.2.0-beta.6

### [v0.2.0-beta.6](https://github.com/openfga/language/releases/tag/vv0.2.0-beta.3...v0.2.0-beta.4) (2023-12-11)
### [v0.2.0-beta.6](https://github.com/openfga/language/releases/tag/vv0.2.0-beta.5...v0.2.0-beta.6) (2023-12-11)

last commit: 8b692a44e937beae8693cc155b205ffc5b732fbe

Added:
- Initial limited support for mixing operators [#107](https://github.com/openfga/language/pull/107)

## v0.2.0-beta.5

### [v0.2.0-beta.5](https://github.com/openfga/language/releases/tag/vv0.2.0-beta.4...v0.2.0-beta.5) (2023-10-04)

Added:
- Initial support for Conditions when transforming from DSL to JSON (https://github.com/openfga/language/pull/75)

## v0.2.0-beta.4

### [v0.2.0-beta.4](https://github.com/openfga/language/releases/tag/vv0.2.0-beta.3...v0.2.0-beta.4) (2023-10-04)
Expand Down
102 changes: 51 additions & 51 deletions pkg/js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pkg/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfga/syntax-transformer",
"version": "0.2.0-beta.6",
"version": "0.2.0-beta.7",
"description": "",
"license": "Apache-2.0",
"main": "./dist/index.js",
Expand Down Expand Up @@ -33,12 +33,12 @@
"antlr4": "^4.13.1"
},
"devDependencies": {
"@openfga/sdk": "^0.3.0-beta.1",
"@openfga/sdk": "^0.3.0",
"@types/jest": "^29.5.11",
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.10.4",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.0",
Expand Down
28 changes: 23 additions & 5 deletions pkg/js/validator/validate-dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function allowableTypes(typeName: Record<string, TypeDefinition>, type: string,
// for the type/relation, whether there are any unique entry points, and if a loop is found
// if there are unique entry points (i.e., direct relations) then it will return true
// otherwise, it will follow its children to see if there are unique entry points
// if there is a loop durig traversal, the function will return a boolean indicating so
// if there is a loop during traversal, the function will return a boolean indicating so
function hasEntryPointOrLoop(
typeMap: Record<string, TypeDefinition>,
typeName: string,
Expand Down Expand Up @@ -221,7 +221,7 @@ function hasEntryPointOrLoop(
return [false, false];
}

if (visited[decodedType][decodedRelation]) {
if (visited[decodedType]?.[decodedRelation]) {
continue;
}

Expand Down Expand Up @@ -276,7 +276,13 @@ function hasEntryPointOrLoop(
continue;
}

const [hasEntry, _] = hasEntryPointOrLoop(typeMap, assignableType, computedRelationName, assignableRelation, visited);
const [hasEntry, _] = hasEntryPointOrLoop(
typeMap,
assignableType,
computedRelationName,
assignableRelation,
visited,
);
if (hasEntry) {
return [true, false];
}
Expand Down Expand Up @@ -306,7 +312,13 @@ function hasEntryPointOrLoop(
} else if (rewrite.difference) {
const visited = deepCopy(visitedRecords);

const [hasEntryBase, loopBase] = hasEntryPointOrLoop(typeMap, typeName, relationName, rewrite.difference.base, visited);
const [hasEntryBase, loopBase] = hasEntryPointOrLoop(
typeMap,
typeName,
relationName,
rewrite.difference.base,
visited,
);
if (!hasEntryBase) {
return [false, loopBase];
}
Expand Down Expand Up @@ -640,7 +652,13 @@ function modelValidation(
// parse through each of the relations to do validation
for (const relationName in typeDef.relations) {
const currentRelation = typeMap[typeName].relations;
const [hasEntry, loop] = hasEntryPointOrLoop(typeMap, typeName, relationName, currentRelation![relationName], {});
const [hasEntry, loop] = hasEntryPointOrLoop(
typeMap,
typeName,
relationName,
currentRelation![relationName],
{},
);
if (!hasEntry) {
const typeIndex = getTypeLineNumber(typeName, lines);
const lineIndex = getRelationLineNumber(relationName, lines, typeIndex);
Expand Down
12 changes: 12 additions & 0 deletions tests/data/dsl-syntax-validation-cases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1392,3 +1392,15 @@
end: 60
metadata:
symbol: "]"

- name: a valid model should not error
dsl: |
model
schema 1.1
type user
type document
relations
define editor: [team#member]
type team
relations
define member: [user]

0 comments on commit cca4c43

Please sign in to comment.