From 411a86a20ea4ee36042c3db3b9796afd89104b5b Mon Sep 17 00:00:00 2001 From: hperl <34397+hperl@users.noreply.github.com> Date: Tue, 21 Jun 2022 16:30:28 +0200 Subject: [PATCH] add metadata --- docs/namespace_config_spec.md | 53 +++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/docs/namespace_config_spec.md b/docs/namespace_config_spec.md index 423bb9209..28fec198d 100644 --- a/docs/namespace_config_spec.md +++ b/docs/namespace_config_spec.md @@ -56,6 +56,7 @@ The configuration language has the following keywords: * `type` * `this` * `ctx` +* `id` ### Operators @@ -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 @@ -88,11 +90,11 @@ 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 @@ -100,7 +102,7 @@ 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 @@ -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[] @@ -193,8 +195,8 @@ flowchart LR subgraph TypeSpec direction LR - A2(" ") --> RelationDecl - A2(" ") --> PermissionDefn + A2{" "} --> RelationDecl + A2 --> PermissionDefn PermissionDefn --> X2(((" "))) RelationDecl --> X2(((" "))) end @@ -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[] @@ -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[] @@ -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)) +} ``` \ No newline at end of file