-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add initial documentation example for rewrites
- Loading branch information
Showing
6 changed files
with
156 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
dsn: memory | ||
|
||
namespaces: | ||
location: file://./namespaces.keto.ts | ||
|
||
log: | ||
level: trace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/// <reference no-default-lib="true"/> | ||
|
||
type Context = { subject: never } | ||
|
||
interface Namespace { | ||
related?: { [relation: string]: Namespace[] } | ||
permits?: { [method: string]: (ctx: Context) => boolean } | ||
} | ||
|
||
interface Array<Namespace> { | ||
includes(element: Namespace): boolean | ||
traverse(iteratorfn: (element: Namespace) => boolean): boolean | ||
} | ||
|
||
type SubjectSet< | ||
A extends Namespace, | ||
R extends keyof A["related"], | ||
> = A["related"][R] extends Array<infer T> ? T : never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// <reference path="./lib.ts" /> | ||
|
||
class User implements Namespace { | ||
related: { | ||
manager: User[] | ||
} | ||
} | ||
|
||
class Group implements Namespace { | ||
related: { | ||
members: (User | Group)[] | ||
} | ||
} | ||
|
||
class Folder implements Namespace { | ||
related: { | ||
parents: (File | Folder)[] | ||
viewers: SubjectSet<Group, "members">[] | ||
} | ||
|
||
permits = { | ||
view: (ctx: Context): boolean => | ||
this.related.viewers.includes(ctx.subject) || | ||
this.related.parents.traverse((p) => p.permits.view(ctx)), | ||
} | ||
} | ||
|
||
class File implements Namespace { | ||
related: { | ||
parents: (File | Folder)[] | ||
viewers: (User | SubjectSet<Group, "members">)[] | ||
owners: (User | SubjectSet<Group, "members">)[] | ||
} | ||
|
||
// Some comment | ||
permits = { | ||
view: (ctx: Context): boolean => | ||
this.related.parents.traverse((p) => p.permits.view(ctx)) || | ||
this.related.viewers.includes(ctx.subject) || | ||
this.related.owners.includes(ctx.subject), | ||
|
||
edit: (ctx: Context) => this.related.owners.includes(ctx.subject), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
[ | ||
{ | ||
"namespace": "Group", | ||
"object": "developer", | ||
"relation": "members", | ||
"subject_id": "patrik" | ||
}, | ||
{ | ||
"namespace": "Group", | ||
"object": "developer", | ||
"relation": "members", | ||
"subject_set": { | ||
"namespace": "User", | ||
"object": "Patrik" | ||
} | ||
}, | ||
{ | ||
"namespace": "Group", | ||
"object": "developer", | ||
"relation": "members", | ||
"subject_set": { | ||
"namespace": "User", | ||
"object": "Henning" | ||
} | ||
}, | ||
{ | ||
"namespace": "Folder", | ||
"object": "keto/", | ||
"relation": "viewers", | ||
"subject_set": { | ||
"namespace": "Group", | ||
"object": "developer", | ||
"relation": "members" | ||
} | ||
}, | ||
{ | ||
"namespace": "File", | ||
"object": "keto/README.md", | ||
"relation": "parents", | ||
"subject_set": { | ||
"namespace": "Folder", | ||
"object": "keto/" | ||
} | ||
}, | ||
{ | ||
"namespace": "Folder", | ||
"object": "keto/src/", | ||
"relation": "parents", | ||
"subject_set": { | ||
"namespace": "Folder", | ||
"object": "keto/" | ||
} | ||
}, | ||
{ | ||
"namespace": "File", | ||
"object": "keto/src/main.go", | ||
"relation": "parents", | ||
"subject_set": { | ||
"namespace": "Folder", | ||
"object": "keto/src/" | ||
} | ||
}, | ||
{ | ||
"namespace": "File", | ||
"object": "private", | ||
"relation": "owners", | ||
"subject_set": { | ||
"namespace": "User", | ||
"object": "Henning" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters