openfga / language

Grammar for the OpenFGA modeling language
https://openfga.dev
Apache License 2.0
18 stars 7 forks source link

feat: First cut of autocompletion suggestions #57

Closed d-jeffery closed 1 year ago

d-jeffery commented 1 year ago

Description

Visitor visits each typeName, relationName and builds up a collection of potentialy matching symbols.

model
  schema 1.1
type user
type team
  relations
    define member: [user,team#member]
type repo
  relations
    define admin: [user,team#member] or repo_admin from owner
    define maintainer: [user,team#member] or admin
    define owner: [organization]
    define reader: [user,team#member] or triager or repo_reader from owner
    define triager: [user,team#member] or writer
    define writer: [user,team#member] or maintainer or repo_writer from owner
type organization
  relations
    define member: [user] or owner
    define owner: [user]
    define repo_admin: [user,organization#member]
    define repo_reader: [user,organization#member]
    define repo_writer: [user,organization#member]

Returns;

{
  "literals": Set {
    "model",
    "schema",
    "type",
    "relations",
    "define",
  },
  "operators": Set {
    "and",
    "or",
    "but not",
    "from",
  },
  "restrictions": Set {
    "user",
    "user:*",
    "team",
    "team:*",
    "team#member",
    "repo",
    "repo:*",
    "repo#admin",
    "repo#maintainer",
    "repo#owner",
    "repo#reader",
    "repo#triager",
    "repo#writer",
    "organization",
    "organization:*",
    "organization#member",
    "organization#owner",
    "organization#repo_admin",
    "organization#repo_reader",
    "organization#repo_writer",
  },
  "typeNames": {
    "organization": Set {
      "member",
      "owner",
      "repo_admin",
      "repo_reader",
      "repo_writer",
    },
    "repo": Set {
      "admin",
      "maintainer",
      "owner",
      "reader",
      "triager",
      "writer",
    },
    "team": Set {
      "member",
    },
    "user": Set {},
  },
}

This could be built into the validation call to save time, or kept separate and only invoked after a successful validation.

Additional work needs to be done to make type restrictions contextual. Currently every restriction is added a sset.

References

Review Checklist