@zenfs/core 0.5.4 → 0.5.6
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/ApiError.d.ts +5 -12
- package/dist/ApiError.js +6 -27
- package/dist/FileIndex.js +10 -10
- package/dist/backends/AsyncMirror.d.ts +1 -1
- package/dist/backends/AsyncMirror.js +2 -0
- package/dist/backends/AsyncStore.js +24 -24
- package/dist/backends/InMemory.d.ts +2 -2
- package/dist/backends/InMemory.js +1 -0
- package/dist/backends/Overlay.d.ts +1 -1
- package/dist/backends/Overlay.js +17 -17
- package/dist/backends/SyncStore.js +23 -23
- package/dist/backends/backend.d.ts +4 -4
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/emulation/{callbacks.d.ts → async.d.ts} +52 -15
- package/dist/emulation/{callbacks.js → async.js} +99 -35
- package/dist/emulation/constants.d.ts +5 -0
- package/dist/emulation/constants.js +5 -0
- package/dist/emulation/dir.d.ts +3 -2
- package/dist/emulation/dir.js +6 -2
- package/dist/emulation/index.d.ts +2 -2
- package/dist/emulation/index.js +2 -2
- package/dist/emulation/promises.d.ts +88 -115
- package/dist/emulation/promises.js +112 -110
- package/dist/emulation/shared.d.ts +9 -10
- package/dist/emulation/shared.js +28 -40
- package/dist/emulation/streams.d.ts +5 -0
- package/dist/emulation/sync.d.ts +50 -18
- package/dist/emulation/sync.js +65 -29
- package/dist/file.d.ts +11 -7
- package/dist/file.js +11 -15
- package/dist/stats.d.ts +34 -19
- package/dist/stats.js +8 -51
- package/dist/utils.d.ts +2 -3
- package/dist/utils.js +6 -88
- package/package.json +3 -2
|
@@ -134,10 +134,10 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
134
134
|
// Remove oldPath from parent's directory listing.
|
|
135
135
|
oldDirNode = this.findINode(tx, oldParent), oldDirList = this.getDirListing(tx, oldDirNode, oldParent);
|
|
136
136
|
if (!oldDirNode.toStats().hasAccess(W_OK, cred)) {
|
|
137
|
-
throw ApiError.EACCES
|
|
137
|
+
throw ApiError.With('EACCES', oldPath, 'renameSync');
|
|
138
138
|
}
|
|
139
139
|
if (!oldDirList[oldName]) {
|
|
140
|
-
throw ApiError.ENOENT
|
|
140
|
+
throw ApiError.With('ENOENT', oldPath, 'renameSync');
|
|
141
141
|
}
|
|
142
142
|
const ino = oldDirList[oldName];
|
|
143
143
|
delete oldDirList[oldName];
|
|
@@ -175,7 +175,7 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
175
175
|
}
|
|
176
176
|
else {
|
|
177
177
|
// If it's a directory, throw a permissions error.
|
|
178
|
-
throw ApiError.EPERM
|
|
178
|
+
throw ApiError.With('EPERM', newPath, 'renameSync');
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
newDirList[newName] = ino;
|
|
@@ -194,7 +194,7 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
194
194
|
// Get the inode to the item, convert it into a Stats object.
|
|
195
195
|
const stats = this.findINode(this.store.beginTransaction(), p).toStats();
|
|
196
196
|
if (!stats.hasAccess(R_OK, cred)) {
|
|
197
|
-
throw ApiError.EACCES
|
|
197
|
+
throw ApiError.With('EACCES', p, 'statSync');
|
|
198
198
|
}
|
|
199
199
|
return stats;
|
|
200
200
|
}
|
|
@@ -205,10 +205,10 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
205
205
|
openFileSync(p, flag, cred) {
|
|
206
206
|
const tx = this.store.beginTransaction(), node = this.findINode(tx, p), data = tx.get(node.ino);
|
|
207
207
|
if (!node.toStats().hasAccess(flagToMode(flag), cred)) {
|
|
208
|
-
throw ApiError.EACCES
|
|
208
|
+
throw ApiError.With('EACCES', p, 'openFileSync');
|
|
209
209
|
}
|
|
210
210
|
if (data === null) {
|
|
211
|
-
throw ApiError.ENOENT
|
|
211
|
+
throw ApiError.With('ENOENT', p, 'openFileSync');
|
|
212
212
|
}
|
|
213
213
|
return new SyncStoreFile(this, p, flag, node.toStats(), data);
|
|
214
214
|
}
|
|
@@ -218,7 +218,7 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
218
218
|
rmdirSync(p, cred) {
|
|
219
219
|
// Check first if directory is empty.
|
|
220
220
|
if (this.readdirSync(p, cred).length > 0) {
|
|
221
|
-
throw ApiError.ENOTEMPTY
|
|
221
|
+
throw ApiError.With('ENOTEMPTY', p, 'rmdirSync');
|
|
222
222
|
}
|
|
223
223
|
else {
|
|
224
224
|
this.removeEntry(p, true, cred);
|
|
@@ -231,7 +231,7 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
231
231
|
const tx = this.store.beginTransaction();
|
|
232
232
|
const node = this.findINode(tx, p);
|
|
233
233
|
if (!node.toStats().hasAccess(R_OK, cred)) {
|
|
234
|
-
throw ApiError.EACCES
|
|
234
|
+
throw ApiError.With('EACCES', p, 'readdirSync');
|
|
235
235
|
}
|
|
236
236
|
return Object.keys(this.getDirListing(tx, node, p));
|
|
237
237
|
}
|
|
@@ -258,16 +258,16 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
258
258
|
linkSync(existing, newpath, cred) {
|
|
259
259
|
const tx = this.store.beginTransaction(), existingDir = dirname(existing), existingDirNode = this.findINode(tx, existingDir);
|
|
260
260
|
if (!existingDirNode.toStats().hasAccess(R_OK, cred)) {
|
|
261
|
-
throw ApiError.EACCES
|
|
261
|
+
throw ApiError.With('EACCES', existingDir, 'linkSync');
|
|
262
262
|
}
|
|
263
263
|
const newDir = dirname(newpath), newDirNode = this.findINode(tx, newDir), newListing = this.getDirListing(tx, newDirNode, newDir);
|
|
264
264
|
if (!newDirNode.toStats().hasAccess(W_OK, cred)) {
|
|
265
|
-
throw ApiError.EACCES
|
|
265
|
+
throw ApiError.With('EACCES', newDir, 'linkSync');
|
|
266
266
|
}
|
|
267
267
|
const ino = this._findINode(tx, existingDir, basename(existing));
|
|
268
268
|
const node = this.getINode(tx, ino, existing);
|
|
269
269
|
if (!node.toStats().hasAccess(W_OK, cred)) {
|
|
270
|
-
throw ApiError.EACCES
|
|
270
|
+
throw ApiError.With('EACCES', newpath, 'linkSync');
|
|
271
271
|
}
|
|
272
272
|
node.nlink++;
|
|
273
273
|
newListing[basename(newpath)] = ino;
|
|
@@ -314,7 +314,7 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
314
314
|
const ino = this._findINode(tx, dirname(parent), basename(parent), visited);
|
|
315
315
|
const dir = this.getDirListing(tx, this.getINode(tx, ino, parent + sep + filename), parent);
|
|
316
316
|
if (!(filename in dir)) {
|
|
317
|
-
throw ApiError.ENOENT
|
|
317
|
+
throw ApiError.With('ENOENT', resolve(parent, filename), '_findINode');
|
|
318
318
|
}
|
|
319
319
|
return dir[filename];
|
|
320
320
|
}
|
|
@@ -322,7 +322,7 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
322
322
|
// Find the item in the root node.
|
|
323
323
|
const dir = this.getDirListing(tx, this.getINode(tx, rootIno, parent), parent);
|
|
324
324
|
if (!(filename in dir)) {
|
|
325
|
-
throw ApiError.ENOENT
|
|
325
|
+
throw ApiError.With('ENOENT', resolve(parent, filename), '_findINode');
|
|
326
326
|
}
|
|
327
327
|
return dir[filename];
|
|
328
328
|
}
|
|
@@ -348,7 +348,7 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
348
348
|
getINode(tx, id, p) {
|
|
349
349
|
const data = tx.get(id);
|
|
350
350
|
if (!data) {
|
|
351
|
-
throw ApiError.ENOENT
|
|
351
|
+
throw ApiError.With('ENOENT', p, 'getINode');
|
|
352
352
|
}
|
|
353
353
|
const inode = new Inode(data.buffer);
|
|
354
354
|
return inode;
|
|
@@ -358,11 +358,11 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
358
358
|
*/
|
|
359
359
|
getDirListing(tx, inode, p) {
|
|
360
360
|
if (!inode.toStats().isDirectory()) {
|
|
361
|
-
throw ApiError.ENOTDIR
|
|
361
|
+
throw ApiError.With('ENOTDIR', p, 'getDirListing');
|
|
362
362
|
}
|
|
363
363
|
const data = tx.get(inode.ino);
|
|
364
364
|
if (!data) {
|
|
365
|
-
throw ApiError.ENOENT
|
|
365
|
+
throw ApiError.With('ENOENT', p, 'getDirListing');
|
|
366
366
|
}
|
|
367
367
|
return decodeDirListing(data);
|
|
368
368
|
}
|
|
@@ -394,18 +394,18 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
394
394
|
const tx = this.store.beginTransaction(), parentDir = dirname(p), fname = basename(p), parentNode = this.findINode(tx, parentDir), dirListing = this.getDirListing(tx, parentNode, parentDir);
|
|
395
395
|
//Check that the creater has correct access
|
|
396
396
|
if (!parentNode.toStats().hasAccess(W_OK, cred)) {
|
|
397
|
-
throw ApiError.EACCES
|
|
397
|
+
throw ApiError.With('EACCES', p, 'commitNewFile');
|
|
398
398
|
}
|
|
399
399
|
/* Invariant: The root always exists.
|
|
400
400
|
If we don't check this prior to taking steps below,
|
|
401
401
|
we will create a file with name '' in root should p == '/'.
|
|
402
402
|
*/
|
|
403
403
|
if (p === '/') {
|
|
404
|
-
throw ApiError.EEXIST
|
|
404
|
+
throw ApiError.With('EEXIST', p, 'commitNewFile');
|
|
405
405
|
}
|
|
406
406
|
// Check if file already exists.
|
|
407
407
|
if (dirListing[fname]) {
|
|
408
|
-
throw ApiError.EEXIST
|
|
408
|
+
throw ApiError.With('EEXIST', p, 'commitNewFile');
|
|
409
409
|
}
|
|
410
410
|
const fileNode = new Inode();
|
|
411
411
|
try {
|
|
@@ -435,20 +435,20 @@ export class SyncStoreFS extends Sync(FileSystem) {
|
|
|
435
435
|
removeEntry(p, isDir, cred) {
|
|
436
436
|
const tx = this.store.beginTransaction(), parent = dirname(p), parentNode = this.findINode(tx, parent), parentListing = this.getDirListing(tx, parentNode, parent), fileName = basename(p), fileIno = parentListing[fileName];
|
|
437
437
|
if (!fileIno) {
|
|
438
|
-
throw ApiError.ENOENT
|
|
438
|
+
throw ApiError.With('ENOENT', p, 'removeEntry');
|
|
439
439
|
}
|
|
440
440
|
// Get file inode.
|
|
441
441
|
const fileNode = this.getINode(tx, fileIno, p);
|
|
442
442
|
if (!fileNode.toStats().hasAccess(W_OK, cred)) {
|
|
443
|
-
throw ApiError.EACCES
|
|
443
|
+
throw ApiError.With('EACCES', p, 'removeEntry');
|
|
444
444
|
}
|
|
445
445
|
// Remove from directory listing of parent.
|
|
446
446
|
delete parentListing[fileName];
|
|
447
447
|
if (!isDir && fileNode.toStats().isDirectory()) {
|
|
448
|
-
throw ApiError.EISDIR
|
|
448
|
+
throw ApiError.With('EISDIR', p, 'removeEntry');
|
|
449
449
|
}
|
|
450
450
|
if (isDir && !fileNode.toStats().isDirectory()) {
|
|
451
|
-
throw ApiError.ENOTDIR
|
|
451
|
+
throw ApiError.With('ENOTDIR', p, 'removeEntry');
|
|
452
452
|
}
|
|
453
453
|
try {
|
|
454
454
|
// Update directory listing.
|
|
@@ -11,7 +11,7 @@ export interface OptionConfig<T> {
|
|
|
11
11
|
/**
|
|
12
12
|
* Whether or not the option is required (optional can be set to null or undefined). Defaults to false.
|
|
13
13
|
*/
|
|
14
|
-
required
|
|
14
|
+
required: boolean;
|
|
15
15
|
/**
|
|
16
16
|
* Description of the option. Used in error messages and documentation.
|
|
17
17
|
*/
|
|
@@ -73,8 +73,8 @@ export declare function createBackend<B extends Backend>(backend: B, options?: o
|
|
|
73
73
|
*
|
|
74
74
|
* The option object for each file system corresponds to that file system's option object passed to its `Create()` method.
|
|
75
75
|
*/
|
|
76
|
-
export interface BackendConfig {
|
|
77
|
-
backend: Backend
|
|
76
|
+
export interface BackendConfig<FS extends FileSystem = FileSystem, OC extends BackendOptionsConfig = BackendOptionsConfig> {
|
|
77
|
+
backend: Backend<FS, OC>;
|
|
78
78
|
[key: string]: unknown;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -85,5 +85,5 @@ export declare function isBackendConfig(arg: unknown): arg is BackendConfig;
|
|
|
85
85
|
* Retrieve a file system with the given configuration.
|
|
86
86
|
* @param config A BackendConfig object.
|
|
87
87
|
*/
|
|
88
|
-
export declare function resolveBackend(options: BackendConfig
|
|
88
|
+
export declare function resolveBackend<FS extends FileSystem>(options: BackendConfig<FS>, _depth?: number): Promise<FS>;
|
|
89
89
|
export {};
|