@tinycloud/vfs 0.1.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +910 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +394 -0
- package/dist/index.d.ts +394 -0
- package/dist/index.js +869 -0
- package/dist/index.js.map +1 -0
- package/dist/worker.cjs +611 -0
- package/dist/worker.cjs.map +1 -0
- package/dist/worker.js +609 -0
- package/dist/worker.js.map +1 -0
- package/package.json +41 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
2
|
+
import { VirtualProvider, VirtualFileSystem } from '@platformatic/vfs';
|
|
3
|
+
|
|
4
|
+
interface PortableDelegationLike {
|
|
5
|
+
cid: string;
|
|
6
|
+
delegationHeader: {
|
|
7
|
+
Authorization: string;
|
|
8
|
+
};
|
|
9
|
+
spaceId: string;
|
|
10
|
+
path: string;
|
|
11
|
+
actions: string[];
|
|
12
|
+
expiry: Date;
|
|
13
|
+
delegateDID: string;
|
|
14
|
+
ownerAddress: string;
|
|
15
|
+
chainId: number;
|
|
16
|
+
host?: string;
|
|
17
|
+
disableSubDelegation?: boolean;
|
|
18
|
+
publicDelegation?: PortableDelegationLike;
|
|
19
|
+
}
|
|
20
|
+
interface TinyCloudVfsSessionData {
|
|
21
|
+
delegationHeader: {
|
|
22
|
+
Authorization: string;
|
|
23
|
+
};
|
|
24
|
+
delegationCid: string;
|
|
25
|
+
spaceId: string;
|
|
26
|
+
jwk: object;
|
|
27
|
+
verificationMethod: string;
|
|
28
|
+
address?: string;
|
|
29
|
+
chainId?: number;
|
|
30
|
+
}
|
|
31
|
+
type TinyCloudVfsSource = {
|
|
32
|
+
kind: "session";
|
|
33
|
+
host: string;
|
|
34
|
+
session: TinyCloudVfsSessionData;
|
|
35
|
+
} | {
|
|
36
|
+
kind: "resolved-delegation";
|
|
37
|
+
host: string;
|
|
38
|
+
session: TinyCloudVfsSessionData;
|
|
39
|
+
kvPrefix: string;
|
|
40
|
+
};
|
|
41
|
+
interface TinyCloudVfsOptions {
|
|
42
|
+
mountPoint?: string;
|
|
43
|
+
mountPrefix?: string;
|
|
44
|
+
readOnly?: boolean;
|
|
45
|
+
moduleHooks?: boolean;
|
|
46
|
+
overlay?: boolean;
|
|
47
|
+
virtualCwd?: boolean;
|
|
48
|
+
}
|
|
49
|
+
interface TinyCloudVfsProviderOptions {
|
|
50
|
+
source: TinyCloudVfsSource;
|
|
51
|
+
mountPrefix?: string;
|
|
52
|
+
readOnly?: boolean;
|
|
53
|
+
}
|
|
54
|
+
interface TinyCloudVfsWorkerInit {
|
|
55
|
+
source: TinyCloudVfsSource;
|
|
56
|
+
mountPrefix: string;
|
|
57
|
+
}
|
|
58
|
+
interface TinyCloudVfsMetadata {
|
|
59
|
+
kind: "file" | "directory";
|
|
60
|
+
size: number;
|
|
61
|
+
mode: number;
|
|
62
|
+
ctimeMs: number;
|
|
63
|
+
mtimeMs: number;
|
|
64
|
+
birthtimeMs: number;
|
|
65
|
+
}
|
|
66
|
+
interface TinyCloudVfsDirent {
|
|
67
|
+
name: string;
|
|
68
|
+
kind: "file" | "directory";
|
|
69
|
+
parentPath: string;
|
|
70
|
+
}
|
|
71
|
+
type WorkerRequest = {
|
|
72
|
+
type: "init";
|
|
73
|
+
init: TinyCloudVfsWorkerInit;
|
|
74
|
+
} | {
|
|
75
|
+
type: "stat";
|
|
76
|
+
path: string;
|
|
77
|
+
} | {
|
|
78
|
+
type: "readFile";
|
|
79
|
+
path: string;
|
|
80
|
+
} | {
|
|
81
|
+
type: "writeFile";
|
|
82
|
+
path: string;
|
|
83
|
+
content: Uint8Array;
|
|
84
|
+
mode?: number;
|
|
85
|
+
} | {
|
|
86
|
+
type: "readdir";
|
|
87
|
+
path: string;
|
|
88
|
+
} | {
|
|
89
|
+
type: "mkdir";
|
|
90
|
+
path: string;
|
|
91
|
+
recursive?: boolean;
|
|
92
|
+
mode?: number;
|
|
93
|
+
} | {
|
|
94
|
+
type: "rmdir";
|
|
95
|
+
path: string;
|
|
96
|
+
} | {
|
|
97
|
+
type: "unlink";
|
|
98
|
+
path: string;
|
|
99
|
+
} | {
|
|
100
|
+
type: "rename";
|
|
101
|
+
oldPath: string;
|
|
102
|
+
newPath: string;
|
|
103
|
+
};
|
|
104
|
+
type WorkerResponse = {
|
|
105
|
+
ok: true;
|
|
106
|
+
result: null;
|
|
107
|
+
} | {
|
|
108
|
+
ok: true;
|
|
109
|
+
result: {
|
|
110
|
+
metadata: TinyCloudVfsMetadata;
|
|
111
|
+
};
|
|
112
|
+
} | {
|
|
113
|
+
ok: true;
|
|
114
|
+
result: {
|
|
115
|
+
content: Uint8Array;
|
|
116
|
+
metadata: TinyCloudVfsMetadata;
|
|
117
|
+
};
|
|
118
|
+
} | {
|
|
119
|
+
ok: true;
|
|
120
|
+
result: {
|
|
121
|
+
entries: TinyCloudVfsDirent[];
|
|
122
|
+
};
|
|
123
|
+
} | {
|
|
124
|
+
ok: false;
|
|
125
|
+
error: WorkerErrorPayload;
|
|
126
|
+
};
|
|
127
|
+
interface WorkerErrorPayload {
|
|
128
|
+
code: string;
|
|
129
|
+
message: string;
|
|
130
|
+
syscall?: string;
|
|
131
|
+
path?: string;
|
|
132
|
+
}
|
|
133
|
+
interface TinyCloudVfsHandleState {
|
|
134
|
+
path: string;
|
|
135
|
+
flags: string;
|
|
136
|
+
mode: number;
|
|
137
|
+
content: Buffer;
|
|
138
|
+
metadata: TinyCloudVfsMetadata;
|
|
139
|
+
}
|
|
140
|
+
interface CreateTinyCloudDelegatedVfsOptions extends Omit<TinyCloudVfsOptions, "mountPrefix"> {
|
|
141
|
+
node: TinyCloudNodeLike;
|
|
142
|
+
delegation: PortableDelegationLike;
|
|
143
|
+
mountPrefix?: string;
|
|
144
|
+
host?: string;
|
|
145
|
+
}
|
|
146
|
+
interface CreateTinyCloudNodeVfsOptions extends Omit<TinyCloudVfsOptions, "mountPrefix"> {
|
|
147
|
+
mountPrefix?: string;
|
|
148
|
+
host?: string;
|
|
149
|
+
}
|
|
150
|
+
interface TinyCloudNodeLike {
|
|
151
|
+
session?: TinyCloudVfsSessionData;
|
|
152
|
+
config?: {
|
|
153
|
+
host?: string;
|
|
154
|
+
};
|
|
155
|
+
useDelegation?: (delegation: PortableDelegationLike) => Promise<{
|
|
156
|
+
session?: TinyCloudVfsSessionData;
|
|
157
|
+
kv: {
|
|
158
|
+
config?: {
|
|
159
|
+
prefix?: string;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
}>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
declare class TinyCloudVfsBridge {
|
|
166
|
+
private readonly worker;
|
|
167
|
+
constructor(init: TinyCloudVfsWorkerInit);
|
|
168
|
+
close(): void;
|
|
169
|
+
requestSync(request: WorkerRequest): WorkerResponse;
|
|
170
|
+
requestAsync(request: WorkerRequest): Promise<WorkerResponse>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare class TinyCloudVfsFileHandle {
|
|
174
|
+
private readonly bridge;
|
|
175
|
+
private readonly state;
|
|
176
|
+
private closed;
|
|
177
|
+
private dirty;
|
|
178
|
+
private position;
|
|
179
|
+
constructor(bridge: TinyCloudVfsBridge, state: TinyCloudVfsHandleState);
|
|
180
|
+
private ensureOpen;
|
|
181
|
+
private commit;
|
|
182
|
+
readSync(buffer: Buffer$1, offset: number, length: number, position: number | null): number;
|
|
183
|
+
writeSync(buffer: Buffer$1, offset: number, length: number, position: number | null): number;
|
|
184
|
+
readFileSync(options?: BufferEncoding | {
|
|
185
|
+
encoding?: BufferEncoding | null;
|
|
186
|
+
} | null): Buffer$1 | string;
|
|
187
|
+
writeFileSync(data: string | Buffer$1, options?: BufferEncoding | {
|
|
188
|
+
encoding?: BufferEncoding;
|
|
189
|
+
mode?: number;
|
|
190
|
+
}): void;
|
|
191
|
+
statSync(): {
|
|
192
|
+
dev: number;
|
|
193
|
+
mode: number;
|
|
194
|
+
nlink: number;
|
|
195
|
+
uid: number;
|
|
196
|
+
gid: number;
|
|
197
|
+
rdev: number;
|
|
198
|
+
blksize: number;
|
|
199
|
+
ino: number;
|
|
200
|
+
size: number;
|
|
201
|
+
blocks: number;
|
|
202
|
+
atimeMs: number;
|
|
203
|
+
mtimeMs: number;
|
|
204
|
+
ctimeMs: number;
|
|
205
|
+
birthtimeMs: number;
|
|
206
|
+
atime: Date;
|
|
207
|
+
mtime: Date;
|
|
208
|
+
ctime: Date;
|
|
209
|
+
birthtime: Date;
|
|
210
|
+
isFile: () => boolean;
|
|
211
|
+
isDirectory: () => boolean;
|
|
212
|
+
isSymbolicLink: () => boolean;
|
|
213
|
+
isBlockDevice: () => boolean;
|
|
214
|
+
isCharacterDevice: () => boolean;
|
|
215
|
+
isFIFO: () => boolean;
|
|
216
|
+
isSocket: () => boolean;
|
|
217
|
+
};
|
|
218
|
+
closeSync(): void;
|
|
219
|
+
}
|
|
220
|
+
declare class TinyCloudVfsProvider extends VirtualProvider {
|
|
221
|
+
private readonly bridge;
|
|
222
|
+
private readonly forceReadOnly;
|
|
223
|
+
constructor(options: TinyCloudVfsProviderOptions);
|
|
224
|
+
get readonly(): boolean;
|
|
225
|
+
close(): void;
|
|
226
|
+
private ensureWritable;
|
|
227
|
+
private normalize;
|
|
228
|
+
openSync(path: string, flags?: string, mode?: number): TinyCloudVfsFileHandle;
|
|
229
|
+
open(path: string, flags?: string, mode?: number): Promise<TinyCloudVfsFileHandle>;
|
|
230
|
+
statSync(path: string): {
|
|
231
|
+
dev: number;
|
|
232
|
+
mode: number;
|
|
233
|
+
nlink: number;
|
|
234
|
+
uid: number;
|
|
235
|
+
gid: number;
|
|
236
|
+
rdev: number;
|
|
237
|
+
blksize: number;
|
|
238
|
+
ino: number;
|
|
239
|
+
size: number;
|
|
240
|
+
blocks: number;
|
|
241
|
+
atimeMs: number;
|
|
242
|
+
mtimeMs: number;
|
|
243
|
+
ctimeMs: number;
|
|
244
|
+
birthtimeMs: number;
|
|
245
|
+
atime: Date;
|
|
246
|
+
mtime: Date;
|
|
247
|
+
ctime: Date;
|
|
248
|
+
birthtime: Date;
|
|
249
|
+
isFile: () => boolean;
|
|
250
|
+
isDirectory: () => boolean;
|
|
251
|
+
isSymbolicLink: () => boolean;
|
|
252
|
+
isBlockDevice: () => boolean;
|
|
253
|
+
isCharacterDevice: () => boolean;
|
|
254
|
+
isFIFO: () => boolean;
|
|
255
|
+
isSocket: () => boolean;
|
|
256
|
+
};
|
|
257
|
+
stat(path: string): Promise<{
|
|
258
|
+
dev: number;
|
|
259
|
+
mode: number;
|
|
260
|
+
nlink: number;
|
|
261
|
+
uid: number;
|
|
262
|
+
gid: number;
|
|
263
|
+
rdev: number;
|
|
264
|
+
blksize: number;
|
|
265
|
+
ino: number;
|
|
266
|
+
size: number;
|
|
267
|
+
blocks: number;
|
|
268
|
+
atimeMs: number;
|
|
269
|
+
mtimeMs: number;
|
|
270
|
+
ctimeMs: number;
|
|
271
|
+
birthtimeMs: number;
|
|
272
|
+
atime: Date;
|
|
273
|
+
mtime: Date;
|
|
274
|
+
ctime: Date;
|
|
275
|
+
birthtime: Date;
|
|
276
|
+
isFile: () => boolean;
|
|
277
|
+
isDirectory: () => boolean;
|
|
278
|
+
isSymbolicLink: () => boolean;
|
|
279
|
+
isBlockDevice: () => boolean;
|
|
280
|
+
isCharacterDevice: () => boolean;
|
|
281
|
+
isFIFO: () => boolean;
|
|
282
|
+
isSocket: () => boolean;
|
|
283
|
+
}>;
|
|
284
|
+
lstatSync(path: string): {
|
|
285
|
+
dev: number;
|
|
286
|
+
mode: number;
|
|
287
|
+
nlink: number;
|
|
288
|
+
uid: number;
|
|
289
|
+
gid: number;
|
|
290
|
+
rdev: number;
|
|
291
|
+
blksize: number;
|
|
292
|
+
ino: number;
|
|
293
|
+
size: number;
|
|
294
|
+
blocks: number;
|
|
295
|
+
atimeMs: number;
|
|
296
|
+
mtimeMs: number;
|
|
297
|
+
ctimeMs: number;
|
|
298
|
+
birthtimeMs: number;
|
|
299
|
+
atime: Date;
|
|
300
|
+
mtime: Date;
|
|
301
|
+
ctime: Date;
|
|
302
|
+
birthtime: Date;
|
|
303
|
+
isFile: () => boolean;
|
|
304
|
+
isDirectory: () => boolean;
|
|
305
|
+
isSymbolicLink: () => boolean;
|
|
306
|
+
isBlockDevice: () => boolean;
|
|
307
|
+
isCharacterDevice: () => boolean;
|
|
308
|
+
isFIFO: () => boolean;
|
|
309
|
+
isSocket: () => boolean;
|
|
310
|
+
};
|
|
311
|
+
lstat(path: string): Promise<{
|
|
312
|
+
dev: number;
|
|
313
|
+
mode: number;
|
|
314
|
+
nlink: number;
|
|
315
|
+
uid: number;
|
|
316
|
+
gid: number;
|
|
317
|
+
rdev: number;
|
|
318
|
+
blksize: number;
|
|
319
|
+
ino: number;
|
|
320
|
+
size: number;
|
|
321
|
+
blocks: number;
|
|
322
|
+
atimeMs: number;
|
|
323
|
+
mtimeMs: number;
|
|
324
|
+
ctimeMs: number;
|
|
325
|
+
birthtimeMs: number;
|
|
326
|
+
atime: Date;
|
|
327
|
+
mtime: Date;
|
|
328
|
+
ctime: Date;
|
|
329
|
+
birthtime: Date;
|
|
330
|
+
isFile: () => boolean;
|
|
331
|
+
isDirectory: () => boolean;
|
|
332
|
+
isSymbolicLink: () => boolean;
|
|
333
|
+
isBlockDevice: () => boolean;
|
|
334
|
+
isCharacterDevice: () => boolean;
|
|
335
|
+
isFIFO: () => boolean;
|
|
336
|
+
isSocket: () => boolean;
|
|
337
|
+
}>;
|
|
338
|
+
readdirSync(path: string, options?: {
|
|
339
|
+
withFileTypes?: boolean;
|
|
340
|
+
}): string[] | {
|
|
341
|
+
name: string;
|
|
342
|
+
parentPath: string;
|
|
343
|
+
path: string;
|
|
344
|
+
isFile: () => boolean;
|
|
345
|
+
isDirectory: () => boolean;
|
|
346
|
+
isSymbolicLink: () => boolean;
|
|
347
|
+
isBlockDevice: () => boolean;
|
|
348
|
+
isCharacterDevice: () => boolean;
|
|
349
|
+
isFIFO: () => boolean;
|
|
350
|
+
isSocket: () => boolean;
|
|
351
|
+
}[];
|
|
352
|
+
readdir(path: string, options?: {
|
|
353
|
+
withFileTypes?: boolean;
|
|
354
|
+
}): Promise<string[] | {
|
|
355
|
+
name: string;
|
|
356
|
+
parentPath: string;
|
|
357
|
+
path: string;
|
|
358
|
+
isFile: () => boolean;
|
|
359
|
+
isDirectory: () => boolean;
|
|
360
|
+
isSymbolicLink: () => boolean;
|
|
361
|
+
isBlockDevice: () => boolean;
|
|
362
|
+
isCharacterDevice: () => boolean;
|
|
363
|
+
isFIFO: () => boolean;
|
|
364
|
+
isSocket: () => boolean;
|
|
365
|
+
}[]>;
|
|
366
|
+
mkdirSync(path: string, options?: {
|
|
367
|
+
recursive?: boolean;
|
|
368
|
+
mode?: number;
|
|
369
|
+
}): string | undefined;
|
|
370
|
+
mkdir(path: string, options?: {
|
|
371
|
+
recursive?: boolean;
|
|
372
|
+
mode?: number;
|
|
373
|
+
}): Promise<string | undefined>;
|
|
374
|
+
rmdirSync(path: string): void;
|
|
375
|
+
rmdir(path: string): Promise<void>;
|
|
376
|
+
unlinkSync(path: string): void;
|
|
377
|
+
unlink(path: string): Promise<void>;
|
|
378
|
+
renameSync(oldPath: string, newPath: string): void;
|
|
379
|
+
rename(oldPath: string, newPath: string): Promise<void>;
|
|
380
|
+
}
|
|
381
|
+
declare function createTinyCloudVfs(options: TinyCloudVfsProviderOptions & TinyCloudVfsOptions): {
|
|
382
|
+
provider: TinyCloudVfsProvider;
|
|
383
|
+
vfs: VirtualFileSystem;
|
|
384
|
+
};
|
|
385
|
+
declare function createTinyCloudVfsFromNode(node: TinyCloudNodeLike, options?: CreateTinyCloudNodeVfsOptions): {
|
|
386
|
+
provider: TinyCloudVfsProvider;
|
|
387
|
+
vfs: VirtualFileSystem;
|
|
388
|
+
};
|
|
389
|
+
declare function createTinyCloudDelegatedVfs(options: CreateTinyCloudDelegatedVfsOptions): Promise<{
|
|
390
|
+
provider: TinyCloudVfsProvider;
|
|
391
|
+
vfs: VirtualFileSystem;
|
|
392
|
+
}>;
|
|
393
|
+
|
|
394
|
+
export { type CreateTinyCloudDelegatedVfsOptions, type CreateTinyCloudNodeVfsOptions, type TinyCloudVfsMetadata, type TinyCloudVfsOptions, TinyCloudVfsProvider, type TinyCloudVfsProviderOptions, type TinyCloudVfsSessionData, type TinyCloudVfsSource, createTinyCloudDelegatedVfs, createTinyCloudVfs, createTinyCloudVfsFromNode };
|