@zenfs/core 0.9.7 → 0.10.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/backends/AsyncStore.js +29 -29
- package/dist/backends/Fetch.d.ts +84 -0
- package/dist/backends/Fetch.js +171 -0
- package/dist/backends/Index.js +19 -19
- package/dist/backends/Locked.d.ts +11 -11
- package/dist/backends/Locked.js +50 -49
- package/dist/backends/Overlay.js +21 -21
- package/dist/backends/SyncStore.js +27 -27
- package/dist/backends/backend.js +4 -4
- package/dist/backends/port/fs.d.ts +124 -0
- package/dist/backends/port/fs.js +241 -0
- package/dist/backends/port/rpc.d.ts +60 -0
- package/dist/backends/port/rpc.js +71 -0
- package/dist/backends/port/store.d.ts +30 -0
- package/dist/backends/port/store.js +142 -0
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.d.ts +8 -10
- package/dist/config.js +11 -11
- package/dist/emulation/async.js +6 -6
- package/dist/emulation/dir.js +2 -2
- package/dist/emulation/index.d.ts +1 -1
- package/dist/emulation/index.js +1 -1
- package/dist/emulation/path.d.ts +3 -2
- package/dist/emulation/path.js +19 -45
- package/dist/emulation/promises.d.ts +7 -12
- package/dist/emulation/promises.js +144 -146
- package/dist/emulation/shared.d.ts +5 -10
- package/dist/emulation/shared.js +8 -8
- package/dist/emulation/streams.js +3 -3
- package/dist/emulation/sync.js +25 -25
- package/dist/{ApiError.d.ts → error.d.ts} +13 -14
- package/dist/error.js +292 -0
- package/dist/file.d.ts +2 -0
- package/dist/file.js +10 -4
- package/dist/filesystem.js +15 -15
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/mutex.js +2 -1
- package/dist/utils.d.ts +8 -7
- package/dist/utils.js +11 -12
- package/package.json +3 -3
- package/readme.md +17 -9
- package/src/backends/AsyncStore.ts +29 -29
- package/src/backends/Fetch.ts +230 -0
- package/src/backends/Index.ts +19 -19
- package/src/backends/Locked.ts +50 -49
- package/src/backends/Overlay.ts +23 -23
- package/src/backends/SyncStore.ts +27 -27
- package/src/backends/backend.ts +6 -6
- package/src/backends/port/fs.ts +308 -0
- package/src/backends/port/readme.md +59 -0
- package/src/backends/port/rpc.ts +144 -0
- package/src/backends/port/store.ts +187 -0
- package/src/config.ts +20 -24
- package/src/emulation/async.ts +6 -6
- package/src/emulation/dir.ts +2 -2
- package/src/emulation/index.ts +1 -1
- package/src/emulation/path.ts +25 -49
- package/src/emulation/promises.ts +150 -159
- package/src/emulation/shared.ts +12 -14
- package/src/emulation/streams.ts +3 -3
- package/src/emulation/sync.ts +28 -28
- package/src/{ApiError.ts → error.ts} +89 -89
- package/src/file.ts +12 -4
- package/src/filesystem.ts +15 -15
- package/src/index.ts +4 -1
- package/src/mutex.ts +3 -1
- package/src/utils.ts +16 -18
- package/tsconfig.json +2 -2
- package/dist/ApiError.js +0 -292
package/src/filesystem.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ExtractProperties } from 'utilium';
|
|
2
|
-
import {
|
|
2
|
+
import { ErrnoError, Errno } from './error.js';
|
|
3
3
|
import { rootCred, type Cred } from './cred.js';
|
|
4
4
|
import { join } from './emulation/path.js';
|
|
5
5
|
import { PreloadFile, parseFlag, type File } from './file.js';
|
|
@@ -493,59 +493,59 @@ export function Readonly<T extends abstract new (...args: any[]) => FileSystem>(
|
|
|
493
493
|
}
|
|
494
494
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
495
495
|
public async rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {
|
|
496
|
-
throw new
|
|
496
|
+
throw new ErrnoError(Errno.EROFS);
|
|
497
497
|
}
|
|
498
498
|
|
|
499
499
|
public renameSync(oldPath: string, newPath: string, cred: Cred): void {
|
|
500
|
-
throw new
|
|
500
|
+
throw new ErrnoError(Errno.EROFS);
|
|
501
501
|
}
|
|
502
502
|
|
|
503
503
|
public async createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File> {
|
|
504
|
-
throw new
|
|
504
|
+
throw new ErrnoError(Errno.EROFS);
|
|
505
505
|
}
|
|
506
506
|
|
|
507
507
|
public createFileSync(path: string, flag: string, mode: number, cred: Cred): File {
|
|
508
|
-
throw new
|
|
508
|
+
throw new ErrnoError(Errno.EROFS);
|
|
509
509
|
}
|
|
510
510
|
|
|
511
511
|
public async unlink(path: string, cred: Cred): Promise<void> {
|
|
512
|
-
throw new
|
|
512
|
+
throw new ErrnoError(Errno.EROFS);
|
|
513
513
|
}
|
|
514
514
|
|
|
515
515
|
public unlinkSync(path: string, cred: Cred): void {
|
|
516
|
-
throw new
|
|
516
|
+
throw new ErrnoError(Errno.EROFS);
|
|
517
517
|
}
|
|
518
518
|
|
|
519
519
|
public async rmdir(path: string, cred: Cred): Promise<void> {
|
|
520
|
-
throw new
|
|
520
|
+
throw new ErrnoError(Errno.EROFS);
|
|
521
521
|
}
|
|
522
522
|
|
|
523
523
|
public rmdirSync(path: string, cred: Cred): void {
|
|
524
|
-
throw new
|
|
524
|
+
throw new ErrnoError(Errno.EROFS);
|
|
525
525
|
}
|
|
526
526
|
|
|
527
527
|
public async mkdir(path: string, mode: number, cred: Cred): Promise<void> {
|
|
528
|
-
throw new
|
|
528
|
+
throw new ErrnoError(Errno.EROFS);
|
|
529
529
|
}
|
|
530
530
|
|
|
531
531
|
public mkdirSync(path: string, mode: number, cred: Cred): void {
|
|
532
|
-
throw new
|
|
532
|
+
throw new ErrnoError(Errno.EROFS);
|
|
533
533
|
}
|
|
534
534
|
|
|
535
535
|
public async link(srcpath: string, dstpath: string, cred: Cred): Promise<void> {
|
|
536
|
-
throw new
|
|
536
|
+
throw new ErrnoError(Errno.EROFS);
|
|
537
537
|
}
|
|
538
538
|
|
|
539
539
|
public linkSync(srcpath: string, dstpath: string, cred: Cred): void {
|
|
540
|
-
throw new
|
|
540
|
+
throw new ErrnoError(Errno.EROFS);
|
|
541
541
|
}
|
|
542
542
|
|
|
543
543
|
public async sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void> {
|
|
544
|
-
throw new
|
|
544
|
+
throw new ErrnoError(Errno.EROFS);
|
|
545
545
|
}
|
|
546
546
|
|
|
547
547
|
public syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void {
|
|
548
|
-
throw new
|
|
548
|
+
throw new ErrnoError(Errno.EROFS);
|
|
549
549
|
}
|
|
550
550
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
551
551
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './error.js';
|
|
2
|
+
export * from './backends/port/fs.js';
|
|
3
|
+
export * from './backends/port/store.js';
|
|
2
4
|
export * from './backends/AsyncStore.js';
|
|
5
|
+
export * from './backends/Fetch.js';
|
|
3
6
|
export * from './backends/InMemory.js';
|
|
4
7
|
export * from './backends/Index.js';
|
|
5
8
|
export * from './backends/Locked.js';
|
package/src/mutex.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ErrnoError, Errno } from './error.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Non-recursive mutex
|
|
3
5
|
* @internal
|
|
@@ -17,7 +19,7 @@ export class Mutex {
|
|
|
17
19
|
|
|
18
20
|
public unlock(path: string): void {
|
|
19
21
|
if (!this._locks.has(path)) {
|
|
20
|
-
throw new
|
|
22
|
+
throw new ErrnoError(Errno.EPERM, 'Can not unlock an already unlocked path', path);
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
const next = this._locks.get(path)?.shift();
|
package/src/utils.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { OptionalTuple } from 'utilium';
|
|
2
|
-
import {
|
|
2
|
+
import { ErrnoError, Errno } from './error.js';
|
|
3
3
|
import { Cred } from './cred.js';
|
|
4
|
-
import { dirname, resolve } from './emulation/path.js';
|
|
4
|
+
import { dirname, resolve, type AbsolutePath } from './emulation/path.js';
|
|
5
5
|
import { FileSystem } from './filesystem.js';
|
|
6
|
+
import type * as fs from 'node:fs';
|
|
6
7
|
|
|
7
8
|
declare global {
|
|
8
9
|
function atob(data: string): string;
|
|
@@ -17,10 +18,10 @@ declare const globalThis: {
|
|
|
17
18
|
* Synchronous recursive makedir.
|
|
18
19
|
* @hidden
|
|
19
20
|
*/
|
|
20
|
-
export function mkdirpSync(
|
|
21
|
-
if (!fs.existsSync(
|
|
22
|
-
mkdirpSync(dirname(
|
|
23
|
-
fs.mkdirSync(
|
|
21
|
+
export function mkdirpSync(path: string, mode: number, cred: Cred, fs: FileSystem): void {
|
|
22
|
+
if (!fs.existsSync(path, cred)) {
|
|
23
|
+
mkdirpSync(dirname(path), mode, cred, fs);
|
|
24
|
+
fs.mkdirSync(path, mode, cred);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
|
|
@@ -122,7 +123,7 @@ export const setImmediate = typeof globalThis.setImmediate == 'function' ? globa
|
|
|
122
123
|
*/
|
|
123
124
|
export function encode(input: string): Uint8Array {
|
|
124
125
|
if (typeof input != 'string') {
|
|
125
|
-
throw new
|
|
126
|
+
throw new ErrnoError(Errno.EINVAL, 'Can not encode a non-string');
|
|
126
127
|
}
|
|
127
128
|
return new Uint8Array(Array.from(input).map(char => char.charCodeAt(0)));
|
|
128
129
|
}
|
|
@@ -133,7 +134,7 @@ export function encode(input: string): Uint8Array {
|
|
|
133
134
|
*/
|
|
134
135
|
export function decode(input?: Uint8Array): string {
|
|
135
136
|
if (!(input instanceof Uint8Array)) {
|
|
136
|
-
throw new
|
|
137
|
+
throw new ErrnoError(Errno.EINVAL, 'Can not decode a non-Uint8Array');
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
return Array.from(input)
|
|
@@ -171,9 +172,7 @@ export function encodeDirListing(data: Record<string, bigint>): Uint8Array {
|
|
|
171
172
|
);
|
|
172
173
|
}
|
|
173
174
|
|
|
174
|
-
export type Callback<Args extends unknown[] = []> = (e?:
|
|
175
|
-
|
|
176
|
-
import type { EncodingOption, OpenMode, PathLike, WriteFileOptions } from 'node:fs';
|
|
175
|
+
export type Callback<Args extends unknown[] = []> = (e?: ErrnoError, ...args: OptionalTuple<Args>) => unknown;
|
|
177
176
|
|
|
178
177
|
/**
|
|
179
178
|
* converts Date or number to a integer UNIX timestamp
|
|
@@ -211,7 +210,7 @@ export function normalizeMode(mode: string | number | unknown, def?: number): nu
|
|
|
211
210
|
return def;
|
|
212
211
|
}
|
|
213
212
|
|
|
214
|
-
throw new
|
|
213
|
+
throw new ErrnoError(Errno.EINVAL, 'Invalid mode: ' + mode?.toString());
|
|
215
214
|
}
|
|
216
215
|
|
|
217
216
|
/**
|
|
@@ -231,21 +230,20 @@ export function normalizeTime(time: string | number | Date): Date {
|
|
|
231
230
|
return new Date(time);
|
|
232
231
|
}
|
|
233
232
|
|
|
234
|
-
throw new
|
|
233
|
+
throw new ErrnoError(Errno.EINVAL, 'Invalid time.');
|
|
235
234
|
}
|
|
236
235
|
|
|
237
236
|
/**
|
|
238
237
|
* Normalizes a path
|
|
239
238
|
* @internal
|
|
240
239
|
*/
|
|
241
|
-
export function normalizePath(p: PathLike):
|
|
240
|
+
export function normalizePath(p: fs.PathLike): AbsolutePath {
|
|
242
241
|
p = p.toString();
|
|
243
|
-
// Node doesn't allow null characters in paths.
|
|
244
242
|
if (p.includes('\x00')) {
|
|
245
|
-
throw new
|
|
243
|
+
throw new ErrnoError(Errno.EINVAL, 'Path can not contain null character');
|
|
246
244
|
}
|
|
247
245
|
if (p.length == 0) {
|
|
248
|
-
throw new
|
|
246
|
+
throw new ErrnoError(Errno.EINVAL, 'Path can not be empty');
|
|
249
247
|
}
|
|
250
248
|
return resolve(p.replaceAll(/[/\\]+/g, '/'));
|
|
251
249
|
}
|
|
@@ -259,7 +257,7 @@ export function normalizePath(p: PathLike): string {
|
|
|
259
257
|
* @internal
|
|
260
258
|
*/
|
|
261
259
|
export function normalizeOptions(
|
|
262
|
-
options: WriteFileOptions | (EncodingOption & { flag?: OpenMode }) | undefined,
|
|
260
|
+
options: fs.WriteFileOptions | (fs.EncodingOption & { flag?: fs.OpenMode }) | undefined,
|
|
263
261
|
encoding: BufferEncoding | null = 'utf8',
|
|
264
262
|
flag: string,
|
|
265
263
|
mode: number = 0
|
package/tsconfig.json
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
"module": "NodeNext",
|
|
4
4
|
"target": "ES2020",
|
|
5
5
|
"outDir": "dist",
|
|
6
|
-
"lib": ["ESNext"],
|
|
6
|
+
"lib": ["ESNext", "ESNext.Disposable"],
|
|
7
7
|
"moduleResolution": "NodeNext",
|
|
8
8
|
"declaration": true,
|
|
9
9
|
"strict": true
|
|
10
10
|
},
|
|
11
|
-
"include": ["src
|
|
11
|
+
"include": ["src/**/*.ts"],
|
|
12
12
|
"exclude": ["node_modules"]
|
|
13
13
|
}
|
package/dist/ApiError.js
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Standard libc error codes. More will be added to this enum and ErrorStrings as they are
|
|
3
|
-
* needed.
|
|
4
|
-
* @url https://en.wikipedia.org/wiki/Errno.h
|
|
5
|
-
*/
|
|
6
|
-
export var ErrorCode;
|
|
7
|
-
(function (ErrorCode) {
|
|
8
|
-
/** Operation not permitted */
|
|
9
|
-
ErrorCode[ErrorCode["EPERM"] = 1] = "EPERM";
|
|
10
|
-
/** No such file or directory */
|
|
11
|
-
ErrorCode[ErrorCode["ENOENT"] = 2] = "ENOENT";
|
|
12
|
-
/** Interrupted system call */
|
|
13
|
-
ErrorCode[ErrorCode["EINTR"] = 4] = "EINTR";
|
|
14
|
-
/** Input/output error */
|
|
15
|
-
ErrorCode[ErrorCode["EIO"] = 5] = "EIO";
|
|
16
|
-
/** No such device or address */
|
|
17
|
-
ErrorCode[ErrorCode["ENXIO"] = 6] = "ENXIO";
|
|
18
|
-
/** Bad file descriptor */
|
|
19
|
-
ErrorCode[ErrorCode["EBADF"] = 9] = "EBADF";
|
|
20
|
-
/** Resource temporarily unavailable */
|
|
21
|
-
ErrorCode[ErrorCode["EAGAIN"] = 11] = "EAGAIN";
|
|
22
|
-
/** Cannot allocate memory */
|
|
23
|
-
ErrorCode[ErrorCode["ENOMEM"] = 12] = "ENOMEM";
|
|
24
|
-
/** Permission denied */
|
|
25
|
-
ErrorCode[ErrorCode["EACCES"] = 13] = "EACCES";
|
|
26
|
-
/** Bad address */
|
|
27
|
-
ErrorCode[ErrorCode["EFAULT"] = 14] = "EFAULT";
|
|
28
|
-
/** Block device required */
|
|
29
|
-
ErrorCode[ErrorCode["ENOTBLK"] = 15] = "ENOTBLK";
|
|
30
|
-
/** Resource busy or locked */
|
|
31
|
-
ErrorCode[ErrorCode["EBUSY"] = 16] = "EBUSY";
|
|
32
|
-
/** File exists */
|
|
33
|
-
ErrorCode[ErrorCode["EEXIST"] = 17] = "EEXIST";
|
|
34
|
-
/** Invalid cross-device link */
|
|
35
|
-
ErrorCode[ErrorCode["EXDEV"] = 18] = "EXDEV";
|
|
36
|
-
/** No such device */
|
|
37
|
-
ErrorCode[ErrorCode["ENODEV"] = 19] = "ENODEV";
|
|
38
|
-
/** File is not a directory */
|
|
39
|
-
ErrorCode[ErrorCode["ENOTDIR"] = 20] = "ENOTDIR";
|
|
40
|
-
/** File is a directory */
|
|
41
|
-
ErrorCode[ErrorCode["EISDIR"] = 21] = "EISDIR";
|
|
42
|
-
/** Invalid argument */
|
|
43
|
-
ErrorCode[ErrorCode["EINVAL"] = 22] = "EINVAL";
|
|
44
|
-
/** Too many open files in system */
|
|
45
|
-
ErrorCode[ErrorCode["ENFILE"] = 23] = "ENFILE";
|
|
46
|
-
/** Too many open files */
|
|
47
|
-
ErrorCode[ErrorCode["EMFILE"] = 24] = "EMFILE";
|
|
48
|
-
/** Text file busy */
|
|
49
|
-
ErrorCode[ErrorCode["ETXTBSY"] = 26] = "ETXTBSY";
|
|
50
|
-
/** File is too big */
|
|
51
|
-
ErrorCode[ErrorCode["EFBIG"] = 27] = "EFBIG";
|
|
52
|
-
/** No space left on disk */
|
|
53
|
-
ErrorCode[ErrorCode["ENOSPC"] = 28] = "ENOSPC";
|
|
54
|
-
/** Illegal seek */
|
|
55
|
-
ErrorCode[ErrorCode["ESPIPE"] = 29] = "ESPIPE";
|
|
56
|
-
/** Cannot modify a read-only file system */
|
|
57
|
-
ErrorCode[ErrorCode["EROFS"] = 30] = "EROFS";
|
|
58
|
-
/** Too many links */
|
|
59
|
-
ErrorCode[ErrorCode["EMLINK"] = 31] = "EMLINK";
|
|
60
|
-
/** Broken pipe */
|
|
61
|
-
ErrorCode[ErrorCode["EPIPE"] = 32] = "EPIPE";
|
|
62
|
-
/** Numerical argument out of domain */
|
|
63
|
-
ErrorCode[ErrorCode["EDOM"] = 33] = "EDOM";
|
|
64
|
-
/** Numerical result out of range */
|
|
65
|
-
ErrorCode[ErrorCode["ERANGE"] = 34] = "ERANGE";
|
|
66
|
-
/** Resource deadlock would occur */
|
|
67
|
-
ErrorCode[ErrorCode["EDEADLK"] = 35] = "EDEADLK";
|
|
68
|
-
/** File name too long */
|
|
69
|
-
ErrorCode[ErrorCode["ENAMETOOLONG"] = 36] = "ENAMETOOLONG";
|
|
70
|
-
/** No locks available */
|
|
71
|
-
ErrorCode[ErrorCode["ENOLCK"] = 37] = "ENOLCK";
|
|
72
|
-
/** Function not implemented */
|
|
73
|
-
ErrorCode[ErrorCode["ENOSYS"] = 38] = "ENOSYS";
|
|
74
|
-
/** Directory is not empty */
|
|
75
|
-
ErrorCode[ErrorCode["ENOTEMPTY"] = 39] = "ENOTEMPTY";
|
|
76
|
-
/** Too many levels of symbolic links */
|
|
77
|
-
ErrorCode[ErrorCode["ELOOP"] = 40] = "ELOOP";
|
|
78
|
-
/** No message of desired type */
|
|
79
|
-
ErrorCode[ErrorCode["ENOMSG"] = 42] = "ENOMSG";
|
|
80
|
-
/** Invalid exchange */
|
|
81
|
-
ErrorCode[ErrorCode["EBADE"] = 52] = "EBADE";
|
|
82
|
-
/** Invalid request descriptor */
|
|
83
|
-
ErrorCode[ErrorCode["EBADR"] = 53] = "EBADR";
|
|
84
|
-
/** Exchange full */
|
|
85
|
-
ErrorCode[ErrorCode["EXFULL"] = 54] = "EXFULL";
|
|
86
|
-
/** No anode */
|
|
87
|
-
ErrorCode[ErrorCode["ENOANO"] = 55] = "ENOANO";
|
|
88
|
-
/** Invalid request code */
|
|
89
|
-
ErrorCode[ErrorCode["EBADRQC"] = 56] = "EBADRQC";
|
|
90
|
-
/** Device not a stream */
|
|
91
|
-
ErrorCode[ErrorCode["ENOSTR"] = 60] = "ENOSTR";
|
|
92
|
-
/** No data available */
|
|
93
|
-
ErrorCode[ErrorCode["ENODATA"] = 61] = "ENODATA";
|
|
94
|
-
/** Timer expired */
|
|
95
|
-
ErrorCode[ErrorCode["ETIME"] = 62] = "ETIME";
|
|
96
|
-
/** Out of streams resources */
|
|
97
|
-
ErrorCode[ErrorCode["ENOSR"] = 63] = "ENOSR";
|
|
98
|
-
/** Machine is not on the network */
|
|
99
|
-
ErrorCode[ErrorCode["ENONET"] = 64] = "ENONET";
|
|
100
|
-
/** Object is remote */
|
|
101
|
-
ErrorCode[ErrorCode["EREMOTE"] = 66] = "EREMOTE";
|
|
102
|
-
/** Link has been severed */
|
|
103
|
-
ErrorCode[ErrorCode["ENOLINK"] = 67] = "ENOLINK";
|
|
104
|
-
/** Communication error on send */
|
|
105
|
-
ErrorCode[ErrorCode["ECOMM"] = 70] = "ECOMM";
|
|
106
|
-
/** Protocol error */
|
|
107
|
-
ErrorCode[ErrorCode["EPROTO"] = 71] = "EPROTO";
|
|
108
|
-
/** Bad message */
|
|
109
|
-
ErrorCode[ErrorCode["EBADMSG"] = 74] = "EBADMSG";
|
|
110
|
-
/** Value too large for defined data type */
|
|
111
|
-
ErrorCode[ErrorCode["EOVERFLOW"] = 75] = "EOVERFLOW";
|
|
112
|
-
/** File descriptor in bad state */
|
|
113
|
-
ErrorCode[ErrorCode["EBADFD"] = 77] = "EBADFD";
|
|
114
|
-
/** Streams pipe error */
|
|
115
|
-
ErrorCode[ErrorCode["ESTRPIPE"] = 86] = "ESTRPIPE";
|
|
116
|
-
/** Socket operation on non-socket */
|
|
117
|
-
ErrorCode[ErrorCode["ENOTSOCK"] = 88] = "ENOTSOCK";
|
|
118
|
-
/** Destination address required */
|
|
119
|
-
ErrorCode[ErrorCode["EDESTADDRREQ"] = 89] = "EDESTADDRREQ";
|
|
120
|
-
/** Message too long */
|
|
121
|
-
ErrorCode[ErrorCode["EMSGSIZE"] = 90] = "EMSGSIZE";
|
|
122
|
-
/** Protocol wrong type for socket */
|
|
123
|
-
ErrorCode[ErrorCode["EPROTOTYPE"] = 91] = "EPROTOTYPE";
|
|
124
|
-
/** Protocol not available */
|
|
125
|
-
ErrorCode[ErrorCode["ENOPROTOOPT"] = 92] = "ENOPROTOOPT";
|
|
126
|
-
/** Protocol not supported */
|
|
127
|
-
ErrorCode[ErrorCode["EPROTONOSUPPORT"] = 93] = "EPROTONOSUPPORT";
|
|
128
|
-
/** Socket type not supported */
|
|
129
|
-
ErrorCode[ErrorCode["ESOCKTNOSUPPORT"] = 94] = "ESOCKTNOSUPPORT";
|
|
130
|
-
/** Operation is not supported */
|
|
131
|
-
ErrorCode[ErrorCode["ENOTSUP"] = 95] = "ENOTSUP";
|
|
132
|
-
/** Network is down */
|
|
133
|
-
ErrorCode[ErrorCode["ENETDOWN"] = 100] = "ENETDOWN";
|
|
134
|
-
/** Network is unreachable */
|
|
135
|
-
ErrorCode[ErrorCode["ENETUNREACH"] = 101] = "ENETUNREACH";
|
|
136
|
-
/** Network dropped connection on reset */
|
|
137
|
-
ErrorCode[ErrorCode["ENETRESET"] = 102] = "ENETRESET";
|
|
138
|
-
/** Connection timed out */
|
|
139
|
-
ErrorCode[ErrorCode["ETIMEDOUT"] = 110] = "ETIMEDOUT";
|
|
140
|
-
/** Connection refused */
|
|
141
|
-
ErrorCode[ErrorCode["ECONNREFUSED"] = 111] = "ECONNREFUSED";
|
|
142
|
-
/** Host is down */
|
|
143
|
-
ErrorCode[ErrorCode["EHOSTDOWN"] = 112] = "EHOSTDOWN";
|
|
144
|
-
/** No route to host */
|
|
145
|
-
ErrorCode[ErrorCode["EHOSTUNREACH"] = 113] = "EHOSTUNREACH";
|
|
146
|
-
/** Operation already in progress */
|
|
147
|
-
ErrorCode[ErrorCode["EALREADY"] = 114] = "EALREADY";
|
|
148
|
-
/** Operation now in progress */
|
|
149
|
-
ErrorCode[ErrorCode["EINPROGRESS"] = 115] = "EINPROGRESS";
|
|
150
|
-
/** Stale file handle */
|
|
151
|
-
ErrorCode[ErrorCode["ESTALE"] = 116] = "ESTALE";
|
|
152
|
-
/** Remote I/O error */
|
|
153
|
-
ErrorCode[ErrorCode["EREMOTEIO"] = 121] = "EREMOTEIO";
|
|
154
|
-
/** Disk quota exceeded */
|
|
155
|
-
ErrorCode[ErrorCode["EDQUOT"] = 122] = "EDQUOT";
|
|
156
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
157
|
-
/**
|
|
158
|
-
* Strings associated with each error code.
|
|
159
|
-
* @internal
|
|
160
|
-
*/
|
|
161
|
-
export const errorMessages = {
|
|
162
|
-
[ErrorCode.EPERM]: 'Operation not permitted',
|
|
163
|
-
[ErrorCode.ENOENT]: 'No such file or directory',
|
|
164
|
-
[ErrorCode.EINTR]: 'Interrupted system call',
|
|
165
|
-
[ErrorCode.EIO]: 'Input/output error',
|
|
166
|
-
[ErrorCode.ENXIO]: 'No such device or address',
|
|
167
|
-
[ErrorCode.EBADF]: 'Bad file descriptor',
|
|
168
|
-
[ErrorCode.EAGAIN]: 'Resource temporarily unavailable',
|
|
169
|
-
[ErrorCode.ENOMEM]: 'Cannot allocate memory',
|
|
170
|
-
[ErrorCode.EACCES]: 'Permission denied',
|
|
171
|
-
[ErrorCode.EFAULT]: 'Bad address',
|
|
172
|
-
[ErrorCode.ENOTBLK]: 'Block device required',
|
|
173
|
-
[ErrorCode.EBUSY]: 'Resource busy or locked',
|
|
174
|
-
[ErrorCode.EEXIST]: 'File exists',
|
|
175
|
-
[ErrorCode.EXDEV]: 'Invalid cross-device link',
|
|
176
|
-
[ErrorCode.ENODEV]: 'No such device',
|
|
177
|
-
[ErrorCode.ENOTDIR]: 'File is not a directory',
|
|
178
|
-
[ErrorCode.EISDIR]: 'File is a directory',
|
|
179
|
-
[ErrorCode.EINVAL]: 'Invalid argument',
|
|
180
|
-
[ErrorCode.ENFILE]: 'Too many open files in system',
|
|
181
|
-
[ErrorCode.EMFILE]: 'Too many open files',
|
|
182
|
-
[ErrorCode.ETXTBSY]: 'Text file busy',
|
|
183
|
-
[ErrorCode.EFBIG]: 'File is too big',
|
|
184
|
-
[ErrorCode.ENOSPC]: 'No space left on disk',
|
|
185
|
-
[ErrorCode.ESPIPE]: 'Illegal seek',
|
|
186
|
-
[ErrorCode.EROFS]: 'Cannot modify a read-only file system',
|
|
187
|
-
[ErrorCode.EMLINK]: 'Too many links',
|
|
188
|
-
[ErrorCode.EPIPE]: 'Broken pipe',
|
|
189
|
-
[ErrorCode.EDOM]: 'Numerical argument out of domain',
|
|
190
|
-
[ErrorCode.ERANGE]: 'Numerical result out of range',
|
|
191
|
-
[ErrorCode.EDEADLK]: 'Resource deadlock would occur',
|
|
192
|
-
[ErrorCode.ENAMETOOLONG]: 'File name too long',
|
|
193
|
-
[ErrorCode.ENOLCK]: 'No locks available',
|
|
194
|
-
[ErrorCode.ENOSYS]: 'Function not implemented',
|
|
195
|
-
[ErrorCode.ENOTEMPTY]: 'Directory is not empty',
|
|
196
|
-
[ErrorCode.ELOOP]: 'Too many levels of symbolic links',
|
|
197
|
-
[ErrorCode.ENOMSG]: 'No message of desired type',
|
|
198
|
-
[ErrorCode.EBADE]: 'Invalid exchange',
|
|
199
|
-
[ErrorCode.EBADR]: 'Invalid request descriptor',
|
|
200
|
-
[ErrorCode.EXFULL]: 'Exchange full',
|
|
201
|
-
[ErrorCode.ENOANO]: 'No anode',
|
|
202
|
-
[ErrorCode.EBADRQC]: 'Invalid request code',
|
|
203
|
-
[ErrorCode.ENOSTR]: 'Device not a stream',
|
|
204
|
-
[ErrorCode.ENODATA]: 'No data available',
|
|
205
|
-
[ErrorCode.ETIME]: 'Timer expired',
|
|
206
|
-
[ErrorCode.ENOSR]: 'Out of streams resources',
|
|
207
|
-
[ErrorCode.ENONET]: 'Machine is not on the network',
|
|
208
|
-
[ErrorCode.EREMOTE]: 'Object is remote',
|
|
209
|
-
[ErrorCode.ENOLINK]: 'Link has been severed',
|
|
210
|
-
[ErrorCode.ECOMM]: 'Communication error on send',
|
|
211
|
-
[ErrorCode.EPROTO]: 'Protocol error',
|
|
212
|
-
[ErrorCode.EBADMSG]: 'Bad message',
|
|
213
|
-
[ErrorCode.EOVERFLOW]: 'Value too large for defined data type',
|
|
214
|
-
[ErrorCode.EBADFD]: 'File descriptor in bad state',
|
|
215
|
-
[ErrorCode.ESTRPIPE]: 'Streams pipe error',
|
|
216
|
-
[ErrorCode.ENOTSOCK]: 'Socket operation on non-socket',
|
|
217
|
-
[ErrorCode.EDESTADDRREQ]: 'Destination address required',
|
|
218
|
-
[ErrorCode.EMSGSIZE]: 'Message too long',
|
|
219
|
-
[ErrorCode.EPROTOTYPE]: 'Protocol wrong type for socket',
|
|
220
|
-
[ErrorCode.ENOPROTOOPT]: 'Protocol not available',
|
|
221
|
-
[ErrorCode.EPROTONOSUPPORT]: 'Protocol not supported',
|
|
222
|
-
[ErrorCode.ESOCKTNOSUPPORT]: 'Socket type not supported',
|
|
223
|
-
[ErrorCode.ENOTSUP]: 'Operation is not supported',
|
|
224
|
-
[ErrorCode.ENETDOWN]: 'Network is down',
|
|
225
|
-
[ErrorCode.ENETUNREACH]: 'Network is unreachable',
|
|
226
|
-
[ErrorCode.ENETRESET]: 'Network dropped connection on reset',
|
|
227
|
-
[ErrorCode.ETIMEDOUT]: 'Connection timed out',
|
|
228
|
-
[ErrorCode.ECONNREFUSED]: 'Connection refused',
|
|
229
|
-
[ErrorCode.EHOSTDOWN]: 'Host is down',
|
|
230
|
-
[ErrorCode.EHOSTUNREACH]: 'No route to host',
|
|
231
|
-
[ErrorCode.EALREADY]: 'Operation already in progress',
|
|
232
|
-
[ErrorCode.EINPROGRESS]: 'Operation now in progress',
|
|
233
|
-
[ErrorCode.ESTALE]: 'Stale file handle',
|
|
234
|
-
[ErrorCode.EREMOTEIO]: 'Remote I/O error',
|
|
235
|
-
[ErrorCode.EDQUOT]: 'Disk quota exceeded',
|
|
236
|
-
};
|
|
237
|
-
/**
|
|
238
|
-
* Represents a ZenFS error. Passed back to applications after a failed
|
|
239
|
-
* call to the ZenFS API.
|
|
240
|
-
*/
|
|
241
|
-
export class ApiError extends Error {
|
|
242
|
-
static fromJSON(json) {
|
|
243
|
-
const err = new ApiError(json.errno, json.message, json.path, json.syscall);
|
|
244
|
-
err.code = json.code;
|
|
245
|
-
err.stack = json.stack;
|
|
246
|
-
return err;
|
|
247
|
-
}
|
|
248
|
-
static With(code, path, syscall) {
|
|
249
|
-
return new ApiError(ErrorCode[code], errorMessages[ErrorCode[code]], path, syscall);
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* Represents a ZenFS error. Passed back to applications after a failed
|
|
253
|
-
* call to the ZenFS API.
|
|
254
|
-
*
|
|
255
|
-
* Error codes mirror those returned by regular Unix file operations, which is
|
|
256
|
-
* what Node returns.
|
|
257
|
-
* @constructor ApiError
|
|
258
|
-
* @param type The type of the error.
|
|
259
|
-
* @param message A descriptive error message.
|
|
260
|
-
*/
|
|
261
|
-
constructor(errno, message = errorMessages[errno], path, syscall = '') {
|
|
262
|
-
super(message);
|
|
263
|
-
this.errno = errno;
|
|
264
|
-
this.path = path;
|
|
265
|
-
this.syscall = syscall;
|
|
266
|
-
this.code = ErrorCode[errno];
|
|
267
|
-
this.message = `${this.code}: ${message}${this.path ? `, '${this.path}'` : ''}`;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* @return A friendly error message.
|
|
271
|
-
*/
|
|
272
|
-
toString() {
|
|
273
|
-
return this.message;
|
|
274
|
-
}
|
|
275
|
-
toJSON() {
|
|
276
|
-
return {
|
|
277
|
-
errno: this.errno,
|
|
278
|
-
code: this.code,
|
|
279
|
-
path: this.path,
|
|
280
|
-
stack: this.stack,
|
|
281
|
-
message: this.message,
|
|
282
|
-
syscall: this.syscall,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* The size of the API error in buffer-form in bytes.
|
|
287
|
-
*/
|
|
288
|
-
bufferSize() {
|
|
289
|
-
// 4 bytes for string length.
|
|
290
|
-
return 4 + JSON.stringify(this.toJSON()).length;
|
|
291
|
-
}
|
|
292
|
-
}
|