great-crayon-86888
11/21/2023, 1:02 PMchilly-king-10285
11/21/2023, 1:02 PMchilly-king-10285
11/21/2023, 1:03 PMtypescript import { Namespace, Context } from "@ory/keto-namespace-types" class User implements Namespace {} class Document implements Namespace { related: { owners: User[] editors: User[] viewers: User[] parents: Folder[] } permits = { view: (ctx: Context): boolean => this.related.viewers.includes(ctx.subject) || this.related.editors.includes(ctx.subject) || this.related.owners.includes(ctx.subject) || this.related.parents.traverse((parent) => parent.permits.view(ctx)), } } class Folder implements Namespace { related: { owners: User[] editors: User[] viewers: User[] parents: Folder[] } }
In this example, User
, Document
, and Folder
are declared as namespaces (which can be considered as objects). Relationships are defined inside the corresponding class, and permissions are expressed as TypeScript functions that take a context containing the subject and answer permission checks based on the relationships the object has to the subject. For more detailed information and examples, you may want to refer to the [Ory Keto documentation](https://www.ory.sh/docs/keto).