generated from fission-codes/project-template
-
Notifications
You must be signed in to change notification settings - Fork 24
/
types.ts
170 lines (125 loc) · 4.91 KB
/
types.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import type { CID } from "multiformats/cid"
import * as Path from "../path/index.js"
import { Maybe } from "../common/index.js"
import { PutResult } from "../components/depot/implementation.js"
import { DirectoryPath, DistinctivePath, FilePath, Partitioned, PartitionedNonEmpty, Partition } from "../path/index.js"
import { Ucan } from "../ucan/types.js"
// 💾 TOP LEVEL
// ------------
export type API = Persistence & Properties & Posix & Sharing
export interface Persistence {
historyStep(): Promise<void>
publish(): Promise<CID>
}
export interface Properties {
account: AssociatedIdentity
}
export interface Posix {
exists(path: DistinctivePath<PartitionedNonEmpty<Partition>>): Promise<boolean>
get(path: DistinctivePath<Partitioned<Partition>>): Promise<PuttableUnixTree | File | null>
mv(from: DistinctivePath<PartitionedNonEmpty<Partition>>, to: DistinctivePath<PartitionedNonEmpty<Partition>>): Promise<this>
rm(path: DistinctivePath<PartitionedNonEmpty<Partition>>): Promise<this>
resolveSymlink(link: SoftLink): Promise<File | Tree | null>
symlink(args: {
at: DirectoryPath<PartitionedNonEmpty<Partition>>
referringTo: {
path: Path.Distinctive<Partitioned<Partition>>
username?: string
}
name: string
}): Promise<this>
// Directories
ls(path: DirectoryPath<Partitioned<Partition>>): Promise<Links>
mkdir(path: DirectoryPath<PartitionedNonEmpty<Partition>>, options?: MutationOptions): Promise<this>
// Files
write(
path: DistinctivePath<PartitionedNonEmpty<Partition>>,
content: Uint8Array | SoftLink | SoftLink[] | Record<string, SoftLink>,
options?: MutationOptions
): Promise<this>
read(path: FilePath<PartitionedNonEmpty<Partition>>): Promise<Uint8Array | null>
}
export interface Sharing {
acceptShare({ shareId, sharedBy }: { shareId: string; sharedBy: string }): Promise<this>
loadShare({ shareId, sharedBy }: { shareId: string; sharedBy: string }): Promise<UnixTree>
sharePrivate(paths: DistinctivePath<Path.PartitionedNonEmpty<Path.Private>>[], { sharedBy, shareWith }: { sharedBy?: SharedBy; shareWith: string | string[] }): Promise<ShareDetails>
}
// FILE
// -----
export interface File extends Puttable {
content: Uint8Array
updateContent(content: Uint8Array): Promise<this>
}
// LINKS
// -----
export interface SimpleLink {
name: string
size: number
cid: CID | string
}
export interface BaseLink {
name: string
size: number
isFile: boolean
}
export interface SoftLink {
ipns: string
name: string
key?: string
privateName?: string
}
export interface HardLink extends SimpleLink, BaseLink { }
export type Link = HardLink | SoftLink | BaseLink
export interface SimpleLinks { [ name: string ]: SimpleLink }
export interface BaseLinks { [ name: string ]: BaseLink }
export interface HardLinks { [ name: string ]: HardLink }
export interface Links { [ name: string ]: Link }
// MISC
// ----
export type AssociatedIdentity = {
rootDID: string
username?: string
}
export type NonEmptyPath = [ string, ...string[] ]
export interface Puttable {
put(): Promise<CID>
putDetailed(): Promise<PutResult>
}
export type UpdateCallback = () => Promise<unknown>
export type PublishHook = (result: CID, proof: Ucan) => unknown
export type SharedBy = { rootDid: string; username: string }
export type ShareDetails = { shareId: string; sharedBy: SharedBy }
export type PuttableUnixTree = UnixTree & Puttable
// OPTIONS
// -------
export type MutationOptions = {
publish?: boolean
}
// TREE
// ----
export interface UnixTree {
readOnly: boolean
ls(path: Path.Segments): Promise<Links>
mkdir(path: Path.Segments): Promise<this>
cat(path: Path.Segments): Promise<Uint8Array>
add(path: Path.Segments, content: Uint8Array): Promise<this>
rm(path: Path.Segments): Promise<this>
mv(from: Path.Segments, to: Path.Segments): Promise<this>
get(path: Path.Segments): Promise<PuttableUnixTree | File | null>
exists(path: Path.Segments): Promise<boolean>
}
export interface Tree extends UnixTree, Puttable {
createChildTree(name: string, onUpdate: Maybe<UpdateCallback>): Promise<Tree>
createOrUpdateChildFile(content: Uint8Array, name: string, onUpdate: Maybe<UpdateCallback>): Promise<File>
mkdirRecurse(path: Path.Segments, onUpdate: Maybe<UpdateCallback>): Promise<this>
addRecurse(path: Path.Segments, content: Uint8Array, onUpdate: Maybe<UpdateCallback>): Promise<this>
rmRecurse(path: Path.Segments, onUpdate: Maybe<UpdateCallback>): Promise<this>
updateChild(child: Tree | File, path: Path.Segments): Promise<this>
updateDirectChild(child: Tree | File, name: string, onUpdate: Maybe<UpdateCallback>): Promise<this>
removeDirectChild(name: string): this
get(path: Path.Segments): Promise<Tree | File | null>
getDirectChild(name: string): Promise<Tree | File | null>
getOrCreateDirectChild(name: string, onUpdate: Maybe<UpdateCallback>): Promise<Tree | File>
updateLink(name: string, result: PutResult): this
getLinks(): Links
}