gyomu 0.1.0 → 0.2.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.
Files changed (143) hide show
  1. package/index.js +3 -0
  2. package/lib/archive/abstract.d.ts +7 -7
  3. package/lib/archive/abstract.js +23 -30
  4. package/lib/archive/gz.d.ts +15 -16
  5. package/lib/archive/gz.js +49 -66
  6. package/lib/archive/index.d.ts +3 -3
  7. package/lib/archive/index.js +3 -19
  8. package/lib/archive/tar.d.ts +17 -17
  9. package/lib/archive/tar.js +128 -165
  10. package/lib/archive/zip.d.ts +27 -28
  11. package/lib/archive/zip.js +210 -254
  12. package/lib/base64.d.ts +5 -6
  13. package/lib/base64.js +17 -24
  14. package/lib/buffer.d.ts +3 -4
  15. package/lib/buffer.js +22 -23
  16. package/lib/configurator.d.ts +16 -16
  17. package/lib/configurator.js +40 -53
  18. package/lib/dateOperation.d.ts +3 -3
  19. package/lib/dateOperation.js +17 -23
  20. package/lib/dbsingleton.d.ts +7 -11
  21. package/lib/dbsingleton.js +15 -13
  22. package/lib/dbutil.d.ts +3 -3
  23. package/lib/dbutil.js +23 -44
  24. package/lib/dictionary.d.ts +8 -8
  25. package/lib/dictionary.js +51 -55
  26. package/lib/encryption.d.ts +31 -17
  27. package/lib/encryption.js +179 -202
  28. package/lib/errors.d.ts +31 -31
  29. package/lib/errors.js +52 -64
  30. package/lib/excel.d.ts +1 -1
  31. package/lib/excel.js +7 -34
  32. package/lib/fileModel.d.ts +96 -96
  33. package/lib/fileModel.js +170 -170
  34. package/lib/fileOperation.d.ts +11 -11
  35. package/lib/fileOperation.js +196 -275
  36. package/lib/generated/prisma/browser.d.ts +99 -0
  37. package/lib/generated/prisma/browser.js +17 -0
  38. package/lib/generated/prisma/client.d.ts +116 -0
  39. package/lib/generated/prisma/client.js +32 -0
  40. package/lib/generated/prisma/commonInputTypes.d.ts +367 -0
  41. package/lib/generated/prisma/commonInputTypes.js +10 -0
  42. package/lib/generated/prisma/enums.d.ts +1 -0
  43. package/lib/generated/prisma/enums.js +10 -0
  44. package/lib/generated/prisma/internal/class.d.ts +324 -0
  45. package/lib/generated/prisma/internal/class.js +41 -0
  46. package/lib/generated/prisma/internal/prismaNamespace.d.ts +2052 -0
  47. package/lib/generated/prisma/internal/prismaNamespace.js +243 -0
  48. package/lib/generated/prisma/internal/prismaNamespaceBrowser.d.ts +221 -0
  49. package/lib/generated/prisma/internal/prismaNamespaceBrowser.js +213 -0
  50. package/lib/generated/prisma/models/gyomu_apps_info_cdtbl.d.ts +1013 -0
  51. package/lib/generated/prisma/models/gyomu_apps_info_cdtbl.js +1 -0
  52. package/lib/generated/prisma/models/gyomu_market_holiday.d.ts +983 -0
  53. package/lib/generated/prisma/models/gyomu_market_holiday.js +1 -0
  54. package/lib/generated/prisma/models/gyomu_milestone_cdtbl.d.ts +909 -0
  55. package/lib/generated/prisma/models/gyomu_milestone_cdtbl.js +1 -0
  56. package/lib/generated/prisma/models/gyomu_milestone_daily.d.ts +987 -0
  57. package/lib/generated/prisma/models/gyomu_milestone_daily.js +1 -0
  58. package/lib/generated/prisma/models/gyomu_param_master.d.ts +942 -0
  59. package/lib/generated/prisma/models/gyomu_param_master.js +1 -0
  60. package/lib/generated/prisma/models/gyomu_service_cdtbl.d.ts +1009 -0
  61. package/lib/generated/prisma/models/gyomu_service_cdtbl.js +1 -0
  62. package/lib/generated/prisma/models/gyomu_service_type_cdtbl.d.ts +1003 -0
  63. package/lib/generated/prisma/models/gyomu_service_type_cdtbl.js +1 -0
  64. package/lib/generated/prisma/models/gyomu_status_handler.d.ts +1075 -0
  65. package/lib/generated/prisma/models/gyomu_status_handler.js +1 -0
  66. package/lib/generated/prisma/models/gyomu_status_info.d.ts +1236 -0
  67. package/lib/generated/prisma/models/gyomu_status_info.js +1 -0
  68. package/lib/generated/prisma/models/gyomu_status_type_cdtbl.d.ts +947 -0
  69. package/lib/generated/prisma/models/gyomu_status_type_cdtbl.js +1 -0
  70. package/lib/generated/prisma/models/gyomu_task_data.d.ts +1111 -0
  71. package/lib/generated/prisma/models/gyomu_task_data.js +1 -0
  72. package/lib/generated/prisma/models/gyomu_task_data_log.d.ts +1015 -0
  73. package/lib/generated/prisma/models/gyomu_task_data_log.js +1 -0
  74. package/lib/generated/prisma/models/gyomu_task_data_status.d.ts +1015 -0
  75. package/lib/generated/prisma/models/gyomu_task_data_status.js +1 -0
  76. package/lib/generated/prisma/models/gyomu_task_info_access_list.d.ts +1074 -0
  77. package/lib/generated/prisma/models/gyomu_task_info_access_list.js +1 -0
  78. package/lib/generated/prisma/models/gyomu_task_info_cdtbl.d.ts +1098 -0
  79. package/lib/generated/prisma/models/gyomu_task_info_cdtbl.js +1 -0
  80. package/lib/generated/prisma/models/gyomu_task_instance.d.ts +1161 -0
  81. package/lib/generated/prisma/models/gyomu_task_instance.js +1 -0
  82. package/lib/generated/prisma/models/gyomu_task_instance_submit_information.d.ts +981 -0
  83. package/lib/generated/prisma/models/gyomu_task_instance_submit_information.js +1 -0
  84. package/lib/generated/prisma/models/gyomu_task_scheduler_config.d.ts +1167 -0
  85. package/lib/generated/prisma/models/gyomu_task_scheduler_config.js +1 -0
  86. package/lib/generated/prisma/models/gyomu_variable_parameter.d.ts +909 -0
  87. package/lib/generated/prisma/models/gyomu_variable_parameter.js +1 -0
  88. package/lib/generated/prisma/models.d.ts +20 -0
  89. package/lib/generated/prisma/models.js +1 -0
  90. package/lib/holidays.d.ts +20 -20
  91. package/lib/holidays.js +159 -200
  92. package/lib/index.d.ts +11 -15
  93. package/lib/index.js +11 -31
  94. package/lib/milestone.d.ts +25 -19
  95. package/lib/milestone.js +100 -169
  96. package/lib/net/_ftp.js +228 -228
  97. package/lib/net/ftp.d.ts +19 -19
  98. package/lib/net/ftp.js +97 -160
  99. package/lib/net/remoteConnection.d.ts +11 -11
  100. package/lib/net/remoteConnection.js +29 -26
  101. package/lib/net/sftp.d.ts +19 -19
  102. package/lib/net/sftp.js +86 -155
  103. package/lib/numberOperation.d.ts +3 -3
  104. package/lib/numberOperation.js +18 -24
  105. package/lib/parameter.d.ts +15 -14
  106. package/lib/parameter.js +166 -291
  107. package/lib/platform/common.d.ts +28 -0
  108. package/lib/platform/common.js +29 -0
  109. package/lib/platform/index.d.ts +24 -0
  110. package/lib/platform/index.js +3 -0
  111. package/lib/platform/linux.d.ts +24 -0
  112. package/lib/platform/linux.js +4 -0
  113. package/lib/platform/windows.d.ts +24 -0
  114. package/lib/platform/windows.js +4 -0
  115. package/lib/result-legacy.d.ts +22 -0
  116. package/lib/result-legacy.js +40 -0
  117. package/lib/result-new.d.ts +3 -0
  118. package/lib/result-new.js +7 -0
  119. package/lib/result.d.ts +3 -23
  120. package/lib/result.js +5 -47
  121. package/lib/timer.d.ts +12 -11
  122. package/lib/timer.js +33 -62
  123. package/lib/user.d.ts +11 -11
  124. package/lib/user.js +20 -23
  125. package/lib/variable.d.ts +11 -11
  126. package/lib/variable.js +378 -280
  127. package/lib/web/attribute.d.ts +6 -6
  128. package/lib/web/attribute.js +12 -29
  129. package/lib/web/element.d.ts +24 -24
  130. package/lib/web/element.js +113 -119
  131. package/lib/web/index.d.ts +7 -7
  132. package/lib/web/index.js +7 -19
  133. package/lib/web/page.d.ts +23 -22
  134. package/lib/web/page.js +82 -102
  135. package/lib/web/table.d.ts +15 -15
  136. package/lib/web/table.js +94 -110
  137. package/lib/web/tableColumn.d.ts +10 -10
  138. package/lib/web/tableColumn.js +18 -21
  139. package/lib/web/tableRow.d.ts +10 -10
  140. package/lib/web/tableRow.js +69 -80
  141. package/lib/web/util.d.ts +12 -12
  142. package/lib/web/util.js +17 -22
  143. package/package.json +86 -43
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ module.exports = require('./lib/index');
@@ -1,7 +1,7 @@
1
- export declare abstract class AbstractBaseArchive {
2
- readonly archiveFileName: string;
3
- constructor(tarFilename: string);
4
- protected __massageEntryPath(fileName: string): string;
5
- protected __createDirectoryFromFileNameIfNotExist(destinationFilename: string): void;
6
- protected __createDirectoryIfNotExist(destinationPath: string): void;
7
- }
1
+ export declare abstract class AbstractBaseArchive {
2
+ readonly archiveFileName: string;
3
+ constructor(tarFilename: string);
4
+ protected __massageEntryPath(fileName: string): string;
5
+ protected __createDirectoryFromFileNameIfNotExist(destinationFilename: string): void;
6
+ protected __createDirectoryIfNotExist(destinationPath: string): void;
7
+ }
@@ -1,30 +1,23 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.AbstractBaseArchive = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const fs_1 = __importDefault(require("fs"));
9
- class AbstractBaseArchive {
10
- constructor(tarFilename) {
11
- this.archiveFileName = tarFilename;
12
- }
13
- __massageEntryPath(fileName) {
14
- return fileName.replace(/\\/g, '/');
15
- }
16
- __createDirectoryFromFileNameIfNotExist(destinationFilename) {
17
- let directoryName = path_1.default.dirname(destinationFilename);
18
- if (destinationFilename.endsWith(path_1.default.sep))
19
- directoryName = destinationFilename;
20
- return this.__createDirectoryIfNotExist(directoryName);
21
- }
22
- __createDirectoryIfNotExist(destinationPath) {
23
- let directoryName = destinationPath;
24
- if (!fs_1.default.existsSync(directoryName)) {
25
- //console.log(directoryName + ' to be created');
26
- fs_1.default.mkdirSync(directoryName);
27
- }
28
- }
29
- }
30
- exports.AbstractBaseArchive = AbstractBaseArchive;
1
+ import { platform } from '../platform';
2
+ export class AbstractBaseArchive {
3
+ archiveFileName;
4
+ constructor(tarFilename) {
5
+ this.archiveFileName = tarFilename;
6
+ }
7
+ __massageEntryPath(fileName) {
8
+ return fileName.replace(/\\/g, '/');
9
+ }
10
+ __createDirectoryFromFileNameIfNotExist(destinationFilename) {
11
+ let directoryName = platform.dirname(destinationFilename);
12
+ if (destinationFilename.endsWith(platform.sep))
13
+ directoryName = destinationFilename;
14
+ return this.__createDirectoryIfNotExist(directoryName);
15
+ }
16
+ __createDirectoryIfNotExist(destinationPath) {
17
+ const directoryName = destinationPath;
18
+ if (!platform.existsSync(directoryName)) {
19
+ //console.log(directoryName + ' to be created');
20
+ platform.mkdirSync(directoryName);
21
+ }
22
+ }
23
+ }
@@ -1,16 +1,15 @@
1
- /// <reference types="node" />
2
- import { ArchiveError } from '../errors';
3
- import { PromiseResult } from '../result';
4
- import { AbstractBaseArchive } from './abstract';
5
- import zlib from 'zlib';
6
- /**
7
- * @remarks
8
- * This class (extract side) doesn't support stream based retrieval yet
9
- */
10
- export declare class GzipArchive extends AbstractBaseArchive {
11
- static create(gzipFilename: string, sourceFilename: string): PromiseResult<boolean, ArchiveError>;
12
- static extract(gzipFilename: string, destinationFilename: string): PromiseResult<boolean, ArchiveError>;
13
- static getGzipTransform(): zlib.Gzip;
14
- static getGunzipTransform(): zlib.Gunzip;
15
- static extractStream(gzipFilename: string): zlib.Gunzip;
16
- }
1
+ import { ArchiveError } from '../errors';
2
+ import { ResultAsync } from '../result';
3
+ import { AbstractBaseArchive } from './abstract';
4
+ import zlib from 'zlib';
5
+ /**
6
+ * @remarks
7
+ * This class (extract side) doesn't support stream based retrieval yet
8
+ */
9
+ export declare class GzipArchive extends AbstractBaseArchive {
10
+ static create(gzipFilename: string, sourceFilename: string): ResultAsync<boolean, ArchiveError>;
11
+ static extract(gzipFilename: string, destinationFilename: string): ResultAsync<boolean, ArchiveError>;
12
+ static getGzipTransform(): zlib.Gzip;
13
+ static getGunzipTransform(): zlib.Gunzip;
14
+ static extractStream(gzipFilename: string): zlib.Gunzip;
15
+ }
package/lib/archive/gz.js CHANGED
@@ -1,66 +1,49 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.GzipArchive = void 0;
16
- const fs_1 = __importDefault(require("fs"));
17
- const errors_1 = require("../errors");
18
- const result_1 = require("../result");
19
- const abstract_1 = require("./abstract");
20
- const zlib_1 = __importDefault(require("zlib"));
21
- /**
22
- * @remarks
23
- * This class (extract side) doesn't support stream based retrieval yet
24
- */
25
- class GzipArchive extends abstract_1.AbstractBaseArchive {
26
- static create(gzipFilename, sourceFilename) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- return new Promise((resolve, reject) => {
29
- fs_1.default.createReadStream(sourceFilename)
30
- .pipe(zlib_1.default.createGzip())
31
- .pipe(fs_1.default.createWriteStream(gzipFilename))
32
- .on('error', (err) => {
33
- resolve(new result_1.Failure(new errors_1.ArchiveError('Error on gzip compression', err)));
34
- })
35
- .on('finish', () => {
36
- resolve((0, result_1.success)(true));
37
- });
38
- });
39
- });
40
- }
41
- static extract(gzipFilename, destinationFilename) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- return new Promise((resolve, reject) => {
44
- fs_1.default.createReadStream(gzipFilename)
45
- .pipe(zlib_1.default.createGunzip())
46
- .pipe(fs_1.default.createWriteStream(destinationFilename))
47
- .on('error', (err) => {
48
- resolve(new result_1.Failure(new errors_1.ArchiveError('Error on gzip uncompression', err)));
49
- })
50
- .on('finish', () => {
51
- resolve((0, result_1.success)(true));
52
- });
53
- });
54
- });
55
- }
56
- static getGzipTransform() {
57
- return zlib_1.default.createGzip();
58
- }
59
- static getGunzipTransform() {
60
- return zlib_1.default.createGunzip();
61
- }
62
- static extractStream(gzipFilename) {
63
- return fs_1.default.createReadStream(gzipFilename).pipe(zlib_1.default.createGunzip());
64
- }
65
- }
66
- exports.GzipArchive = GzipArchive;
1
+ import { ArchiveError } from '../errors';
2
+ // import { fail, Result, success, PromiseResult, Failure } from '../result';
3
+ import { ResultAsync } from '../result';
4
+ import { AbstractBaseArchive } from './abstract';
5
+ import zlib from 'zlib';
6
+ import { platform } from '../platform';
7
+ /**
8
+ * @remarks
9
+ * This class (extract side) doesn't support stream based retrieval yet
10
+ */
11
+ export class GzipArchive extends AbstractBaseArchive {
12
+ static create(gzipFilename, sourceFilename) {
13
+ return ResultAsync.fromSafePromise(new Promise((resolve, reject) => {
14
+ platform
15
+ .createReadStream(sourceFilename)
16
+ .pipe(zlib.createGzip())
17
+ .pipe(platform.createWriteStream(gzipFilename))
18
+ .on('error', (err) => {
19
+ reject(new ArchiveError('Error on gzip compression', err));
20
+ })
21
+ .on('finish', () => {
22
+ resolve(true);
23
+ });
24
+ }));
25
+ }
26
+ static extract(gzipFilename, destinationFilename) {
27
+ return ResultAsync.fromSafePromise(new Promise((resolve, reject) => {
28
+ platform
29
+ .createReadStream(gzipFilename)
30
+ .pipe(zlib.createGunzip())
31
+ .pipe(platform.createWriteStream(destinationFilename))
32
+ .on('error', (err) => {
33
+ reject(new ArchiveError('Error on gzip uncompression', err));
34
+ })
35
+ .on('finish', () => {
36
+ resolve(true);
37
+ });
38
+ }));
39
+ }
40
+ static getGzipTransform() {
41
+ return zlib.createGzip();
42
+ }
43
+ static getGunzipTransform() {
44
+ return zlib.createGunzip();
45
+ }
46
+ static extractStream(gzipFilename) {
47
+ return platform.createReadStream(gzipFilename).pipe(zlib.createGunzip());
48
+ }
49
+ }
@@ -1,3 +1,3 @@
1
- export * from './gz';
2
- export * from './tar';
3
- export * from './zip';
1
+ export * from './gz';
2
+ export * from './tar';
3
+ export * from './zip';
@@ -1,19 +1,3 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./gz"), exports);
18
- __exportStar(require("./tar"), exports);
19
- __exportStar(require("./zip"), exports);
1
+ export * from './gz';
2
+ export * from './tar';
3
+ export * from './zip';
@@ -1,17 +1,17 @@
1
- import { FileTransportInfo } from '../fileModel';
2
- import { ArchiveError } from '../errors';
3
- import { PromiseResult } from '../result';
4
- import { AbstractBaseArchive } from './abstract';
5
- /**
6
- * @remarks
7
- * This class (extract side) doesn't support stream based retrieval yet
8
- */
9
- export declare class TarArchive extends AbstractBaseArchive {
10
- static create(tarFileName: string, transferInformation: FileTransportInfo, needGZipCompression?: boolean): PromiseResult<boolean, ArchiveError>;
11
- constructor(tarFilename: string);
12
- fileExists(fileName: string): PromiseResult<boolean, ArchiveError>;
13
- extractSingileFile(sourceEntryFullName: string, destinationFolderName: string): PromiseResult<boolean, ArchiveError>;
14
- extractDirectory(sourceDirectory: string, destinationDirectory: string): PromiseResult<boolean, ArchiveError>;
15
- extractAll(destinationDirectory: string): PromiseResult<boolean, ArchiveError>;
16
- extract(transferInformation: FileTransportInfo): PromiseResult<boolean, ArchiveError>;
17
- }
1
+ import { FileTransportInfo } from '../fileModel';
2
+ import { ArchiveError } from '../errors';
3
+ import { ResultAsync } from '../result';
4
+ import { AbstractBaseArchive } from './abstract';
5
+ /**
6
+ * @remarks
7
+ * This class (extract side) doesn't support stream based retrieval yet
8
+ */
9
+ export declare class TarArchive extends AbstractBaseArchive {
10
+ static create(tarFileName: string, transferInformation: FileTransportInfo, needGZipCompression?: boolean): ResultAsync<boolean, ArchiveError>;
11
+ constructor(tarFilename: string);
12
+ fileExists(fileName: string): ResultAsync<boolean, ArchiveError>;
13
+ extractSingileFile(sourceEntryFullName: string, destinationFolderName: string): ResultAsync<boolean, ArchiveError>;
14
+ extractDirectory(sourceDirectory: string, destinationDirectory: string): ResultAsync<boolean, ArchiveError>;
15
+ extractAll(destinationDirectory: string): ResultAsync<boolean, ArchiveError>;
16
+ extract(transferInformation: FileTransportInfo): ResultAsync<boolean, ArchiveError>;
17
+ }
@@ -1,165 +1,128 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.TarArchive = void 0;
16
- const path_1 = __importDefault(require("path"));
17
- const errors_1 = require("../errors");
18
- const result_1 = require("../result");
19
- // import tarStream from 'tar-stream';
20
- // import tar from 'tar-fs';
21
- const tar_1 = __importDefault(require("tar"));
22
- const abstract_1 = require("./abstract");
23
- /**
24
- * @remarks
25
- * This class (extract side) doesn't support stream based retrieval yet
26
- */
27
- class TarArchive extends abstract_1.AbstractBaseArchive {
28
- static create(tarFileName, transferInformation, needGZipCompression = false) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- let currentDirectory = path_1.default.dirname(transferInformation.sourceFullNameWithBasePath);
31
- let targetPathForTar = transferInformation.sourceFullNameWithBasePath.substring(currentDirectory.length + path_1.default.sep.length);
32
- // console.log('current', currentDirectory);
33
- // console.log('target', targetPathForTar);
34
- if (!transferInformation.isSourceDirectory) {
35
- return (0, result_1.fail)('Single File is not supported', errors_1.ArchiveError);
36
- }
37
- let tarOptions;
38
- tarOptions = {
39
- file: tarFileName,
40
- cwd: transferInformation.sourceFullNameWithBasePath,
41
- };
42
- if (needGZipCompression) {
43
- tarOptions = {
44
- file: tarFileName,
45
- cwd: transferInformation.sourceFullNameWithBasePath,
46
- gzip: true,
47
- };
48
- }
49
- return new Promise((resolve, reject) => {
50
- let result;
51
- if (!needGZipCompression) {
52
- result = tar_1.default.create({
53
- file: tarFileName,
54
- cwd: transferInformation.sourceFullNameWithBasePath,
55
- }, ['']);
56
- }
57
- else {
58
- result = tar_1.default.create({
59
- file: tarFileName,
60
- cwd: transferInformation.sourceFullNameWithBasePath,
61
- gzip: true,
62
- }, ['']);
63
- }
64
- result
65
- .then(() => {
66
- return resolve((0, result_1.success)(true));
67
- })
68
- .catch((err) => {
69
- return resolve((0, result_1.fail)('Fail to Tar archive', errors_1.ArchiveError));
70
- });
71
- });
72
- });
73
- }
74
- constructor(tarFilename) {
75
- super(tarFilename);
76
- }
77
- fileExists(fileName) {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- fileName = this.__massageEntryPath(fileName);
80
- let isExist = false;
81
- const extract = yield tar_1.default.list({
82
- file: this.archiveFileName,
83
- onentry: (entry) => {
84
- if (entry.header.path === fileName)
85
- isExist = true;
86
- },
87
- });
88
- return (0, result_1.success)(isExist);
89
- });
90
- }
91
- extractSingileFile(sourceEntryFullName, destinationFolderName) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- const targetEntryName = this.__massageEntryPath(sourceEntryFullName);
94
- const numPathElementToSkip = (targetEntryName.match(/\//g) || []).length;
95
- this.__createDirectoryIfNotExist(destinationFolderName);
96
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
97
- yield tar_1.default
98
- .extract({
99
- cwd: destinationFolderName,
100
- file: this.archiveFileName,
101
- filter: (path, stat) => {
102
- return path === targetEntryName;
103
- },
104
- strip: numPathElementToSkip,
105
- })
106
- .then(() => {
107
- return resolve((0, result_1.success)(true));
108
- })
109
- .catch((reason) => {
110
- return resolve(new result_1.Failure(new errors_1.ArchiveError(`Fail to untar ${this.archiveFileName} -> ${targetEntryName}`, reason)));
111
- });
112
- }));
113
- });
114
- }
115
- extractDirectory(sourceDirectory, destinationDirectory) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- const targetEntryName = this.__massageEntryPath(sourceDirectory);
118
- const numPathElementToSkip = !sourceDirectory
119
- ? 0
120
- : (targetEntryName.match(/\//g) || []).length + 1;
121
- //let directoryName = path.dirname(destinationDirectory);
122
- this.__createDirectoryIfNotExist(destinationDirectory);
123
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
124
- yield tar_1.default
125
- .extract({
126
- cwd: destinationDirectory,
127
- file: this.archiveFileName,
128
- filter: (path, stat) => {
129
- return !targetEntryName || path.startsWith(targetEntryName);
130
- },
131
- strip: numPathElementToSkip,
132
- })
133
- .then(() => {
134
- resolve((0, result_1.success)(true));
135
- })
136
- .catch((reason) => {
137
- resolve(new result_1.Failure(new errors_1.ArchiveError(`Fail to untar ${this.archiveFileName} -> ${targetEntryName}`, reason)));
138
- });
139
- }));
140
- });
141
- }
142
- extractAll(destinationDirectory) {
143
- return __awaiter(this, void 0, void 0, function* () {
144
- return this.extractDirectory('', destinationDirectory);
145
- });
146
- }
147
- extract(transferInformation) {
148
- return __awaiter(this, void 0, void 0, function* () {
149
- //console.log('directory', directory);
150
- const targetEntryName = this.__massageEntryPath(transferInformation.sourceFullName);
151
- if (transferInformation.sourceFileName !==
152
- transferInformation.destinationFileName)
153
- return (0, result_1.fail)('Destination filename must be same as original filename', errors_1.ArchiveError);
154
- //console.log('targetEntryName:', targetEntryName, ':');
155
- //const directory = await unzipper.Open.file(this.zipFilename);
156
- if (!transferInformation.isSourceDirectory) {
157
- return yield this.extractSingileFile(transferInformation.sourceFullName, transferInformation.destinationPath);
158
- }
159
- else {
160
- return yield this.extractDirectory(transferInformation.sourceFullName, transferInformation.destinationFullName);
161
- }
162
- });
163
- }
164
- }
165
- exports.TarArchive = TarArchive;
1
+ import { ArchiveError } from '../errors';
2
+ //import { fail, Result, success, PromiseResult, Failure } from '../result';
3
+ import { ResultAsync, errAsync, okAsync } from '../result';
4
+ // import tarStream from 'tar-stream';
5
+ // import tar from 'tar-fs';
6
+ import * as tar from 'tar';
7
+ import { AbstractBaseArchive } from './abstract';
8
+ /**
9
+ * @remarks
10
+ * This class (extract side) doesn't support stream based retrieval yet
11
+ */
12
+ export class TarArchive extends AbstractBaseArchive {
13
+ static create(tarFileName, transferInformation, needGZipCompression = false) {
14
+ // let currentDirectory = path.dirname(
15
+ // transferInformation.sourceFullNameWithBasePath
16
+ // );
17
+ // let targetPathForTar =
18
+ // transferInformation.sourceFullNameWithBasePath.substring(
19
+ // currentDirectory.length + path.sep.length
20
+ // );
21
+ // console.log('current', currentDirectory);
22
+ // console.log('target', targetPathForTar);
23
+ if (!transferInformation.isSourceDirectory) {
24
+ return errAsync(new ArchiveError('Single File is not supported'));
25
+ }
26
+ // let tarOptions: tar.CreateOptions & tar.FileOptions;
27
+ // tarOptions = {
28
+ // file: tarFileName,
29
+ // cwd: transferInformation.sourceFullNameWithBasePath,
30
+ // };
31
+ // if (needGZipCompression) {
32
+ // tarOptions = {
33
+ // file: tarFileName,
34
+ // cwd: transferInformation.sourceFullNameWithBasePath,
35
+ // gzip: true,
36
+ // };
37
+ // }
38
+ return ResultAsync.fromSafePromise(new Promise((resolve, reject) => {
39
+ let result;
40
+ if (!needGZipCompression) {
41
+ result = tar.create({
42
+ file: tarFileName,
43
+ cwd: transferInformation.sourceFullNameWithBasePath,
44
+ }, ['']);
45
+ }
46
+ else {
47
+ result = tar.create({
48
+ file: tarFileName,
49
+ cwd: transferInformation.sourceFullNameWithBasePath,
50
+ gzip: true,
51
+ }, ['']);
52
+ }
53
+ result
54
+ .then(() => {
55
+ return resolve(true);
56
+ })
57
+ .catch((err) => {
58
+ return reject(new ArchiveError('Fail to Tar archive', err));
59
+ });
60
+ }));
61
+ }
62
+ constructor(tarFilename) {
63
+ super(tarFilename);
64
+ }
65
+ fileExists(fileName) {
66
+ fileName = this.__massageEntryPath(fileName);
67
+ let isExist = false;
68
+ return ResultAsync.fromPromise(tar.list({
69
+ file: this.archiveFileName,
70
+ onentry: (entry) => {
71
+ if (entry.path === fileName)
72
+ isExist = true;
73
+ },
74
+ }), () => new ArchiveError('Fail to list tar archive')).andThen(() => okAsync(isExist));
75
+ }
76
+ extractSingileFile(sourceEntryFullName, destinationFolderName) {
77
+ const targetEntryName = this.__massageEntryPath(sourceEntryFullName);
78
+ const numPathElementToSkip = (targetEntryName.match(/\//g) || []).length;
79
+ this.__createDirectoryIfNotExist(destinationFolderName);
80
+ return ResultAsync.fromSafePromise(tar
81
+ .extract({
82
+ cwd: destinationFolderName,
83
+ file: this.archiveFileName,
84
+ filter: (path) => path === targetEntryName,
85
+ strip: numPathElementToSkip,
86
+ })
87
+ .then(() => true)
88
+ .catch((reason) => {
89
+ throw new ArchiveError(`Fail to untar ${this.archiveFileName} -> ${targetEntryName}`, reason);
90
+ }));
91
+ }
92
+ extractDirectory(sourceDirectory, destinationDirectory) {
93
+ const targetEntryName = this.__massageEntryPath(sourceDirectory);
94
+ const numPathElementToSkip = !sourceDirectory
95
+ ? 0
96
+ : (targetEntryName.match(/\//g) || []).length + 1;
97
+ //let directoryName = path.dirname(destinationDirectory);
98
+ this.__createDirectoryIfNotExist(destinationDirectory);
99
+ return ResultAsync.fromPromise(tar
100
+ .extract({
101
+ cwd: destinationDirectory,
102
+ file: this.archiveFileName,
103
+ filter: (path) => !targetEntryName || path.startsWith(targetEntryName),
104
+ strip: numPathElementToSkip,
105
+ })
106
+ .then(() => true), (reason) => new ArchiveError(`Fail to untar ${this.archiveFileName} -> ${targetEntryName}`, reason));
107
+ }
108
+ extractAll(destinationDirectory) {
109
+ return this.extractDirectory('', destinationDirectory);
110
+ }
111
+ extract(transferInformation) {
112
+ //console.log('directory', directory);
113
+ // const targetEntryName = this.__massageEntryPath(
114
+ // transferInformation.sourceFullName
115
+ // );
116
+ if (transferInformation.sourceFileName !==
117
+ transferInformation.destinationFileName)
118
+ return errAsync(new ArchiveError('Destination filename must be same as original filename'));
119
+ //console.log('targetEntryName:', targetEntryName, ':');
120
+ //const directory = await unzipper.Open.file(this.zipFilename);
121
+ if (!transferInformation.isSourceDirectory) {
122
+ return this.extractSingileFile(transferInformation.sourceFullName, transferInformation.destinationPath);
123
+ }
124
+ else {
125
+ return this.extractDirectory(transferInformation.sourceFullName, transferInformation.destinationFullName);
126
+ }
127
+ }
128
+ }