gyomu 0.1.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/lib/archive/abstract.d.ts +7 -0
- package/lib/archive/abstract.js +30 -0
- package/lib/archive/gz.d.ts +16 -0
- package/lib/archive/gz.js +66 -0
- package/lib/archive/index.d.ts +3 -0
- package/lib/archive/index.js +19 -0
- package/lib/archive/tar.d.ts +17 -0
- package/lib/archive/tar.js +165 -0
- package/lib/archive/zip.d.ts +28 -0
- package/lib/archive/zip.js +254 -0
- package/lib/base64.d.ts +6 -0
- package/lib/base64.js +24 -0
- package/lib/buffer.d.ts +4 -0
- package/lib/buffer.js +23 -0
- package/lib/configurator.d.ts +16 -0
- package/lib/configurator.js +53 -0
- package/lib/dateOperation.d.ts +3 -0
- package/lib/dateOperation.js +23 -0
- package/lib/dbsingleton.d.ts +11 -0
- package/lib/dbsingleton.js +13 -0
- package/lib/dbutil.d.ts +3 -0
- package/lib/dbutil.js +44 -0
- package/lib/dictionary.d.ts +8 -0
- package/lib/dictionary.js +55 -0
- package/lib/encryption.d.ts +17 -0
- package/lib/encryption.js +202 -0
- package/lib/errors.d.ts +31 -0
- package/lib/errors.js +64 -0
- package/lib/excel.d.ts +1 -0
- package/lib/excel.js +34 -0
- package/lib/fileModel.d.ts +96 -0
- package/lib/fileModel.js +170 -0
- package/lib/fileOperation.d.ts +11 -0
- package/lib/fileOperation.js +275 -0
- package/lib/holidays.d.ts +20 -0
- package/lib/holidays.js +200 -0
- package/lib/index.d.ts +15 -0
- package/lib/index.js +31 -0
- package/lib/milestone.d.ts +19 -0
- package/lib/milestone.js +169 -0
- package/lib/net/_ftp.d.ts +0 -0
- package/lib/net/_ftp.js +228 -0
- package/lib/net/ftp.d.ts +19 -0
- package/lib/net/ftp.js +160 -0
- package/lib/net/remoteConnection.d.ts +11 -0
- package/lib/net/remoteConnection.js +26 -0
- package/lib/net/sftp.d.ts +19 -0
- package/lib/net/sftp.js +155 -0
- package/lib/numberOperation.d.ts +3 -0
- package/lib/numberOperation.js +24 -0
- package/lib/parameter.d.ts +14 -0
- package/lib/parameter.js +291 -0
- package/lib/result.d.ts +23 -0
- package/lib/result.js +47 -0
- package/lib/timer.d.ts +11 -0
- package/lib/timer.js +62 -0
- package/lib/user.d.ts +11 -0
- package/lib/user.js +23 -0
- package/lib/variable.d.ts +11 -0
- package/lib/variable.js +280 -0
- package/lib/web/attribute.d.ts +6 -0
- package/lib/web/attribute.js +29 -0
- package/lib/web/element.d.ts +24 -0
- package/lib/web/element.js +119 -0
- package/lib/web/index.d.ts +7 -0
- package/lib/web/index.js +19 -0
- package/lib/web/page.d.ts +22 -0
- package/lib/web/page.js +102 -0
- package/lib/web/table.d.ts +15 -0
- package/lib/web/table.js +110 -0
- package/lib/web/tableColumn.d.ts +10 -0
- package/lib/web/tableColumn.js +21 -0
- package/lib/web/tableRow.d.ts +10 -0
- package/lib/web/tableRow.js +80 -0
- package/lib/web/util.d.ts +12 -0
- package/lib/web/util.js +22 -0
- package/package.json +63 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
export declare class FileInfo {
|
|
2
|
+
readonly fileName: string;
|
|
3
|
+
readonly fullPath: string;
|
|
4
|
+
readonly directoryName: string;
|
|
5
|
+
readonly directoryPath: string;
|
|
6
|
+
readonly size: number;
|
|
7
|
+
readonly extension: string;
|
|
8
|
+
readonly createTime: Date;
|
|
9
|
+
readonly updateTime: Date;
|
|
10
|
+
readonly lastAccessTime: Date;
|
|
11
|
+
readonly isFile: boolean;
|
|
12
|
+
constructor(filePath: string);
|
|
13
|
+
}
|
|
14
|
+
export declare const FilterType: {
|
|
15
|
+
readonly FileName: "Name";
|
|
16
|
+
readonly CreateTime: "Create Time";
|
|
17
|
+
readonly LastAccessTime: "Last Access Time";
|
|
18
|
+
readonly LastModifiedTime: "Last Modified Time";
|
|
19
|
+
};
|
|
20
|
+
export declare type FilterType = typeof FilterType[keyof typeof FilterType];
|
|
21
|
+
export declare const FileCompareType: {
|
|
22
|
+
readonly Equal: "Equal";
|
|
23
|
+
readonly Larger: "Larger";
|
|
24
|
+
readonly Less: "Less";
|
|
25
|
+
readonly LargerOrEqual: "LargerOrEqual";
|
|
26
|
+
readonly LessOrEqual: "LessOrEqual";
|
|
27
|
+
};
|
|
28
|
+
export declare type FileCompareType = typeof FileCompareType[keyof typeof FileCompareType];
|
|
29
|
+
export declare const FileArchiveType: {
|
|
30
|
+
readonly Zip: "zip";
|
|
31
|
+
readonly Tgz: "tgz";
|
|
32
|
+
readonly BZip2: "bz2";
|
|
33
|
+
readonly GZip: "gz";
|
|
34
|
+
readonly Tar: "tar";
|
|
35
|
+
readonly GuessFromFileName: "unknown";
|
|
36
|
+
};
|
|
37
|
+
export declare type FileArchiveType = typeof FileArchiveType[keyof typeof FileArchiveType];
|
|
38
|
+
export declare class FileFilterInfo {
|
|
39
|
+
readonly kind: FilterType;
|
|
40
|
+
readonly operator: FileCompareType;
|
|
41
|
+
readonly nameFilter: string;
|
|
42
|
+
readonly targetDate: Date;
|
|
43
|
+
constructor(kind: FilterType, operator: FileCompareType, filter: string | Date);
|
|
44
|
+
}
|
|
45
|
+
export declare class FileTransportInfo {
|
|
46
|
+
#private;
|
|
47
|
+
readonly sourceFileName: string;
|
|
48
|
+
readonly sourceFolderName: string;
|
|
49
|
+
readonly basePath: string;
|
|
50
|
+
readonly deleteSourceFileAfterCompletion: boolean;
|
|
51
|
+
readonly overwriteDestination: boolean;
|
|
52
|
+
readonly isSourceDirectory: boolean;
|
|
53
|
+
readonly isDestinationDirectory: boolean;
|
|
54
|
+
readonly isDestinationRoot: boolean;
|
|
55
|
+
readonly filterConditions?: FileFilterInfo[];
|
|
56
|
+
/**
|
|
57
|
+
* Base Sdir Sname Ddir Dname (S)full+base (S)Full (S)path (S)name (D)full (D)path (D)name
|
|
58
|
+
* x x x x x base\SDir\Sname SDir\Sname SDir Sname Ddir\Dname Ddir Dname
|
|
59
|
+
* x x x x base\SDir\Sname SDir\Sname SDir Sname Ddir\Sname Ddir Sname
|
|
60
|
+
* x x x x base\SDir\Sname SDir\Sname SDir Sname SDir\Dname Sdir Dname
|
|
61
|
+
* x x x base\SDir\Sname SDir\Sname SDir Sname SDir\Sname SDir Sname
|
|
62
|
+
* x x x base\SDir SDir SDir Ddir Ddir
|
|
63
|
+
* x x base\SDir SDir SDir SDir SDir
|
|
64
|
+
* x base
|
|
65
|
+
* x x base Ddir Ddir
|
|
66
|
+
* x x x x base\Sname Sname Sname Ddir\Dname Ddir Dname
|
|
67
|
+
* x x x base\Sname Sname Sname Ddir\Sname Ddir Sname
|
|
68
|
+
* x x x base\Sname Sname Sname Dname Dname
|
|
69
|
+
* x x base\Sname Sname Sname Sname Sname
|
|
70
|
+
* x x x x SDir\Sname SDir Sname Ddir\Dname Ddir Dname
|
|
71
|
+
* x x x SDir\Sname SDir Sname Ddir\Sname Ddir Sname
|
|
72
|
+
* x x x SDir\Sname SDir Sname SDir\Dname SDir Dname
|
|
73
|
+
* x x SDir\Sname SDir Sname SDir\Sname SDir Sname
|
|
74
|
+
* x x SDir SDir Ddir Ddir
|
|
75
|
+
* x SDir SDir SDir SDir
|
|
76
|
+
* x x x Sname Sname Ddir\Dname Ddir Dname
|
|
77
|
+
* x x Sname Sname Ddir\Sname Ddir Sname
|
|
78
|
+
* x x Sname Sname Dname Dname
|
|
79
|
+
* x Sname Sname Sname Sname
|
|
80
|
+
*/
|
|
81
|
+
constructor({ basePath, sourceFilename, sourceFolderName, destinationFileName, destinationFolderName, deleteSourceFileAfterCompletion, overwriteDestination, filterConditions, }: {
|
|
82
|
+
basePath?: string;
|
|
83
|
+
sourceFilename?: string;
|
|
84
|
+
sourceFolderName?: string;
|
|
85
|
+
destinationFileName?: string;
|
|
86
|
+
destinationFolderName?: string;
|
|
87
|
+
deleteSourceFileAfterCompletion?: boolean;
|
|
88
|
+
overwriteDestination?: boolean;
|
|
89
|
+
filterConditions?: FileFilterInfo[];
|
|
90
|
+
});
|
|
91
|
+
get sourceFullName(): string;
|
|
92
|
+
get sourceFullNameWithBasePath(): string;
|
|
93
|
+
get destinationFileName(): string;
|
|
94
|
+
get destinationPath(): string;
|
|
95
|
+
get destinationFullName(): string;
|
|
96
|
+
}
|
package/lib/fileModel.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _FileTransportInfo_destinationFileName, _FileTransportInfo_destinationFolderName;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.FileTransportInfo = exports.FileFilterInfo = exports.FileArchiveType = exports.FileCompareType = exports.FilterType = exports.FileInfo = void 0;
|
|
19
|
+
const fs_1 = require("fs");
|
|
20
|
+
const path_1 = __importDefault(require("path"));
|
|
21
|
+
const date_fns_1 = require("date-fns");
|
|
22
|
+
const errors_1 = require("./errors");
|
|
23
|
+
class FileInfo {
|
|
24
|
+
constructor(filePath) {
|
|
25
|
+
//console.log('FileInfo', filePath);
|
|
26
|
+
const stats = (0, fs_1.statSync)(filePath);
|
|
27
|
+
this.isFile = stats.isFile();
|
|
28
|
+
if (this.isFile) {
|
|
29
|
+
this.fileName = path_1.default.basename(filePath);
|
|
30
|
+
this.fullPath = path_1.default.resolve(filePath);
|
|
31
|
+
this.directoryName = path_1.default.basename(path_1.default.dirname(filePath));
|
|
32
|
+
this.directoryPath = path_1.default.dirname(path_1.default.resolve(filePath));
|
|
33
|
+
this.extension = path_1.default.extname(filePath);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.fileName = '';
|
|
37
|
+
this.extension = '';
|
|
38
|
+
this.fullPath = path_1.default.resolve(filePath);
|
|
39
|
+
this.directoryName = path_1.default.basename(path_1.default.dirname(filePath));
|
|
40
|
+
this.directoryPath = path_1.default.dirname(path_1.default.resolve(filePath));
|
|
41
|
+
}
|
|
42
|
+
this.size = stats.size;
|
|
43
|
+
this.createTime = stats.birthtime;
|
|
44
|
+
this.updateTime = stats.mtime;
|
|
45
|
+
this.lastAccessTime = stats.atime;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.FileInfo = FileInfo;
|
|
49
|
+
exports.FilterType = {
|
|
50
|
+
FileName: 'Name',
|
|
51
|
+
CreateTime: 'Create Time',
|
|
52
|
+
LastAccessTime: 'Last Access Time',
|
|
53
|
+
LastModifiedTime: 'Last Modified Time',
|
|
54
|
+
};
|
|
55
|
+
exports.FileCompareType = {
|
|
56
|
+
Equal: 'Equal',
|
|
57
|
+
Larger: 'Larger',
|
|
58
|
+
Less: 'Less',
|
|
59
|
+
LargerOrEqual: 'LargerOrEqual',
|
|
60
|
+
LessOrEqual: 'LessOrEqual',
|
|
61
|
+
};
|
|
62
|
+
exports.FileArchiveType = {
|
|
63
|
+
Zip: 'zip',
|
|
64
|
+
Tgz: 'tgz',
|
|
65
|
+
BZip2: 'bz2',
|
|
66
|
+
GZip: 'gz',
|
|
67
|
+
Tar: 'tar',
|
|
68
|
+
GuessFromFileName: 'unknown',
|
|
69
|
+
};
|
|
70
|
+
class FileFilterInfo {
|
|
71
|
+
constructor(kind, operator, filter) {
|
|
72
|
+
this.kind = kind;
|
|
73
|
+
this.operator = operator;
|
|
74
|
+
if (this.kind === exports.FilterType.FileName && typeof filter === 'string') {
|
|
75
|
+
this.nameFilter = filter;
|
|
76
|
+
this.targetDate = new Date();
|
|
77
|
+
}
|
|
78
|
+
else if (this.kind !== exports.FilterType.FileName) {
|
|
79
|
+
this.nameFilter = '';
|
|
80
|
+
if (typeof filter === 'string')
|
|
81
|
+
this.targetDate = (0, date_fns_1.parse)(filter, 'yyyyMMdd', 0);
|
|
82
|
+
else
|
|
83
|
+
this.targetDate = filter;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new errors_1.ValueError('Date Parameter is invalid:' + filter);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.FileFilterInfo = FileFilterInfo;
|
|
91
|
+
class FileTransportInfo {
|
|
92
|
+
/**
|
|
93
|
+
* Base Sdir Sname Ddir Dname (S)full+base (S)Full (S)path (S)name (D)full (D)path (D)name
|
|
94
|
+
* x x x x x base\SDir\Sname SDir\Sname SDir Sname Ddir\Dname Ddir Dname
|
|
95
|
+
* x x x x base\SDir\Sname SDir\Sname SDir Sname Ddir\Sname Ddir Sname
|
|
96
|
+
* x x x x base\SDir\Sname SDir\Sname SDir Sname SDir\Dname Sdir Dname
|
|
97
|
+
* x x x base\SDir\Sname SDir\Sname SDir Sname SDir\Sname SDir Sname
|
|
98
|
+
* x x x base\SDir SDir SDir Ddir Ddir
|
|
99
|
+
* x x base\SDir SDir SDir SDir SDir
|
|
100
|
+
* x base
|
|
101
|
+
* x x base Ddir Ddir
|
|
102
|
+
* x x x x base\Sname Sname Sname Ddir\Dname Ddir Dname
|
|
103
|
+
* x x x base\Sname Sname Sname Ddir\Sname Ddir Sname
|
|
104
|
+
* x x x base\Sname Sname Sname Dname Dname
|
|
105
|
+
* x x base\Sname Sname Sname Sname Sname
|
|
106
|
+
* x x x x SDir\Sname SDir Sname Ddir\Dname Ddir Dname
|
|
107
|
+
* x x x SDir\Sname SDir Sname Ddir\Sname Ddir Sname
|
|
108
|
+
* x x x SDir\Sname SDir Sname SDir\Dname SDir Dname
|
|
109
|
+
* x x SDir\Sname SDir Sname SDir\Sname SDir Sname
|
|
110
|
+
* x x SDir SDir Ddir Ddir
|
|
111
|
+
* x SDir SDir SDir SDir
|
|
112
|
+
* x x x Sname Sname Ddir\Dname Ddir Dname
|
|
113
|
+
* x x Sname Sname Ddir\Sname Ddir Sname
|
|
114
|
+
* x x Sname Sname Dname Dname
|
|
115
|
+
* x Sname Sname Sname Sname
|
|
116
|
+
*/
|
|
117
|
+
constructor({ basePath = '', sourceFilename = '', sourceFolderName = '', destinationFileName = '', destinationFolderName = '', deleteSourceFileAfterCompletion = false, overwriteDestination = false, filterConditions = undefined, }) {
|
|
118
|
+
_FileTransportInfo_destinationFileName.set(this, void 0);
|
|
119
|
+
_FileTransportInfo_destinationFolderName.set(this, void 0);
|
|
120
|
+
this.basePath = basePath;
|
|
121
|
+
this.sourceFileName = sourceFilename;
|
|
122
|
+
this.sourceFolderName = sourceFolderName;
|
|
123
|
+
__classPrivateFieldSet(this, _FileTransportInfo_destinationFileName, destinationFileName, "f");
|
|
124
|
+
__classPrivateFieldSet(this, _FileTransportInfo_destinationFolderName, destinationFolderName, "f");
|
|
125
|
+
this.deleteSourceFileAfterCompletion = deleteSourceFileAfterCompletion;
|
|
126
|
+
this.overwriteDestination = overwriteDestination;
|
|
127
|
+
this.filterConditions = filterConditions;
|
|
128
|
+
this.isSourceDirectory = !this.sourceFileName;
|
|
129
|
+
this.isDestinationDirectory = !this.destinationFileName;
|
|
130
|
+
this.isDestinationRoot =
|
|
131
|
+
!this.sourceFolderName && !__classPrivateFieldGet(this, _FileTransportInfo_destinationFolderName, "f");
|
|
132
|
+
if (!this.sourceFileName && __classPrivateFieldGet(this, _FileTransportInfo_destinationFileName, "f"))
|
|
133
|
+
throw new errors_1.ValueError('Invalid Parameter');
|
|
134
|
+
if (!this.basePath && !this.sourceFolderName && !this.sourceFileName)
|
|
135
|
+
throw new errors_1.ValueError('Invalid Parameter');
|
|
136
|
+
}
|
|
137
|
+
get sourceFullName() {
|
|
138
|
+
if (!this.sourceFolderName)
|
|
139
|
+
return this.sourceFileName;
|
|
140
|
+
if (!this.sourceFileName)
|
|
141
|
+
return this.sourceFolderName;
|
|
142
|
+
return path_1.default.join(this.sourceFolderName, this.sourceFileName);
|
|
143
|
+
}
|
|
144
|
+
get sourceFullNameWithBasePath() {
|
|
145
|
+
if (!this.sourceFullName)
|
|
146
|
+
return this.basePath;
|
|
147
|
+
if (!!this.basePath)
|
|
148
|
+
return path_1.default.join(this.basePath, this.sourceFullName);
|
|
149
|
+
return this.sourceFullName;
|
|
150
|
+
}
|
|
151
|
+
get destinationFileName() {
|
|
152
|
+
if (!__classPrivateFieldGet(this, _FileTransportInfo_destinationFileName, "f"))
|
|
153
|
+
return this.sourceFileName;
|
|
154
|
+
return __classPrivateFieldGet(this, _FileTransportInfo_destinationFileName, "f");
|
|
155
|
+
}
|
|
156
|
+
get destinationPath() {
|
|
157
|
+
if (!__classPrivateFieldGet(this, _FileTransportInfo_destinationFolderName, "f"))
|
|
158
|
+
return this.sourceFolderName;
|
|
159
|
+
return __classPrivateFieldGet(this, _FileTransportInfo_destinationFolderName, "f");
|
|
160
|
+
}
|
|
161
|
+
get destinationFullName() {
|
|
162
|
+
if (!this.destinationPath)
|
|
163
|
+
return this.destinationFileName;
|
|
164
|
+
if (!this.destinationFileName)
|
|
165
|
+
return this.destinationPath;
|
|
166
|
+
return path_1.default.join(this.destinationPath, this.destinationFileName);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.FileTransportInfo = FileTransportInfo;
|
|
170
|
+
_FileTransportInfo_destinationFileName = new WeakMap(), _FileTransportInfo_destinationFolderName = new WeakMap();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Configurator } from './configurator';
|
|
2
|
+
import { FileArchiveType, FileFilterInfo, FileInfo, FileTransportInfo } from './fileModel';
|
|
3
|
+
import { PromiseResult, Result } from './result';
|
|
4
|
+
import { AccessError, ArchiveError, TimeoutError } from './errors';
|
|
5
|
+
export declare class FileOperation {
|
|
6
|
+
#private;
|
|
7
|
+
static canAccess(fileName: string, readOnly?: boolean): PromiseResult<boolean, AccessError>;
|
|
8
|
+
static waitTillExclusiveAccess(fileName: string, timeoutSeconds: number): PromiseResult<boolean, TimeoutError>;
|
|
9
|
+
static search(parentDirectory: string, filterConditions: FileFilterInfo[], isRecursive?: boolean): FileInfo[];
|
|
10
|
+
static archive(archiveFileName: string, archiveType: FileArchiveType, sourceFileList: FileTransportInfo[], config: Configurator, applicationId: number, password?: string): Promise<Result<boolean, ArchiveError>>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
35
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
36
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
37
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
38
|
+
};
|
|
39
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
40
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
|
+
};
|
|
42
|
+
var _a, _FileOperation_isFileValid, _FileOperation_isFileValidForFileter, _FileOperation_isFileNameMatch, _FileOperation_isFileDateMatch;
|
|
43
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
+
exports.FileOperation = void 0;
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const path_1 = __importDefault(require("path"));
|
|
47
|
+
const fileModel_1 = require("./fileModel");
|
|
48
|
+
const compareAsc_1 = __importDefault(require("date-fns/compareAsc"));
|
|
49
|
+
const result_1 = require("./result");
|
|
50
|
+
const errors_1 = require("./errors");
|
|
51
|
+
const zip_1 = require("./archive/zip");
|
|
52
|
+
const tar_1 = require("./archive/tar");
|
|
53
|
+
const date_fns_1 = require("date-fns");
|
|
54
|
+
const gz_1 = require("./archive/gz");
|
|
55
|
+
const timer_1 = require("./timer");
|
|
56
|
+
class FileOperation {
|
|
57
|
+
static canAccess(fileName, readOnly = false) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
if (!fs.existsSync(fileName))
|
|
61
|
+
return resolve((0, result_1.fail)(`File Not exist: ${fileName}`, errors_1.AccessError));
|
|
62
|
+
const specialExtension = ['xls', 'xlsm', 'xlsx', 'zip'];
|
|
63
|
+
const stat = fs.statSync(fileName);
|
|
64
|
+
if (specialExtension.includes(path_1.default.extname(fileName)) && stat.size === 0)
|
|
65
|
+
return resolve((0, result_1.fail)(`File is invalid: ${fileName}`, errors_1.AccessError));
|
|
66
|
+
if (readOnly)
|
|
67
|
+
return resolve((0, result_1.success)(true));
|
|
68
|
+
yield setTimeout(() => {
|
|
69
|
+
const stat2 = fs.statSync(fileName);
|
|
70
|
+
if (!(0, date_fns_1.isEqual)(stat.ctime, stat2.ctime) ||
|
|
71
|
+
!(0, date_fns_1.isEqual)(stat.mtime, stat2.mtime)) {
|
|
72
|
+
// console.log(stat.ctime, stat2.ctime);
|
|
73
|
+
// console.log(stat.mtime, stat2.mtime);
|
|
74
|
+
return resolve((0, result_1.fail)(`File is under operation: ${fileName}`, errors_1.AccessError));
|
|
75
|
+
}
|
|
76
|
+
//console.log('Accessible', stat2.mtime);
|
|
77
|
+
return resolve((0, result_1.success)(true));
|
|
78
|
+
}, 100);
|
|
79
|
+
return false;
|
|
80
|
+
}));
|
|
81
|
+
// try {
|
|
82
|
+
// const fileHandle = fs.openSync(
|
|
83
|
+
// fileName,
|
|
84
|
+
// readOnly ? 'r' : 'r+',
|
|
85
|
+
// readOnly
|
|
86
|
+
// ? fs.constants.O_RDONLY
|
|
87
|
+
// : fs.constants.O_RDWR | fs.constants.O_EXCL
|
|
88
|
+
// );
|
|
89
|
+
// fs.closeSync(fileHandle);
|
|
90
|
+
// return true;
|
|
91
|
+
// } catch (err) {
|
|
92
|
+
// return false;
|
|
93
|
+
// }
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
static waitTillExclusiveAccess(fileName, timeoutSeconds) {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
return yield (0, timer_1.polling)(`File Access check ${fileName}`, timeoutSeconds, 0.5, (fileName) => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const accessible = yield this.canAccess(fileName, false);
|
|
100
|
+
if (accessible.isSuccess()) {
|
|
101
|
+
//console.log('accessible', accessible.value);
|
|
102
|
+
return (0, result_1.success)(accessible.value);
|
|
103
|
+
}
|
|
104
|
+
else
|
|
105
|
+
return (0, result_1.success)(false);
|
|
106
|
+
}), fileName);
|
|
107
|
+
// const timeoutTime = new Date().getTime() + timeoutSeconds * 1000;
|
|
108
|
+
// const nextIntervalMilliSecond = 500;
|
|
109
|
+
// const accessible = await this.canAccess(fileName, false);
|
|
110
|
+
// if (accessible.isSuccess() && accessible.value) {
|
|
111
|
+
// return success(accessible.value);
|
|
112
|
+
// }
|
|
113
|
+
// if (new Date().getTime() > timeoutTime) {
|
|
114
|
+
// return fail(`Timeout happen to access ${fileName}`, TimeoutError);
|
|
115
|
+
// }
|
|
116
|
+
// return new Promise(async (resolve, reject) => {
|
|
117
|
+
// const timerId = await setInterval(async () => {
|
|
118
|
+
// const accessible = await this.canAccess(fileName, false);
|
|
119
|
+
// if (accessible.isSuccess() && accessible.value) {
|
|
120
|
+
// clearInterval(timerId);
|
|
121
|
+
// return resolve(success(accessible.value));
|
|
122
|
+
// }
|
|
123
|
+
// if (new Date().getTime() > timeoutTime) {
|
|
124
|
+
// //console.log('Timeout');
|
|
125
|
+
// clearInterval(timerId);
|
|
126
|
+
// return resolve(
|
|
127
|
+
// fail(`Timeout happen to access ${fileName}`, TimeoutError)
|
|
128
|
+
// );
|
|
129
|
+
// }
|
|
130
|
+
// //console.log('wait next', new Date().getTime(), timeoutTime);
|
|
131
|
+
// }, nextIntervalMilliSecond);
|
|
132
|
+
// });
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
static search(parentDirectory, filterConditions, isRecursive = false) {
|
|
136
|
+
const fileInfoList = new Array();
|
|
137
|
+
if (!fs.existsSync(parentDirectory))
|
|
138
|
+
return fileInfoList;
|
|
139
|
+
fs.readdirSync(parentDirectory, { withFileTypes: true }).forEach((dirent) => {
|
|
140
|
+
if (dirent.isFile()) {
|
|
141
|
+
const fullPath = path_1.default.join(path_1.default.resolve(parentDirectory), dirent.name);
|
|
142
|
+
const [result, fileInfo] = __classPrivateFieldGet(this, _a, "m", _FileOperation_isFileValid).call(this, fullPath, filterConditions);
|
|
143
|
+
if (result) {
|
|
144
|
+
fileInfoList.push(fileInfo);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else if (dirent.isDirectory()) {
|
|
148
|
+
const fullPath = path_1.default.join(path_1.default.resolve(parentDirectory), dirent.name);
|
|
149
|
+
const childInfoList = FileOperation.search(fullPath, filterConditions, isRecursive);
|
|
150
|
+
fileInfoList.push(...childInfoList);
|
|
151
|
+
}
|
|
152
|
+
// const fullPath = path.join(path.resolve(parentDirectory), file);
|
|
153
|
+
// console.log(fullPath);
|
|
154
|
+
// const [result, fileInfo] = this.#isFileValid(fullPath, filterConditions);
|
|
155
|
+
// if (result) fileInfoList.push(fileInfo);
|
|
156
|
+
// if (!fileInfo.isFile && isRecursive) {
|
|
157
|
+
// const childInfoList = FileOperation.search(
|
|
158
|
+
// fileInfo.directoryPath,
|
|
159
|
+
// filterConditions,
|
|
160
|
+
// isRecursive
|
|
161
|
+
// );
|
|
162
|
+
// fileInfoList.push(...childInfoList);
|
|
163
|
+
// }
|
|
164
|
+
});
|
|
165
|
+
return fileInfoList;
|
|
166
|
+
}
|
|
167
|
+
static archive(archiveFileName, archiveType, sourceFileList, config, applicationId, password = '') {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
if (!sourceFileList || sourceFileList.length === 0)
|
|
170
|
+
return (0, result_1.fail)('Source File Not Specified to archive', errors_1.ArchiveError);
|
|
171
|
+
const archiveInformation = new fileModel_1.FileInfo(archiveFileName);
|
|
172
|
+
if (archiveType == fileModel_1.FileArchiveType.GuessFromFileName) {
|
|
173
|
+
const extension = archiveInformation.extension.toLowerCase();
|
|
174
|
+
switch (extension) {
|
|
175
|
+
case 'zip':
|
|
176
|
+
archiveType = fileModel_1.FileArchiveType.Zip;
|
|
177
|
+
break;
|
|
178
|
+
case 'tgz':
|
|
179
|
+
archiveType = fileModel_1.FileArchiveType.Tgz;
|
|
180
|
+
break;
|
|
181
|
+
case 'bz2':
|
|
182
|
+
archiveType = fileModel_1.FileArchiveType.BZip2;
|
|
183
|
+
break;
|
|
184
|
+
case 'gz':
|
|
185
|
+
archiveType = fileModel_1.FileArchiveType.GZip;
|
|
186
|
+
break;
|
|
187
|
+
case 'tar':
|
|
188
|
+
archiveType = fileModel_1.FileArchiveType.Tar;
|
|
189
|
+
break;
|
|
190
|
+
default:
|
|
191
|
+
return (0, result_1.fail)('File Extension Not supported for archiving ' + extension, errors_1.ArchiveError);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (archiveType == fileModel_1.FileArchiveType.BZip2 ||
|
|
195
|
+
archiveType == fileModel_1.FileArchiveType.GZip) {
|
|
196
|
+
if (sourceFileList.length > 1 || sourceFileList[0].isSourceDirectory)
|
|
197
|
+
return (0, result_1.fail)('Multiple files are not supported in this compression type: ' +
|
|
198
|
+
archiveType, errors_1.ArchiveError);
|
|
199
|
+
}
|
|
200
|
+
if (archiveType !== fileModel_1.FileArchiveType.Zip && password !== '')
|
|
201
|
+
return (0, result_1.fail)('password is not supported on other than zip format', errors_1.ArchiveError);
|
|
202
|
+
if (archiveType === fileModel_1.FileArchiveType.Tar ||
|
|
203
|
+
archiveType === fileModel_1.FileArchiveType.Tgz) {
|
|
204
|
+
if (sourceFileList.length > 1 || !sourceFileList[0].isSourceDirectory)
|
|
205
|
+
return (0, result_1.fail)('single file or multiple directory is not supported in this compression type: ' +
|
|
206
|
+
archiveType, errors_1.ArchiveError);
|
|
207
|
+
}
|
|
208
|
+
switch (archiveType) {
|
|
209
|
+
case fileModel_1.FileArchiveType.Zip:
|
|
210
|
+
return yield zip_1.ZipArchive.create(archiveInformation.fullPath, sourceFileList, password);
|
|
211
|
+
case fileModel_1.FileArchiveType.Tar:
|
|
212
|
+
return yield tar_1.TarArchive.create(archiveInformation.fullPath, sourceFileList[0]);
|
|
213
|
+
case fileModel_1.FileArchiveType.GZip:
|
|
214
|
+
return yield gz_1.GzipArchive.create(archiveInformation.fullPath, sourceFileList[0].sourceFullName);
|
|
215
|
+
case fileModel_1.FileArchiveType.Tgz:
|
|
216
|
+
return yield tar_1.TarArchive.create(archiveInformation.fullPath, sourceFileList[0], true);
|
|
217
|
+
}
|
|
218
|
+
return (0, result_1.success)(true);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
exports.FileOperation = FileOperation;
|
|
223
|
+
_a = FileOperation, _FileOperation_isFileValid = function _FileOperation_isFileValid(fileFullPath, filterConditions) {
|
|
224
|
+
let isMatch = true;
|
|
225
|
+
const fileInformation = new fileModel_1.FileInfo(fileFullPath);
|
|
226
|
+
if (!fileInformation.isFile)
|
|
227
|
+
return [false, fileInformation];
|
|
228
|
+
if (!filterConditions || filterConditions.length === 0)
|
|
229
|
+
return [true, fileInformation];
|
|
230
|
+
for (var filterInfo of filterConditions) {
|
|
231
|
+
isMatch = __classPrivateFieldGet(this, _a, "m", _FileOperation_isFileValidForFileter).call(this, fileInformation, filterInfo);
|
|
232
|
+
if (!isMatch)
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
return [isMatch, fileInformation];
|
|
236
|
+
}, _FileOperation_isFileValidForFileter = function _FileOperation_isFileValidForFileter(fileInformation, filterInformation) {
|
|
237
|
+
switch (filterInformation.kind) {
|
|
238
|
+
case fileModel_1.FilterType.FileName:
|
|
239
|
+
return __classPrivateFieldGet(this, _a, "m", _FileOperation_isFileNameMatch).call(this, fileInformation.fileName, filterInformation.nameFilter, filterInformation.operator);
|
|
240
|
+
case fileModel_1.FilterType.CreateTime:
|
|
241
|
+
return __classPrivateFieldGet(this, _a, "m", _FileOperation_isFileDateMatch).call(this, fileInformation.createTime, filterInformation.targetDate, filterInformation.operator);
|
|
242
|
+
case fileModel_1.FilterType.LastAccessTime:
|
|
243
|
+
return __classPrivateFieldGet(this, _a, "m", _FileOperation_isFileDateMatch).call(this, fileInformation.lastAccessTime, filterInformation.targetDate, filterInformation.operator);
|
|
244
|
+
case fileModel_1.FilterType.LastModifiedTime:
|
|
245
|
+
return __classPrivateFieldGet(this, _a, "m", _FileOperation_isFileDateMatch).call(this, fileInformation.updateTime, filterInformation.targetDate, filterInformation.operator);
|
|
246
|
+
}
|
|
247
|
+
}, _FileOperation_isFileNameMatch = function _FileOperation_isFileNameMatch(fileName, targetFilter, compareType) {
|
|
248
|
+
switch (compareType) {
|
|
249
|
+
case fileModel_1.FileCompareType.Equal:
|
|
250
|
+
const match = fileName.match(targetFilter);
|
|
251
|
+
return !!match && match.length > 0;
|
|
252
|
+
case fileModel_1.FileCompareType.Larger:
|
|
253
|
+
return fileName > targetFilter;
|
|
254
|
+
case fileModel_1.FileCompareType.LargerOrEqual:
|
|
255
|
+
return fileName >= targetFilter;
|
|
256
|
+
case fileModel_1.FileCompareType.Less:
|
|
257
|
+
return fileName < targetFilter;
|
|
258
|
+
case fileModel_1.FileCompareType.LessOrEqual:
|
|
259
|
+
return fileName <= targetFilter;
|
|
260
|
+
}
|
|
261
|
+
}, _FileOperation_isFileDateMatch = function _FileOperation_isFileDateMatch(fileDate, targetFilter, compareType) {
|
|
262
|
+
const result = (0, compareAsc_1.default)(fileDate, targetFilter);
|
|
263
|
+
switch (compareType) {
|
|
264
|
+
case fileModel_1.FileCompareType.Equal:
|
|
265
|
+
return result === 0;
|
|
266
|
+
case fileModel_1.FileCompareType.Larger:
|
|
267
|
+
return result > 0;
|
|
268
|
+
case fileModel_1.FileCompareType.LargerOrEqual:
|
|
269
|
+
return result >= 0;
|
|
270
|
+
case fileModel_1.FileCompareType.Less:
|
|
271
|
+
return result < 0;
|
|
272
|
+
case fileModel_1.FileCompareType.LessOrEqual:
|
|
273
|
+
return result <= 0;
|
|
274
|
+
}
|
|
275
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { PromiseResult } from './result';
|
|
2
|
+
import { DBError } from './errors';
|
|
3
|
+
export default class MarketDateAccess {
|
|
4
|
+
#private;
|
|
5
|
+
private static __marketHolidays;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getMarketAccess(market: string): PromiseResult<MarketDateAccess, DBError>;
|
|
8
|
+
isBusinessDay(targetDate: Date): boolean;
|
|
9
|
+
businessDay(targetDate: Date, dayOffset: number): Date;
|
|
10
|
+
__getNextBusinessDay(targetDate: Date, dayOffset: number): Date;
|
|
11
|
+
__getPreviousBusinessDay(targetDate: Date, dayOffset: number): Date;
|
|
12
|
+
businessDayOfBeginningMonthWithOffset(targetDate: Date, dayOffset?: number): Date;
|
|
13
|
+
businessDayOfBeginningOfNextMonthWithOffset(targetDate: Date, dayOffset?: number): Date;
|
|
14
|
+
businessDayOfBeginningOfPreviousMonthWithOffset(targetDate: Date, dayOffset?: number): Date;
|
|
15
|
+
businessDayOfEndMonthWithOffset(targetDate: Date, dayOffset: number): Date;
|
|
16
|
+
businessDayOfEndOfNextMonthWithOffset(targetDate: Date, dayOffset: number): Date;
|
|
17
|
+
businessDayOfEndOfPreviousMonthWithOffset(targetDate: Date, dayOffset: number): Date;
|
|
18
|
+
businessDayOfBeginningOfYear(targetDate: Date, dayOffset: number): Date;
|
|
19
|
+
businessDayOfEndOfYear(targetDate: Date, dayOffset: number): Date;
|
|
20
|
+
}
|