Skip to content

Commit

Permalink
docs: adds JSDoc to the npm package '@ory/keto-namespace-types' (#1136)
Browse files Browse the repository at this point in the history
Co-authored-by: Patrik <zepatrik@users.noreply.github.com>
  • Loading branch information
nidomiro and zepatrik committed Nov 17, 2022
1 parent a2a3912 commit b582375
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions contrib/namespace-type-lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,41 @@ declare interface IArguments {}
declare interface RegExp {}

declare interface Array<T extends namespace> {
/**
* Checks whether the elements of this Array have a Relation to the given Subject
* @example
* class File implements Namespace {
* related: {
* owners: (User | SubjectSet<Group, "members">)[]
* }
*
* permits = {
* edit: (ctx: Context) => this.related.owners.includes(ctx.subject),
* }
* }
* @param element usually `ctx.subject`
*/
includes(element: T): boolean

/**
* Executes the {@link iteratorfn} on every element in the Array and evaluates to true if {@link iteratorfn} returns true for any element.
*
* @example
* class File implements Namespace {
* related: {
* parents: (File | Folder)[]
* }
*
* permits = {
* view: (ctx: Context): boolean =>
* // Checks whether the given context (e.g. subject) has view permissions on any of the parents,
* // effectively inhertiting the view permissions of the parents
* this.related.parents.traverse((p) => p.permits.view(ctx))
* }
* }
*
* @param iteratorfn The function that checks if a connection exits
*/
traverse(iteratorfn: (element: T) => boolean): boolean
}

Expand All @@ -21,7 +55,14 @@ interface context {
}

interface namespace {
/**
* Possible Relations to Objects of Namespaces
*/
related?: { [relation: string]: namespace[] }

/**
* Dynamically computed Relations
*/
permits?: { [method: string]: (ctx: context) => boolean }
}

Expand Down

0 comments on commit b582375

Please sign in to comment.