@spinajs/fs 2.0.38
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/lib/exceptions/src/index.d.ts +85 -0
- package/lib/exceptions/src/index.js +106 -0
- package/lib/exceptions/src/index.js.map +1 -0
- package/lib/fs/src/index.d.ts +110 -0
- package/lib/fs/src/index.js +170 -0
- package/lib/fs/src/index.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class of all exceptions in framework
|
|
3
|
+
*/
|
|
4
|
+
export declare class Exception extends Error {
|
|
5
|
+
inner?: Error;
|
|
6
|
+
/**
|
|
7
|
+
* Constructs new exception with message
|
|
8
|
+
*
|
|
9
|
+
* @param message - error message
|
|
10
|
+
* @param inner - inner exception ( eg. original couse of error )
|
|
11
|
+
*/
|
|
12
|
+
constructor(message?: string, inner?: Error);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Exception thrown when functionality is not supported
|
|
16
|
+
*/
|
|
17
|
+
export declare class NotSupported extends Exception {
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Exception thrown when argument passed to function is invalid eg. out of range
|
|
21
|
+
*/
|
|
22
|
+
export declare class InvalidArgument extends Exception {
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Exception thrown when config option is invalidl eg. missing or in invalid format
|
|
26
|
+
*/
|
|
27
|
+
export declare class InvalidOption extends Exception {
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The exception that is thrown when a method call is invalid for the object's current state.
|
|
31
|
+
*/
|
|
32
|
+
export declare class InvalidOperation extends Exception {
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Exception is thrown when authentication fails eg. user credentials are invalid
|
|
36
|
+
*/
|
|
37
|
+
export declare class AuthenticationFailed extends Exception {
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Exception is thrown when request data are invalid
|
|
41
|
+
*/
|
|
42
|
+
export declare class BadRequest extends Exception {
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Exception indicating that an access to resource by a client has been forbidden by the server
|
|
46
|
+
* HTTP 403 - Forbidden
|
|
47
|
+
*/
|
|
48
|
+
export declare class Forbidden extends Exception {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Exception thrown when there was error with IO operations ie. not accessible file
|
|
52
|
+
*/
|
|
53
|
+
export declare class IOFail extends Exception {
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The exception that is thrown when resource is not found eg. model in database or missing file
|
|
57
|
+
*/
|
|
58
|
+
export declare class ResourceNotFound extends Exception {
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The exception that is thrown when method is not implemented
|
|
62
|
+
*/
|
|
63
|
+
export declare class MethodNotImplemented extends Exception {
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The exception that is thrown when strange things happends in server eg. generic server error
|
|
67
|
+
*/
|
|
68
|
+
export declare class UnexpectedServerError extends Exception {
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Exception occurs when resource is duplicated eg. unique constraint failed in db
|
|
72
|
+
*/
|
|
73
|
+
export declare class ResourceDuplicated extends Exception {
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The exception that is thrown when JSON entity is checked against schema and is invalid
|
|
77
|
+
*/
|
|
78
|
+
export declare class JsonValidationFailed extends Exception {
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The exception that is thrown if app not supports requestes `Accept` header eg. if client wants
|
|
82
|
+
* html response but server can send only json.
|
|
83
|
+
*/
|
|
84
|
+
export declare class ExpectedResponseUnacceptable extends Exception {
|
|
85
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExpectedResponseUnacceptable = exports.JsonValidationFailed = exports.ResourceDuplicated = exports.UnexpectedServerError = exports.MethodNotImplemented = exports.ResourceNotFound = exports.IOFail = exports.Forbidden = exports.BadRequest = exports.AuthenticationFailed = exports.InvalidOperation = exports.InvalidOption = exports.InvalidArgument = exports.NotSupported = exports.Exception = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base class of all exceptions in framework
|
|
6
|
+
*/
|
|
7
|
+
class Exception extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Constructs new exception with message
|
|
10
|
+
*
|
|
11
|
+
* @param message - error message
|
|
12
|
+
* @param inner - inner exception ( eg. original couse of error )
|
|
13
|
+
*/
|
|
14
|
+
constructor(message, inner) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.inner = inner;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.Exception = Exception;
|
|
20
|
+
/**
|
|
21
|
+
* Exception thrown when functionality is not supported
|
|
22
|
+
*/
|
|
23
|
+
class NotSupported extends Exception {
|
|
24
|
+
}
|
|
25
|
+
exports.NotSupported = NotSupported;
|
|
26
|
+
/**
|
|
27
|
+
* Exception thrown when argument passed to function is invalid eg. out of range
|
|
28
|
+
*/
|
|
29
|
+
class InvalidArgument extends Exception {
|
|
30
|
+
}
|
|
31
|
+
exports.InvalidArgument = InvalidArgument;
|
|
32
|
+
/**
|
|
33
|
+
* Exception thrown when config option is invalidl eg. missing or in invalid format
|
|
34
|
+
*/
|
|
35
|
+
class InvalidOption extends Exception {
|
|
36
|
+
}
|
|
37
|
+
exports.InvalidOption = InvalidOption;
|
|
38
|
+
/**
|
|
39
|
+
* The exception that is thrown when a method call is invalid for the object's current state.
|
|
40
|
+
*/
|
|
41
|
+
class InvalidOperation extends Exception {
|
|
42
|
+
}
|
|
43
|
+
exports.InvalidOperation = InvalidOperation;
|
|
44
|
+
/**
|
|
45
|
+
* Exception is thrown when authentication fails eg. user credentials are invalid
|
|
46
|
+
*/
|
|
47
|
+
class AuthenticationFailed extends Exception {
|
|
48
|
+
}
|
|
49
|
+
exports.AuthenticationFailed = AuthenticationFailed;
|
|
50
|
+
/**
|
|
51
|
+
* Exception is thrown when request data are invalid
|
|
52
|
+
*/
|
|
53
|
+
class BadRequest extends Exception {
|
|
54
|
+
}
|
|
55
|
+
exports.BadRequest = BadRequest;
|
|
56
|
+
/**
|
|
57
|
+
* Exception indicating that an access to resource by a client has been forbidden by the server
|
|
58
|
+
* HTTP 403 - Forbidden
|
|
59
|
+
*/
|
|
60
|
+
class Forbidden extends Exception {
|
|
61
|
+
}
|
|
62
|
+
exports.Forbidden = Forbidden;
|
|
63
|
+
/**
|
|
64
|
+
* Exception thrown when there was error with IO operations ie. not accessible file
|
|
65
|
+
*/
|
|
66
|
+
class IOFail extends Exception {
|
|
67
|
+
}
|
|
68
|
+
exports.IOFail = IOFail;
|
|
69
|
+
/**
|
|
70
|
+
* The exception that is thrown when resource is not found eg. model in database or missing file
|
|
71
|
+
*/
|
|
72
|
+
class ResourceNotFound extends Exception {
|
|
73
|
+
}
|
|
74
|
+
exports.ResourceNotFound = ResourceNotFound;
|
|
75
|
+
/**
|
|
76
|
+
* The exception that is thrown when method is not implemented
|
|
77
|
+
*/
|
|
78
|
+
class MethodNotImplemented extends Exception {
|
|
79
|
+
}
|
|
80
|
+
exports.MethodNotImplemented = MethodNotImplemented;
|
|
81
|
+
/**
|
|
82
|
+
* The exception that is thrown when strange things happends in server eg. generic server error
|
|
83
|
+
*/
|
|
84
|
+
class UnexpectedServerError extends Exception {
|
|
85
|
+
}
|
|
86
|
+
exports.UnexpectedServerError = UnexpectedServerError;
|
|
87
|
+
/**
|
|
88
|
+
* Exception occurs when resource is duplicated eg. unique constraint failed in db
|
|
89
|
+
*/
|
|
90
|
+
class ResourceDuplicated extends Exception {
|
|
91
|
+
}
|
|
92
|
+
exports.ResourceDuplicated = ResourceDuplicated;
|
|
93
|
+
/**
|
|
94
|
+
* The exception that is thrown when JSON entity is checked against schema and is invalid
|
|
95
|
+
*/
|
|
96
|
+
class JsonValidationFailed extends Exception {
|
|
97
|
+
}
|
|
98
|
+
exports.JsonValidationFailed = JsonValidationFailed;
|
|
99
|
+
/**
|
|
100
|
+
* The exception that is thrown if app not supports requestes `Accept` header eg. if client wants
|
|
101
|
+
* html response but server can send only json.
|
|
102
|
+
*/
|
|
103
|
+
class ExpectedResponseUnacceptable extends Exception {
|
|
104
|
+
}
|
|
105
|
+
exports.ExpectedResponseUnacceptable = ExpectedResponseUnacceptable;
|
|
106
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../exceptions/src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAa,SAAU,SAAQ,KAAK;IAClC;;;;;OAKG;IACH,YAAY,OAAgB,EAAS,KAAa;QAChD,KAAK,CAAC,OAAO,CAAC,CAAC;QADoB,UAAK,GAAL,KAAK,CAAQ;IAElD,CAAC;CACF;AAVD,8BAUC;AAED;;GAEG;AACH,MAAa,YAAa,SAAQ,SAAS;CAAG;AAA9C,oCAA8C;AAE9C;;GAEG;AACH,MAAa,eAAgB,SAAQ,SAAS;CAAG;AAAjD,0CAAiD;AAEjD;;GAEG;AACH,MAAa,aAAc,SAAQ,SAAS;CAAG;AAA/C,sCAA+C;AAE/C;;GAEG;AACH,MAAa,gBAAiB,SAAQ,SAAS;CAAG;AAAlD,4CAAkD;AAElD;;GAEG;AACH,MAAa,oBAAqB,SAAQ,SAAS;CAAG;AAAtD,oDAAsD;AAEtD;;GAEG;AACH,MAAa,UAAW,SAAQ,SAAS;CAAG;AAA5C,gCAA4C;AAE5C;;;GAGG;AACH,MAAa,SAAU,SAAQ,SAAS;CAAG;AAA3C,8BAA2C;AAE3C;;GAEG;AACH,MAAa,MAAO,SAAQ,SAAS;CAAG;AAAxC,wBAAwC;AAExC;;GAEG;AACH,MAAa,gBAAiB,SAAQ,SAAS;CAAG;AAAlD,4CAAkD;AAElD;;GAEG;AACH,MAAa,oBAAqB,SAAQ,SAAS;CAAG;AAAtD,oDAAsD;AAEtD;;GAEG;AACH,MAAa,qBAAsB,SAAQ,SAAS;CAAG;AAAvD,sDAAuD;AAEvD;;GAEG;AACH,MAAa,kBAAmB,SAAQ,SAAS;CAAG;AAApD,gDAAoD;AAEpD;;GAEG;AACH,MAAa,oBAAqB,SAAQ,SAAS;CAAG;AAAtD,oDAAsD;AAEtD;;;GAGG;AACH,MAAa,4BAA6B,SAAQ,SAAS;CAAG;AAA9D,oEAA8D"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { PathLike, ReadStream, WriteStream } from 'fs';
|
|
4
|
+
import { DateTime } from 'luxon';
|
|
5
|
+
export interface IStat {
|
|
6
|
+
IsDirectory?: boolean;
|
|
7
|
+
IsFile?: boolean;
|
|
8
|
+
Size?: number;
|
|
9
|
+
AccessTime?: DateTime;
|
|
10
|
+
ModifiedTime?: DateTime;
|
|
11
|
+
CreationTime?: DateTime;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class fs {
|
|
14
|
+
abstract get Provider(): string;
|
|
15
|
+
abstract download(path: PathLike): Promise<string>;
|
|
16
|
+
abstract read(path: string, encoding: BufferEncoding): Promise<string>;
|
|
17
|
+
abstract readStream(path: string): Promise<ReadStream>;
|
|
18
|
+
abstract write(path: string, data: string | Buffer, encoding: BufferEncoding): Promise<void>;
|
|
19
|
+
abstract writeStream(path: string): Promise<WriteStream>;
|
|
20
|
+
abstract exists(path: PathLike): Promise<boolean>;
|
|
21
|
+
abstract dirExists(path: PathLike): Promise<boolean>;
|
|
22
|
+
abstract copy(path: string, dest: string): Promise<void>;
|
|
23
|
+
abstract move(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
|
24
|
+
abstract rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
|
25
|
+
abstract unlink(path: PathLike): Promise<void>;
|
|
26
|
+
abstract rm(path: PathLike): Promise<void>;
|
|
27
|
+
abstract mkdir(path: PathLike): Promise<void>;
|
|
28
|
+
abstract stat(path: PathLike): Promise<IStat>;
|
|
29
|
+
abstract list(path: PathLike): Promise<string[]>;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Abstract layer for file operations.
|
|
33
|
+
* Basic implementation is just wrapper for native node fs functions
|
|
34
|
+
*
|
|
35
|
+
* It allows to wrap other libs eg. aws s3, ftp
|
|
36
|
+
* and inject it into code without changing logic that use them.
|
|
37
|
+
*
|
|
38
|
+
* TODO: map errors to some kind of common errors shared with other implementations
|
|
39
|
+
*/
|
|
40
|
+
export declare class fsNative extends fs {
|
|
41
|
+
get Provider(): string;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* Tries to download file to local filesystem, then returns local filesystem path.
|
|
45
|
+
* Native implementation simply returns local path and does nothing.
|
|
46
|
+
*
|
|
47
|
+
* @param path - file to download
|
|
48
|
+
*/
|
|
49
|
+
download(path: PathLike): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* read all content of file
|
|
52
|
+
*/
|
|
53
|
+
read(path: string, encoding: BufferEncoding): Promise<string>;
|
|
54
|
+
readStream(path: string): Promise<ReadStream>;
|
|
55
|
+
/**
|
|
56
|
+
* Write to file string or buffer
|
|
57
|
+
*/
|
|
58
|
+
write(path: string, data: string | Buffer, encoding: BufferEncoding): Promise<void>;
|
|
59
|
+
writeStream(path: string): Promise<WriteStream>;
|
|
60
|
+
/**
|
|
61
|
+
* Checks if file existst
|
|
62
|
+
* @param path - path to check
|
|
63
|
+
*/
|
|
64
|
+
exists(path: PathLike): Promise<boolean>;
|
|
65
|
+
dirExists(path: PathLike): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Copy file to another location
|
|
68
|
+
* @param path - src path
|
|
69
|
+
* @param dest - dest path
|
|
70
|
+
*/
|
|
71
|
+
copy(path: string, dest: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Copy file to another location and deletes src file
|
|
74
|
+
*/
|
|
75
|
+
move(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Change name of a file
|
|
78
|
+
*/
|
|
79
|
+
rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Deletes file permanently
|
|
82
|
+
*
|
|
83
|
+
* @param path - path to file that will be deleted
|
|
84
|
+
*/
|
|
85
|
+
unlink(path: PathLike): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
*
|
|
88
|
+
* Deletes dir recursively & all contents inside
|
|
89
|
+
*
|
|
90
|
+
* @param path - dir to remove
|
|
91
|
+
*/
|
|
92
|
+
rm(path: PathLike): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
* Creates directory, recursively
|
|
96
|
+
*
|
|
97
|
+
* @param path - directory to create
|
|
98
|
+
*/
|
|
99
|
+
mkdir(path: PathLike): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Returns file statistics, not all fields may be accesible
|
|
102
|
+
*/
|
|
103
|
+
stat(path: PathLike): Promise<IStat>;
|
|
104
|
+
/**
|
|
105
|
+
* List content of directory
|
|
106
|
+
*
|
|
107
|
+
* @param path - path to directory
|
|
108
|
+
*/
|
|
109
|
+
list(path: PathLike): Promise<string[]>;
|
|
110
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.fsNative = exports.fs = void 0;
|
|
10
|
+
/* eslint-disable security/detect-non-literal-fs-filename */
|
|
11
|
+
const index_1 = require("./../../exceptions/src/index");
|
|
12
|
+
const fs_1 = require("fs");
|
|
13
|
+
const promises_1 = require("node:fs/promises");
|
|
14
|
+
const luxon_1 = require("luxon");
|
|
15
|
+
const di_1 = require("@spinajs/di");
|
|
16
|
+
class fs {
|
|
17
|
+
}
|
|
18
|
+
exports.fs = fs;
|
|
19
|
+
/**
|
|
20
|
+
* Abstract layer for file operations.
|
|
21
|
+
* Basic implementation is just wrapper for native node fs functions
|
|
22
|
+
*
|
|
23
|
+
* It allows to wrap other libs eg. aws s3, ftp
|
|
24
|
+
* and inject it into code without changing logic that use them.
|
|
25
|
+
*
|
|
26
|
+
* TODO: map errors to some kind of common errors shared with other implementations
|
|
27
|
+
*/
|
|
28
|
+
let fsNative = class fsNative extends fs {
|
|
29
|
+
get Provider() {
|
|
30
|
+
return 'fs-local';
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* Tries to download file to local filesystem, then returns local filesystem path.
|
|
35
|
+
* Native implementation simply returns local path and does nothing.
|
|
36
|
+
*
|
|
37
|
+
* @param path - file to download
|
|
38
|
+
*/
|
|
39
|
+
async download(path) {
|
|
40
|
+
const exists = await this.exists(path);
|
|
41
|
+
if (!exists) {
|
|
42
|
+
throw new index_1.IOFail(`file ${path} does not exists`);
|
|
43
|
+
}
|
|
44
|
+
return path;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* read all content of file
|
|
48
|
+
*/
|
|
49
|
+
async read(path, encoding) {
|
|
50
|
+
const fDesc = await (0, promises_1.open)(path, 'r');
|
|
51
|
+
return fDesc.readFile({ encoding });
|
|
52
|
+
}
|
|
53
|
+
async readStream(path) {
|
|
54
|
+
const fDesc = await (0, promises_1.open)(path, 'r');
|
|
55
|
+
return fDesc.createReadStream();
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Write to file string or buffer
|
|
59
|
+
*/
|
|
60
|
+
async write(path, data, encoding) {
|
|
61
|
+
const fDesc = await (0, promises_1.open)(path, 'w');
|
|
62
|
+
return await fDesc.writeFile(data, { encoding });
|
|
63
|
+
}
|
|
64
|
+
async writeStream(path) {
|
|
65
|
+
const fDesc = await (0, promises_1.open)(path, 'w');
|
|
66
|
+
return fDesc.createWriteStream();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks if file existst
|
|
70
|
+
* @param path - path to check
|
|
71
|
+
*/
|
|
72
|
+
async exists(path) {
|
|
73
|
+
try {
|
|
74
|
+
await (0, promises_1.access)(path, fs_1.constants.F_OK);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
catch (_a) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async dirExists(path) {
|
|
82
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
83
|
+
return this.exists(path);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Copy file to another location
|
|
87
|
+
* @param path - src path
|
|
88
|
+
* @param dest - dest path
|
|
89
|
+
*/
|
|
90
|
+
async copy(path, dest) {
|
|
91
|
+
await (0, promises_1.copyFile)(path, dest);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Copy file to another location and deletes src file
|
|
95
|
+
*/
|
|
96
|
+
async move(oldPath, newPath) {
|
|
97
|
+
try {
|
|
98
|
+
await (0, promises_1.rename)(oldPath, newPath);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
102
|
+
if (err.code === 'EXDEV') {
|
|
103
|
+
await (0, promises_1.copyFile)(oldPath, newPath);
|
|
104
|
+
await (0, promises_1.unlink)(oldPath);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Change name of a file
|
|
113
|
+
*/
|
|
114
|
+
async rename(oldPath, newPath) {
|
|
115
|
+
await (0, promises_1.rename)(oldPath, newPath);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Deletes file permanently
|
|
119
|
+
*
|
|
120
|
+
* @param path - path to file that will be deleted
|
|
121
|
+
*/
|
|
122
|
+
async unlink(path) {
|
|
123
|
+
await (0, promises_1.unlink)(path);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
*
|
|
127
|
+
* Deletes dir recursively & all contents inside
|
|
128
|
+
*
|
|
129
|
+
* @param path - dir to remove
|
|
130
|
+
*/
|
|
131
|
+
async rm(path) {
|
|
132
|
+
await (0, promises_1.rm)(path, { recursive: true, force: true, maxRetries: 3, retryDelay: 1000 });
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
*
|
|
136
|
+
* Creates directory, recursively
|
|
137
|
+
*
|
|
138
|
+
* @param path - directory to create
|
|
139
|
+
*/
|
|
140
|
+
async mkdir(path) {
|
|
141
|
+
await (0, promises_1.mkdir)(path, { recursive: true });
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Returns file statistics, not all fields may be accesible
|
|
145
|
+
*/
|
|
146
|
+
async stat(path) {
|
|
147
|
+
const result = await (0, promises_1.stat)(path);
|
|
148
|
+
return {
|
|
149
|
+
IsDirectory: result.isDirectory(),
|
|
150
|
+
IsFile: result.isFile(),
|
|
151
|
+
CreationTime: luxon_1.DateTime.fromJSDate(result.ctime),
|
|
152
|
+
ModifiedTime: luxon_1.DateTime.fromJSDate(result.mtime),
|
|
153
|
+
AccessTime: luxon_1.DateTime.fromJSDate(result.atime),
|
|
154
|
+
Size: result.size,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* List content of directory
|
|
159
|
+
*
|
|
160
|
+
* @param path - path to directory
|
|
161
|
+
*/
|
|
162
|
+
async list(path) {
|
|
163
|
+
return await (0, promises_1.readdir)(path);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
fsNative = __decorate([
|
|
167
|
+
(0, di_1.Injectable)('fs')
|
|
168
|
+
], fsNative);
|
|
169
|
+
exports.fsNative = fsNative;
|
|
170
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;;;;AAAA,4DAA4D;AAC5D,wDAAsD;AACtD,2BAAkE;AAClE,+CAAoG;AACpG,iCAAiC;AACjC,oCAAyC;AAWzC,MAAsB,EAAE;CAiBvB;AAjBD,gBAiBC;AAED;;;;;;;;GAQG;AAEH,IAAa,QAAQ,GAArB,MAAa,QAAS,SAAQ,EAAE;IAC9B,IAAW,QAAQ;QACjB,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,QAAQ,CAAC,IAAc;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,cAAM,CAAC,QAAQ,IAAc,kBAAkB,CAAC,CAAC;SAC5D;QACD,OAAO,IAAc,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,QAAwB;QACtD,MAAM,KAAK,GAAG,MAAM,IAAA,eAAI,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACpC,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;IACtC,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,IAAY;QAClC,MAAM,KAAK,GAAG,MAAM,IAAA,eAAI,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC;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CAAC,IAAI,CAAC,IAAc;QAC9B,OAAO,MAAM,IAAA,kBAAO,EAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF,CAAA;AAtJY,QAAQ;IADpB,IAAA,eAAU,EAAC,IAAI,CAAC;GACJ,QAAQ,CAsJpB;AAtJY,4BAAQ"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spinajs/fs",
|
|
3
|
+
"version": "2.0.38",
|
|
4
|
+
"description": "wrapper for file operations",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"private": false,
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
|
|
9
|
+
"coverage": "nyc npm run test",
|
|
10
|
+
"build-docs": "rimraf docs && typedoc --options typedoc.json src/",
|
|
11
|
+
"build": "npm run clean && npm run compile",
|
|
12
|
+
"compile": "tsc -p tsconfig.build.json",
|
|
13
|
+
"clean": "",
|
|
14
|
+
"prepare": "npm run build",
|
|
15
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
|
16
|
+
"lint": "eslint -c .eslintrc.js --ext .ts src",
|
|
17
|
+
"prepublishOnly": "npm run lint",
|
|
18
|
+
"preversion": "npm run lint",
|
|
19
|
+
"version": "npm run format && git add -A src",
|
|
20
|
+
"postversion": "git push && git push --tags"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"lib/**/*"
|
|
24
|
+
],
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/spinajs/exceptions.git"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"di",
|
|
31
|
+
"container",
|
|
32
|
+
"spinajs",
|
|
33
|
+
"di"
|
|
34
|
+
],
|
|
35
|
+
"author": "SpinaJS <spinajs@coderush.pl> (https://github.com/spinajs/core)",
|
|
36
|
+
"license": "MIT",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/spinajs/exceptions/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/spinajs/exceptions#readme",
|
|
41
|
+
"gitHead": "5ea5440ee9db49595f531592ebdbc6d69f457082",
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"lodash": "^4.17.21",
|
|
44
|
+
"luxon": "^3.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/luxon": "^3.0.1"
|
|
48
|
+
}
|
|
49
|
+
}
|