UNPKG

1.46 kBPlain TextView Raw
1import * as pathing from '../path'
2import { DirectoryPath, DistinctivePath } from '../path'
3import { Potency, Resource } from "../ucan/index"
4
5export type Permissions = {
6 app?: AppInfo
7 fs?: FileSystemPermissions
8 platform?: PlatformPermissions
9 raw?: RawPermissions
10}
11
12export type AppInfo = {
13 name: string
14 creator: string
15}
16
17export type FileSystemPermissions = {
18 private?: Array<DistinctivePath>
19 public?: Array<DistinctivePath>
20}
21
22export type PlatformPermissions = {
23 apps: '*' | Array<string>
24}
25
26export type RawPermissions = Array<RawPermission>
27
28export type RawPermission = {
29 exp: number
30 rsc: Resource
31 ptc: Potency
32}
33
34
35/**
36 * Path for `AppInfo`.
37 */
38export function appDataPath(app: AppInfo): DirectoryPath {
39 return pathing.directory(pathing.Branch.Private, "Apps", app.creator, app.name)
40}
41
42
43/**
44 * Lists the filesystems paths for a set of `Permissions`.
45 * This'll return a list of `DistinctivePath`s.
46 */
47export function paths(permissions: Permissions): DistinctivePath[] {
48 let list = [] as DistinctivePath[]
49
50 if (permissions.app) list.push(appDataPath(permissions.app))
51 if (permissions.fs?.private) list = list.concat(
52 permissions.fs?.private.map(p => pathing.combine(
53 pathing.directory(pathing.Branch.Private),
54 p
55 ))
56 )
57 if (permissions.fs?.public) list = list.concat(
58 permissions.fs?.public.map(p => pathing.combine(
59 pathing.directory(pathing.Branch.Public),
60 p
61 ))
62 )
63
64 return list
65}