Skip to content

Commit 6f3ae38

Browse files
authored
Merge pull request #51 from raldone01/main
feat: Add typescript typings
2 parents ded7f73 + 7d0e199 commit 6f3ae38

File tree

1 file changed

+303
-0
lines changed

1 file changed

+303
-0
lines changed

index.d.ts

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

0 commit comments

Comments
 (0)