generated from fission-codes/project-template
-
Notifications
You must be signed in to change notification settings - Fork 24
/
permissions.ts
82 lines (60 loc) · 1.55 KB
/
permissions.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
77
78
79
80
81
82
import * as Path from "./path/index.js"
import { AppInfo } from "./appInfo.js"
import { Distinctive } from "./path/index.js"
import { Potency, Resource } from "./ucan/index.js"
// 🏔
export const ROOT_FILESYSTEM_PERMISSIONS = {
fs: {
private: [ Path.root() ],
public: [ Path.root() ]
}
}
// 🧩
export type Permissions = {
app?: AppInfo
fs?: FileSystemPermissions
platform?: PlatformPermissions
raw?: RawPermissions
sharing?: boolean
}
export type FileSystemPermissions = {
private?: Array<Distinctive<Path.Segments>>
public?: Array<Distinctive<Path.Segments>>
}
export type PlatformPermissions = {
apps: "*" | Array<string>
}
export type RawPermissions = Array<RawPermission>
export type RawPermission = {
exp: number
rsc: Resource
ptc: Potency
}
// 🛠
/**
* App identifier.
*/
export function appId(app: AppInfo): string {
return `${app.creator}/${app.name}`
}
/**
* Lists the filesystems paths for a set of `Permissions`.
* This'll return a list of `DistinctivePath`s.
*/
export function permissionPaths(permissions: Permissions): Distinctive<Path.Partitioned<Path.Partition>>[] {
let list = [] as Distinctive<Path.Partitioned<Path.Partition>>[]
if (permissions.app) list.push(Path.appData(permissions.app))
if (permissions.fs?.private) list = list.concat(
permissions.fs?.private.map(p => Path.withPartition(
"private",
p
))
)
if (permissions.fs?.public) list = list.concat(
permissions.fs?.public.map(p => Path.withPartition(
"public",
p
))
)
return list
}