1 | import * as pathing from '../path'
|
2 | import { DirectoryPath, DistinctivePath } from '../path'
|
3 | import { Potency, Resource } from "../ucan/index"
|
4 |
|
5 | export type Permissions = {
|
6 | app?: AppInfo
|
7 | fs?: FileSystemPermissions
|
8 | platform?: PlatformPermissions
|
9 | raw?: RawPermissions
|
10 | }
|
11 |
|
12 | export type AppInfo = {
|
13 | name: string
|
14 | creator: string
|
15 | }
|
16 |
|
17 | export type FileSystemPermissions = {
|
18 | private?: Array<DistinctivePath>
|
19 | public?: Array<DistinctivePath>
|
20 | }
|
21 |
|
22 | export type PlatformPermissions = {
|
23 | apps: '*' | Array<string>
|
24 | }
|
25 |
|
26 | export type RawPermissions = Array<RawPermission>
|
27 |
|
28 | export type RawPermission = {
|
29 | exp: number
|
30 | rsc: Resource
|
31 | ptc: Potency
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | export function appDataPath(app: AppInfo): DirectoryPath {
|
39 | return pathing.directory(pathing.Branch.Private, "Apps", app.creator, app.name)
|
40 | }
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | export 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 | }
|