Skip to content

Commit 8a8a400

Browse files
committed
Add typescript typings
1 parent 40bf0bf commit 8a8a400

File tree

1 file changed

+288
-0
lines changed

1 file changed

+288
-0
lines changed

index.d.ts

Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
declare module '@isomorphic-git/lightning-fs' {
2+
export class PromisifiedFS {
3+
/**
4+
*
5+
* @param name This is used to determine the IndexedDb store name.
6+
* @param options The "filesystem" configuration.
7+
*/
8+
init(name: string, options?: FS.Options): void
9+
10+
/**
11+
* Make directory
12+
* @param filepath
13+
* @param options
14+
*/
15+
mkdir(filepath: string, options: FS.MKDirOptions | undefined): Promise<never>
16+
17+
/**
18+
* Remove directory
19+
* @param filepath
20+
* @param options
21+
*/
22+
rmdir(filepath: string, options: undefined): Promise<never>
23+
24+
/**
25+
* Read directory
26+
*
27+
* The Promise return value is an Array of strings. NOTE: To save time, it is NOT SORTED. (Fun fact: Node.js' readdir output is not guaranteed to be sorted either. I learned that the hard way.)
28+
* @param filepath
29+
* @param options
30+
* @returns The file list.
31+
*/
32+
readdir(filepath: string, options: undefined): Promise<string[]>
33+
34+
writeFile(filepath: string, data: Uint8Array | string, options: FS.WriteFileOptions | undefined | string): Promise<never>
35+
36+
readFile(filepath: string, options: FS.ReadFileOptions | undefined | string): Promise<Uint8Array>
37+
38+
/**
39+
* Delete a file
40+
* @param filepath
41+
* @param options
42+
*/
43+
unlink(filepath: string, options: undefined): Promise<never>
44+
45+
/**
46+
* Rename a file or directory
47+
* @param oldFilepath
48+
* @param newFilepath
49+
*/
50+
rename(oldFilepath: string, newFilepath: string): Promise<never>
51+
52+
/**
53+
* The result is a Stat object similar to the one used by Node but with fewer and slightly different properties and methods.
54+
* @param filepath
55+
* @param options
56+
*/
57+
stat(filepath: string, options: undefined): Promise<FS.Stats>
58+
59+
/**
60+
* Like fs.stat except that paths to symlinks return the symlink stats not the file stats of the symlink's target.
61+
* @param filepath
62+
* @param options
63+
*/
64+
lstat(filepath: string, options: undefined): Promise<FS.Stats>
65+
66+
/**
67+
* Create a symlink at filepath that points to target.
68+
* @param target
69+
* @param filepath
70+
*/
71+
symlink(target: string, filepath: string): Promise<never>
72+
73+
/**
74+
* Read the target of a symlink.
75+
* @param filepath
76+
* @param options
77+
* @returns The link string.
78+
*/
79+
readlink(filepath: string, options: undefined): Promise<string>
80+
81+
/**
82+
* Create or change the stat data for a file backed by HTTP. Size is fetched with a HEAD request. Useful when using an HTTP backend without urlauto set, as then files will only be readable if they have stat data. Note that stat data is made automatically from the file /.superblock.txt if found on the server. /.superblock.txt can be generated or updated with the included [standalone script](https://github.com/isomorphic-git/lightning-fs/blob/main/src/superblocktxt.js).
83+
* @param filepath
84+
* @param options
85+
*/
86+
backFile(filepath: string, options: FS.BackFileOptions | undefined): Promise<never>
87+
88+
/**
89+
* @param filepath
90+
* @returns The size of a file or directory in bytes.
91+
*/
92+
du(filepath: string): Promise<number>
93+
}
94+
export class FS {
95+
/**
96+
* You can procrastinate initializing the FS object until later. And, if you're really adventurous, you can re-initialize it with a different name to switch between IndexedDb databases.
97+
*/
98+
constructor()
99+
/**
100+
* First, create or open a "filesystem".
101+
* @param name This is used to determine the IndexedDb store name.
102+
* @param options The "filesystem" configuration.
103+
*/
104+
constructor(name: string, options?: FS.Options)
105+
106+
/**
107+
*
108+
* @param name This is used to determine the IndexedDb store name.
109+
* @param options The "filesystem" configuration.
110+
*/
111+
init(name: string, options?: FS.Options): void
112+
113+
/**
114+
* Make directory
115+
* @param filepath
116+
* @param options
117+
* @param cb
118+
*/
119+
mkdir(filepath: string, options: FS.MKDirOptions | undefined, cb: (err: Error) => void): void
120+
121+
/**
122+
* Remove directory
123+
* @param filepath
124+
* @param options
125+
* @param cb
126+
*/
127+
rmdir(filepath: string, options: undefined, cb: (err: Error) => void): void
128+
129+
/**
130+
* Read directory
131+
*
132+
* The callback return value is an Array of strings. NOTE: To save time, it is NOT SORTED. (Fun fact: Node.js' readdir output is not guaranteed to be sorted either. I learned that the hard way.)
133+
* @param filepath
134+
* @param options
135+
* @param cb
136+
*/
137+
readdir(filepath: string, options: undefined, cb: (err: Error, files: string[]) => void): void
138+
139+
writeFile(filepath: string, data: Uint8Array | string, options: FS.WriteFileOptions | undefined | string, cb: (err: Error) => void): void
140+
141+
readFile(filepath: string, options: FS.ReadFileOptions | undefined | string, cb: (err: Error, data: Uint8Array | string) => void): void
142+
143+
/**
144+
* Delete a file
145+
* @param filepath
146+
* @param options
147+
* @param cb
148+
*/
149+
unlink(filepath: string, options: undefined, cb: (err: Error) => void): void
150+
151+
/**
152+
* Rename a file or directory
153+
* @param oldFilepath
154+
* @param newFilepath
155+
* @param cb
156+
*/
157+
rename(oldFilepath: string, newFilepath: string, cb: (err: Error) => void): void
158+
159+
/**
160+
* The result is a Stat object similar to the one used by Node but with fewer and slightly different properties and methods.
161+
* @param filepath
162+
* @param options
163+
* @param cb
164+
*/
165+
stat(filepath: string, options: undefined, cb: (err: Error, stats: FS.Stats) => void): void
166+
167+
/**
168+
* Like fs.stat except that paths to symlinks return the symlink stats not the file stats of the symlink's target.
169+
* @param filepath
170+
* @param options
171+
* @param cb
172+
*/
173+
lstat(filepath: string, options: undefined, cb: (err: Error, stats: FS.Stats) => void): void
174+
175+
/**
176+
* Create a symlink at filepath that points to target.
177+
* @param target
178+
* @param filepath
179+
* @param cb
180+
*/
181+
symlink(target: string, filepath: string, cb: (err: Error) => void): void
182+
183+
/**
184+
* Read the target of a symlink.
185+
* @param filepath
186+
* @param options
187+
* @param cb
188+
*/
189+
readlink(filepath: string, options: undefined, cb: (err: Error, linkString: string) => void): void
190+
191+
/**
192+
* Create or change the stat data for a file backed by HTTP. Size is fetched with a HEAD request. Useful when using an HTTP backend without urlauto set, as then files will only be readable if they have stat data. Note that stat data is made automatically from the file /.superblock.txt if found on the server. /.superblock.txt can be generated or updated with the included [standalone script](https://github.com/isomorphic-git/lightning-fs/blob/main/src/superblocktxt.js).
193+
* @param filepath
194+
* @param options
195+
* @param cb
196+
*/
197+
backFile(filepath: string, options: FS.BackFileOptions | undefined, cb: (err: Error) => void): void
198+
199+
/**
200+
* Returns the size of a file or directory in bytes.
201+
* @param filepath
202+
* @param cb
203+
*/
204+
du(filepath: string, cb: (err: Error, size: number) => void): void
205+
}
206+
namespace FS {
207+
export interface Options {
208+
/**
209+
* Delete the database and start with an empty filesystem
210+
* @default false
211+
*/
212+
wipe?: boolean
213+
/**
214+
* Let readFile requests fall back to an HTTP request to this base URL
215+
* @default false
216+
*/
217+
url?: string
218+
/**
219+
* Fall back to HTTP for every read of a missing file, even if unbacked
220+
* @default false
221+
*/
222+
urlauto?: boolean
223+
/**
224+
* Customize the database name
225+
*/
226+
fileDbName?: string
227+
/**
228+
* Customize the store name
229+
*/
230+
fileStoreName?: string
231+
/**
232+
* Customize the database name for the lock mutex
233+
*/
234+
lockDbName?: string
235+
/**
236+
* Customize the store name for the lock mutex
237+
*/
238+
lockStoreName?: string
239+
/**
240+
* If true, avoids mutex contention during initialization
241+
* @default false
242+
*/
243+
defer?: boolean
244+
245+
readonly promises: PromisifiedFS
246+
}
247+
export interface MKDirOptions {
248+
/**
249+
* Posix mode permissions
250+
* @default 0o777
251+
*/
252+
mode: number
253+
}
254+
export interface WriteFileOptions {
255+
/**
256+
* Posix mode permissions
257+
* @default 0o777
258+
*/
259+
mode: number
260+
encoding?: 'utf8'
261+
}
262+
export interface ReadFileOptions {
263+
encoding?: 'utf8'
264+
}
265+
export interface Stats {
266+
type: 'file' | 'dir'
267+
mode: any
268+
size: number
269+
ino: any
270+
mtimeMs: any
271+
ctimeMs: any
272+
uid: 1
273+
gid: 1
274+
dev: 1
275+
isFile(): boolean
276+
isDirectory(): boolean
277+
isSymbolicLink(): boolean
278+
}
279+
export interface BackFileOptions {
280+
/**
281+
* Posix mode permissions
282+
* @default 0o666
283+
*/
284+
mode: number
285+
}
286+
}
287+
export default FS
288+
}

0 commit comments

Comments
 (0)