-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathindex.d.ts
76 lines (66 loc) · 2.01 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
/// <reference no-default-lib="true"/>
declare interface Boolean {}
declare interface String {}
declare interface Number {}
declare interface Function {}
declare interface Object {}
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
}
interface context {
subject: never
}
interface namespace {
/**
* Possible Relations to Objects of Namespaces
*/
related?: { [relation: string]: namespace[] }
/**
* Dynamically computed Relations
*/
permits?: { [method: string]: (ctx: context) => boolean }
}
declare module "@ory/keto-namespace-types" {
export type Context = context
export type Namespace = namespace
export type SubjectSet<A extends Namespace, R extends keyof A["related"]> =
A["related"][R] extends Array<infer T> ? T : never
}