Skip to content

Commit

Permalink
add metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Jun 22, 2022
1 parent 5f4ee54 commit 411a86a
Showing 1 changed file with 42 additions and 11 deletions.
53 changes: 42 additions & 11 deletions docs/namespace_config_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The configuration language has the following keywords:
* `type`
* `this`
* `ctx`
* `id`

### Operators

Expand All @@ -78,6 +79,7 @@ The following character sequences represent miscelanious operators:
| `=>` | `view(ctx) => foo(ctx)` | Function definition token. In the example, `view` is true if `foo` is true |
| `.` | `this.x` | Property traversal token |
| `:` | `relation: type` | Relation/type separator token |
| `=` | `id = 123` | Metadata assignment token |

## Statements

Expand All @@ -88,19 +90,19 @@ each namespace. Each `type` consists of relation declarations and permission
declarations.

```ebnf
TypeDecl = "type" identifier "{" [ TypeSpec ] "}" .
TypeDecl = "type" identifier "(" Metadata ")" "{" [ TypeSpec ] "}" .
Metadata = "id" "=" digit .
TypeSpec = { RelationDecl | PermissionDefn } .
```


#### Example

The following declares a type *user* that is never the object in any
relation. It can, however, be the subject of a relation, the relation being
declared on some other type.

```typescript
type user {}
type user(id = 123) {}
```
### Relation declaration
Expand All @@ -119,9 +121,9 @@ The following declares a type *document* has three relations: *owners* and
*viewers*, both of which have *users* as subjects. Additionally, the relation
*parent* has type *file*.
```typescript
type file {}
type file(id=2) {}

type document {
type document(id = 31) {
parent: file
owners: user[]
viewers: user[]
Expand Down Expand Up @@ -193,8 +195,8 @@ flowchart LR
subgraph TypeSpec
direction LR
A2(" ") --> RelationDecl
A2(" ") --> PermissionDefn
A2{" "} --> RelationDecl
A2 --> PermissionDefn
PermissionDefn --> X2(((" ")))
RelationDecl --> X2(((" ")))
end
Expand All @@ -214,9 +216,9 @@ flowchart LR
## Examples

```typescript
type user {}
type user(id=1) {}

type file {
type file(id=2) {
parent: file
viewers: user[]
owners: user[]
Expand All @@ -232,9 +234,9 @@ type file {
### Alternative set membership syntax:
```typescript
type user {}
type user(id=1) {}

type file {
type file(id=2) {
parent: file
viewers: user[]
owners: user[]
Expand All @@ -245,4 +247,33 @@ type file {
edit(ctx) => this.owners.contains(ctx.subject)
rename(ctx) => this.siblings.exists(sibling, sibling.edit(ctx))
}
```
### Alternative full TypeScript syntax
```typescript
class user {
static id = 1
}

class file {
static id = 2

parent: file
viewers: user[]
owners: user[]
siblings: file[]

isViewer = (ctx) => this.viewers.contains(ctx.subject)
view = (ctx) =>
this.viewers.contains(ctx.subject) ||
this.owners.contains(ctx.subject) ||
this.parent.view(ctx)

edit = (ctx) =>
this.owners.contains(ctx.subject)

rename = (ctx) =>
this.siblings.exists(sibling, sibling.edit(ctx))
}
```

0 comments on commit 411a86a

Please sign in to comment.