@datatruck/cli 0.16.0 → 0.16.2

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 (69) hide show
  1. package/Action/BackupAction.d.ts +21 -5
  2. package/Action/BackupAction.js +64 -37
  3. package/Action/BackupSessionsAction.d.ts +1 -1
  4. package/Action/CleanCacheAction.d.ts +1 -1
  5. package/Action/ConfigAction.d.ts +1 -1
  6. package/Action/InitAction.d.ts +1 -1
  7. package/Action/PruneAction.d.ts +2 -2
  8. package/Action/RestoreAction.d.ts +12 -6
  9. package/Action/RestoreAction.js +26 -12
  10. package/Action/RestoreSessionsAction.d.ts +1 -1
  11. package/Action/SnapshotsAction.d.ts +3 -3
  12. package/Command/BackupCommand.d.ts +1 -1
  13. package/Command/BackupSessionsCommand.d.ts +1 -1
  14. package/Command/CleanCacheCommand.d.ts +1 -1
  15. package/Command/CommandAbstract.d.ts +2 -2
  16. package/Command/ConfigCommand.d.ts +2 -2
  17. package/Command/InitCommand.d.ts +2 -2
  18. package/Command/PruneCommand.d.ts +1 -1
  19. package/Command/RestoreCommand.d.ts +1 -1
  20. package/Command/RestoreSessionsCommand.d.ts +1 -1
  21. package/Command/SnapshotsCommand.d.ts +2 -2
  22. package/Config/Config.d.ts +1 -1
  23. package/Config/PackageConfig.d.ts +2 -2
  24. package/Config/PackageRepositoryConfig.d.ts +1 -1
  25. package/Config/PrunePolicyConfig.d.ts +1 -1
  26. package/Config/RepositoryConfig.d.ts +3 -3
  27. package/Config/TaskConfig.d.ts +1 -1
  28. package/Decorator/EntityDecorator.d.ts +1 -1
  29. package/Factory/CommandFactory.d.ts +2 -2
  30. package/Repository/DatatruckRepository.d.ts +4 -4
  31. package/Repository/DatatruckRepository.js +21 -18
  32. package/Repository/GitRepository.d.ts +2 -2
  33. package/Repository/GitRepository.js +3 -3
  34. package/Repository/RepositoryAbstract.d.ts +11 -9
  35. package/Repository/RepositoryAbstract.js +7 -0
  36. package/Repository/ResticRepository.d.ts +2 -2
  37. package/Repository/ResticRepository.js +3 -1
  38. package/SessionDriver/ConsoleSessionDriver.d.ts +3 -3
  39. package/SessionDriver/SessionDriverAbstract.d.ts +4 -4
  40. package/SessionManager/SessionManagerAbstract.d.ts +1 -1
  41. package/Task/GitTask.d.ts +1 -1
  42. package/Task/GitTask.js +2 -2
  43. package/Task/MariadbTask.d.ts +1 -1
  44. package/Task/MariadbTask.js +1 -1
  45. package/Task/MssqlTask.d.ts +1 -1
  46. package/Task/MysqlDumpTask.d.ts +1 -1
  47. package/Task/PostgresqlDumpTask.d.ts +1 -1
  48. package/Task/ScriptTask.d.ts +5 -5
  49. package/Task/ScriptTask.js +6 -6
  50. package/Task/SqlDumpTaskAbstract.d.ts +2 -2
  51. package/Task/SqlDumpTaskAbstract.js +2 -2
  52. package/Task/TaskAbstract.d.ts +4 -2
  53. package/Task/TaskAbstract.js +7 -0
  54. package/package.json +8 -8
  55. package/util/DataFormat.d.ts +1 -1
  56. package/util/ObjectVault.d.ts +1 -1
  57. package/util/ResticUtil.d.ts +3 -2
  58. package/util/ResticUtil.js +12 -10
  59. package/util/cli-util.d.ts +1 -1
  60. package/util/datatruck/config-util.d.ts +9 -9
  61. package/util/date-util.d.ts +1 -1
  62. package/util/fs-util.d.ts +4 -1
  63. package/util/fs-util.js +21 -3
  64. package/util/object-util.d.ts +1 -1
  65. package/util/process-util.d.ts +3 -3
  66. package/util/progress.d.ts +2 -2
  67. package/util/string-util.d.ts +1 -1
  68. package/util/zip-util.d.ts +3 -3
  69. package/util/zip-util.js +18 -16
@@ -3,9 +3,9 @@ import { GitRepositoryConfigType, gitRepositoryName } from "../Repository/GitRep
3
3
  import { ResticRepositoryConfigType, resticRepositoryName } from "../Repository/ResticRepository";
4
4
  import type { JSONSchema7 } from "json-schema";
5
5
  export declare const repositoryConfigDefinition: JSONSchema7;
6
- export declare type RepositoryConfigTypeType = RepositoryConfigType["type"];
7
- export declare type RepositoryConfigEnabledActionType = "backup" | "init" | "prune" | "restore" | "snapshots";
8
- export declare type RepositoryConfigType = {
6
+ export type RepositoryConfigTypeType = RepositoryConfigType["type"];
7
+ export type RepositoryConfigEnabledActionType = "backup" | "init" | "prune" | "restore" | "snapshots";
8
+ export type RepositoryConfigType = {
9
9
  name: string;
10
10
  mirrorRepoNames?: string[];
11
11
  enabled?: boolean | {
@@ -6,7 +6,7 @@ import { PostgresqlDumpTaskConfigType, postgresqlDumpTaskName } from "../Task/Po
6
6
  import { ScriptTaskConfigType, scriptTaskName } from "../Task/ScriptTask";
7
7
  import { JSONSchema7 } from "json-schema";
8
8
  export declare const taskConfigDefinition: JSONSchema7;
9
- export declare type TaskConfigType = {
9
+ export type TaskConfigType = {
10
10
  name: typeof gitTaskName;
11
11
  config?: GitTaskConfigType;
12
12
  } | {
@@ -1,4 +1,4 @@
1
- export declare type EntityDecoratorDataType = {
1
+ export type EntityDecoratorDataType = {
2
2
  tableName: string;
3
3
  };
4
4
  export declare function EntityDecorator(data: EntityDecoratorDataType): (constructor: Function) => void;
@@ -20,7 +20,7 @@ export declare enum CommandEnum {
20
20
  restoreSessions = "restore-sessions",
21
21
  cleanCache = "clean-cache"
22
22
  }
23
- export declare type OptionsMapType = {
23
+ export type OptionsMapType = {
24
24
  [CommandEnum.config]: ConfigCommandOptionsType;
25
25
  [CommandEnum.init]: InitCommandOptionsType;
26
26
  [CommandEnum.snapshots]: SnapshotsCommandOptionsType;
@@ -31,7 +31,7 @@ export declare type OptionsMapType = {
31
31
  [CommandEnum.restoreSessions]: RestoreSessionsCommandOptionsType;
32
32
  [CommandEnum.cleanCache]: CleanCacheActionOptionsType;
33
33
  };
34
- export declare type LogMapType = {
34
+ export type LogMapType = {
35
35
  [CommandEnum.config]: ConfigCommandLogType;
36
36
  [CommandEnum.init]: InitCommandLogType;
37
37
  [CommandEnum.snapshots]: SnapshotsCommandLogType;
@@ -1,6 +1,6 @@
1
1
  import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
2
2
  import type { JSONSchema7 } from "json-schema";
3
- export declare type MetaDataType = {
3
+ export type MetaDataType = {
4
4
  id: string;
5
5
  date: string;
6
6
  package: string;
@@ -9,7 +9,7 @@ export declare type MetaDataType = {
9
9
  version: string;
10
10
  size: number;
11
11
  };
12
- export declare type DatatruckRepositoryConfigType = {
12
+ export type DatatruckRepositoryConfigType = {
13
13
  outPath: string;
14
14
  compress?: boolean;
15
15
  /**
@@ -17,7 +17,7 @@ export declare type DatatruckRepositoryConfigType = {
17
17
  */
18
18
  fileCopyConcurrency?: number;
19
19
  };
20
- declare type CompressObjectType = {
20
+ type CompressObjectType = {
21
21
  packs?: {
22
22
  name?: string;
23
23
  include: string[];
@@ -25,7 +25,7 @@ declare type CompressObjectType = {
25
25
  onePackByResult?: boolean;
26
26
  }[];
27
27
  };
28
- export declare type DatatruckPackageRepositoryConfigType = {
28
+ export type DatatruckPackageRepositoryConfigType = {
29
29
  compress?: CompressObjectType | boolean;
30
30
  };
31
31
  export declare const datatruckRepositoryName = "datatruck";
@@ -123,30 +123,29 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
123
123
  object.current += data.current;
124
124
  }
125
125
  },
126
+ updateProgress: async (end) => {
127
+ const currentTime = perf_hooks_1.performance.now();
128
+ const diff = currentTime - lastTime;
129
+ if (end || diff > 1000) {
130
+ await options.onProgress({
131
+ relative: {
132
+ description: end ? "Scanned files" : "Scanning files",
133
+ payload: object.total.toString(),
134
+ },
135
+ });
136
+ lastTime = currentTime;
137
+ }
138
+ },
126
139
  start: async (cb) => {
127
140
  for await (const entry of (0, fs_util_1.pathIterator)(stream)) {
128
141
  if (!options.disableCounting)
129
142
  object.total++;
130
- const currentTime = perf_hooks_1.performance.now();
131
- const diff = currentTime - lastTime;
132
- if (diff > 1000) {
133
- await options.onProgress({
134
- relative: {
135
- description: "Scanning files",
136
- payload: object.total.toString(),
137
- },
138
- });
139
- lastTime = currentTime;
140
- }
143
+ await object.updateProgress();
141
144
  if (cb)
142
145
  await cb(entry);
143
146
  }
144
- await options.onProgress({
145
- relative: {
146
- description: "Scanned files",
147
- payload: object.total.toString(),
148
- },
149
- });
147
+ if (!options.disableEndProgress)
148
+ await object.updateProgress(true);
150
149
  },
151
150
  };
152
151
  await options.onProgress({
@@ -257,7 +256,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
257
256
  })
258
257
  : undefined;
259
258
  const packs = compress?.packs || [];
260
- const tmpDir = await (0, fs_util_1.mkTmpDir)("path-lists");
259
+ const tmpDir = await this.mkTmpDir("path-lists");
261
260
  const unpackedStream = (0, fs_1.createWriteStream)((0, path_1.join)(tmpDir, "unpacked.txt"));
262
261
  const singlePackStream = (0, fs_1.createWriteStream)((0, path_1.join)(tmpDir, "single-pack.txt"));
263
262
  const packStreams = Array.from({ length: packs.length }).map((v, i) => (0, fs_1.createWriteStream)((0, path_1.join)(tmpDir, `pack-${i}.txt`)));
@@ -439,6 +438,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
439
438
  cwd: sourcePath,
440
439
  },
441
440
  onProgress: data.onProgress,
441
+ disableEndProgress: true,
442
442
  });
443
443
  await scanner.start();
444
444
  const it = await (0, promises_1.opendir)(sourcePath);
@@ -446,6 +446,7 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
446
446
  const path = (0, path_1.join)(sourcePath, dirent.name);
447
447
  if (dirent.name === "permissions.txt") {
448
448
  scanner.total++;
449
+ await scanner.updateProgress();
449
450
  }
450
451
  else if (dirent.name.endsWith(".zip")) {
451
452
  await (0, zip_util_1.listZip)({
@@ -455,10 +456,12 @@ class DatatruckRepository extends RepositoryAbstract_1.RepositoryAbstract {
455
456
  const isDir = item.Folder === "+";
456
457
  if (!isDir)
457
458
  scanner.total++;
459
+ await scanner.updateProgress();
458
460
  },
459
461
  });
460
462
  }
461
463
  }
464
+ await scanner.updateProgress(true);
462
465
  if (data.options.verbose)
463
466
  (0, cli_util_1.logExec)(`Copying files to ${restorePath}`);
464
467
  await (0, fs_util_1.cpy)({
@@ -1,10 +1,10 @@
1
1
  import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagEnum, SnapshotTagObjectType, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
2
2
  import { JSONSchema7 } from "json-schema";
3
- export declare type GitRepositoryConfigType = {
3
+ export type GitRepositoryConfigType = {
4
4
  repo: string;
5
5
  branch?: string;
6
6
  };
7
- export declare type GitPackageRepositoryConfigType = {};
7
+ export type GitPackageRepositoryConfigType = {};
8
8
  export declare const gitRepositoryName = "git";
9
9
  export declare const gitRepositoryDefinition: JSONSchema7;
10
10
  export declare const gitPackageRepositoryDefinition: JSONSchema7;
@@ -84,7 +84,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
84
84
  }
85
85
  async onPrune(data) {
86
86
  const git = new GitUtil_1.GitUtil({
87
- dir: await (0, fs_util_1.mkTmpDir)(GitRepository.name + "-snapshot"),
87
+ dir: await this.mkTmpDir(GitRepository.name + "-snapshot"),
88
88
  log: data.options.verbose,
89
89
  });
90
90
  const branchName = GitRepository.buildBranchName(data.snapshot.packageName);
@@ -107,7 +107,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
107
107
  }
108
108
  async onSnapshots(data) {
109
109
  const git = new GitUtil_1.GitUtil({
110
- dir: await (0, fs_util_1.mkTmpDir)(GitRepository.name + "-snapshot"),
110
+ dir: await this.mkTmpDir(GitRepository.name + "-snapshot"),
111
111
  log: data.options.verbose,
112
112
  });
113
113
  const pkgPatterns = (0, string_util_1.makePathPatterns)(data.options.packageNames);
@@ -148,7 +148,7 @@ class GitRepository extends RepositoryAbstract_1.RepositoryAbstract {
148
148
  (0, assert_1.ok)(typeof sourcePath === "string");
149
149
  if (!(await (0, fs_util_1.existsDir)(sourcePath)))
150
150
  throw new AppError_1.AppError(`Package path not exists: ${sourcePath}`);
151
- const tmpPath = await (0, fs_util_1.mkTmpDir)(GitRepository.name + "-backup");
151
+ const tmpPath = await this.mkTmpDir(GitRepository.name + "-backup");
152
152
  const branchName = GitRepository.buildBranchName(data.package.name);
153
153
  const git = new GitUtil_1.GitUtil({
154
154
  dir: tmpPath,
@@ -5,31 +5,31 @@ import type { SnapshotExtendedType, SnapshotsActionOptionsType } from "../Action
5
5
  import type { PackageConfigType } from "../Config/PackageConfig";
6
6
  import type { RepositoryConfigType } from "../Config/RepositoryConfig";
7
7
  import { Progress } from "../util/progress";
8
- export declare type SnapshotType = {
8
+ export type SnapshotType = {
9
9
  id: string;
10
10
  date: string;
11
11
  };
12
- export declare type SnapshotResultType = SnapshotType & {
12
+ export type SnapshotResultType = SnapshotType & {
13
13
  originalId: string;
14
14
  packageName: string;
15
15
  packageTaskName: string | undefined;
16
16
  tags: string[];
17
17
  size: number;
18
18
  };
19
- export declare type InitDataType = {
19
+ export type InitDataType = {
20
20
  options: InitActionOptionsType;
21
21
  };
22
- export declare type SnapshotsDataType = {
22
+ export type SnapshotsDataType = {
23
23
  options: Pick<SnapshotsActionOptionsType, "ids" | "packageNames" | "packageTaskNames" | "verbose" | "tags">;
24
24
  };
25
- export declare type CopyBackupType<TRepositoryConfig> = {
25
+ export type CopyBackupType<TRepositoryConfig> = {
26
26
  options: BackupActionOptionsType;
27
27
  snapshot: SnapshotType;
28
28
  package: PackageConfigType;
29
29
  mirrorRepositoryConfig: TRepositoryConfig;
30
30
  onProgress: (data: Progress) => Promise<void>;
31
31
  };
32
- export declare type BackupDataType<TPackageConfig> = {
32
+ export type BackupDataType<TPackageConfig> = {
33
33
  options: BackupActionOptionsType;
34
34
  snapshot: SnapshotType;
35
35
  package: PackageConfigType;
@@ -37,7 +37,7 @@ export declare type BackupDataType<TPackageConfig> = {
37
37
  packageConfig: TPackageConfig | undefined;
38
38
  onProgress: (data: Progress) => Promise<void>;
39
39
  };
40
- export declare type RestoreDataType<TPackageConfig> = {
40
+ export type RestoreDataType<TPackageConfig> = {
41
41
  options: RestoreActionOptionsType;
42
42
  snapshot: SnapshotType;
43
43
  package: PackageConfigType;
@@ -45,7 +45,7 @@ export declare type RestoreDataType<TPackageConfig> = {
45
45
  packageConfig: TPackageConfig;
46
46
  onProgress: (data: Progress) => Promise<void>;
47
47
  };
48
- export declare type PruneDataType = {
48
+ export type PruneDataType = {
49
49
  snapshot: SnapshotExtendedType;
50
50
  options: {
51
51
  verbose?: boolean;
@@ -61,7 +61,7 @@ export declare enum SnapshotTagEnum {
61
61
  VERSION = "version",
62
62
  SIZE = "size"
63
63
  }
64
- export declare type SnapshotTagObjectType = {
64
+ export type SnapshotTagObjectType = {
65
65
  [SnapshotTagEnum.ID]: string;
66
66
  [SnapshotTagEnum.SHORT_ID]: string;
67
67
  [SnapshotTagEnum.DATE]: string;
@@ -74,7 +74,9 @@ export declare type SnapshotTagObjectType = {
74
74
  export declare abstract class RepositoryAbstract<TConfig> {
75
75
  readonly repository: RepositoryConfigType;
76
76
  readonly config: TConfig;
77
+ readonly tmpDirs: string[];
77
78
  constructor(repository: RepositoryConfigType);
79
+ mkTmpDir(prefix: string, id?: string): Promise<string>;
78
80
  abstract onGetSource(): string;
79
81
  abstract onInit(data: InitDataType): Promise<void>;
80
82
  abstract onPrune(data: PruneDataType): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RepositoryAbstract = exports.SnapshotTagEnum = void 0;
4
+ const fs_util_1 = require("../util/fs-util");
4
5
  var SnapshotTagEnum;
5
6
  (function (SnapshotTagEnum) {
6
7
  SnapshotTagEnum["ID"] = "id";
@@ -15,7 +16,13 @@ var SnapshotTagEnum;
15
16
  class RepositoryAbstract {
16
17
  constructor(repository) {
17
18
  this.repository = repository;
19
+ this.tmpDirs = [];
18
20
  this.config = repository.config;
19
21
  }
22
+ async mkTmpDir(prefix, id) {
23
+ const dir = await (0, fs_util_1.mkTmpDir)(prefix, id);
24
+ this.tmpDirs.push(dir);
25
+ return dir;
26
+ }
20
27
  }
21
28
  exports.RepositoryAbstract = RepositoryAbstract;
@@ -1,13 +1,13 @@
1
1
  import { RepositoryType } from "../util/ResticUtil";
2
2
  import { RepositoryAbstract, BackupDataType, InitDataType, RestoreDataType, SnapshotsDataType, SnapshotResultType, SnapshotTagObjectType, SnapshotTagEnum, PruneDataType, CopyBackupType } from "./RepositoryAbstract";
3
3
  import { JSONSchema7 } from "json-schema";
4
- export declare type ResticRepositoryConfigType = {
4
+ export type ResticRepositoryConfigType = {
5
5
  password: string | {
6
6
  path: string;
7
7
  };
8
8
  repository: RepositoryType;
9
9
  };
10
- export declare type ResticPackageRepositoryConfigType = {};
10
+ export type ResticPackageRepositoryConfigType = {};
11
11
  export declare const resticRepositoryName = "restic";
12
12
  export declare const resticRepositoryDefinition: JSONSchema7;
13
13
  export declare const resticPackageRepositoryDefinition: JSONSchema7;
@@ -199,7 +199,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
199
199
  description: "Writing excluded paths list",
200
200
  },
201
201
  });
202
- const tmpDir = await (0, fs_util_1.mkTmpDir)("restic-exclude");
202
+ const tmpDir = await this.mkTmpDir("restic-exclude");
203
203
  const ignoredContents = (0, fs_util_1.fastglobToGitIgnore)(exclude, sourcePath).join("\n");
204
204
  gitignorePath = (0, path_1.join)(tmpDir, "ignored.txt");
205
205
  await (0, promises_1.writeFile)(gitignorePath, ignoredContents);
@@ -231,6 +231,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
231
231
  });
232
232
  gitignorePath = await (0, fs_util_1.writeGitIgnoreList)({
233
233
  paths: stream,
234
+ outDir: await this.mkTmpDir("gitignore-list"),
234
235
  });
235
236
  }
236
237
  if (data.options.tags?.some((tag) => tag.startsWith(ResticRepository.refPrefix)))
@@ -280,6 +281,7 @@ class ResticRepository extends RepositoryAbstract_1.RepositoryAbstract {
280
281
  : []),
281
282
  ...(data.options.tags ?? []),
282
283
  ],
284
+ createEmptyDir: async () => await this.mkTmpDir("empty"),
283
285
  onStream: async (streamData) => {
284
286
  if (streamData.message_type === "status") {
285
287
  let showProgressBar = false;
@@ -1,12 +1,12 @@
1
1
  /// <reference types="node" />
2
2
  import { Progress } from "../util/progress";
3
3
  import { WriteDataType, ReadResultType, SessionDriverAbstract, SessionDriverOptions } from "./SessionDriverAbstract";
4
- declare type BadgeType = {
4
+ type BadgeType = {
5
5
  name: string;
6
6
  value: string;
7
7
  color: (input: string) => string;
8
8
  };
9
- declare type MessageType = {
9
+ type MessageType = {
10
10
  sessionId: number;
11
11
  level?: number;
12
12
  textPrefix?: string;
@@ -15,7 +15,7 @@ declare type MessageType = {
15
15
  errorBadge?: BadgeType;
16
16
  progress?: Progress;
17
17
  };
18
- declare type ConsoleSessionDriverOptions = SessionDriverOptions & {
18
+ type ConsoleSessionDriverOptions = SessionDriverOptions & {
19
19
  progress?: "auto" | "tty" | "plain";
20
20
  };
21
21
  export declare class ConsoleSessionDriver extends SessionDriverAbstract<ConsoleSessionDriverOptions> {
@@ -18,7 +18,7 @@ export declare enum EntityEnum {
18
18
  RestoreSessionTask = 4,
19
19
  RestoreSessionRepository = 5
20
20
  }
21
- export declare type WriteDataType = {
21
+ export type WriteDataType = {
22
22
  action: ActionEnum;
23
23
  entity: EntityEnum.BackupSession;
24
24
  data: BackupSessionEntity;
@@ -47,14 +47,14 @@ export declare type WriteDataType = {
47
47
  data: RestoreSessionRepositoryEntity;
48
48
  sessionData: RestoreSessionEntity;
49
49
  };
50
- export declare type ReadDataType = {
50
+ export type ReadDataType = {
51
51
  repositoryNames?: string[];
52
52
  packageNames?: string[];
53
53
  tags?: string[];
54
54
  limit?: number | null;
55
55
  verbose?: boolean;
56
56
  };
57
- export declare type ReadResultType = {
57
+ export type ReadResultType = {
58
58
  id: number;
59
59
  snapshotId: string;
60
60
  creationDate: string;
@@ -64,7 +64,7 @@ export declare type ReadResultType = {
64
64
  repositoryType: string;
65
65
  error: string | null;
66
66
  };
67
- export declare type SessionDriverOptions = {
67
+ export type SessionDriverOptions = {
68
68
  verbose?: boolean;
69
69
  };
70
70
  export declare abstract class SessionDriverAbstract<TOptions extends SessionDriverOptions = SessionDriverOptions> {
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { SessionDriverAbstract } from "../SessionDriver/SessionDriverAbstract";
3
- export declare type OptionsType = {
3
+ export type OptionsType = {
4
4
  driver: SessionDriverAbstract;
5
5
  altDrivers?: SessionDriverAbstract[];
6
6
  progressInterval?: number;
package/Task/GitTask.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
2
2
  import { JSONSchema7 } from "json-schema";
3
- export declare type GitTaskConfigType = {
3
+ export type GitTaskConfigType = {
4
4
  command?: string;
5
5
  /**
6
6
  * @default true
package/Task/GitTask.js CHANGED
@@ -60,7 +60,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
60
60
  }
61
61
  async onBeforeBackup() {
62
62
  return {
63
- targetPath: await (0, fs_util_1.mkTmpDir)(GitTask.name),
63
+ targetPath: await this.mkTmpDir(GitTask.name),
64
64
  };
65
65
  }
66
66
  async onBackup(data) {
@@ -193,7 +193,7 @@ class GitTask extends TaskAbstract_1.TaskAbstract {
193
193
  }
194
194
  async onBeforeRestore() {
195
195
  return {
196
- targetPath: await (0, fs_util_1.mkTmpDir)(GitTask.name),
196
+ targetPath: await this.mkTmpDir(GitTask.name),
197
197
  };
198
198
  }
199
199
  async onRestore(data) {
@@ -1,6 +1,6 @@
1
1
  import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
2
2
  import { JSONSchema7 } from "json-schema";
3
- export declare type MariadbTaskConfigType = {
3
+ export type MariadbTaskConfigType = {
4
4
  command?: string;
5
5
  hostname: string;
6
6
  username: string;
@@ -47,7 +47,7 @@ class MariadbTask extends TaskAbstract_1.TaskAbstract {
47
47
  }
48
48
  async onBeforeBackup() {
49
49
  return {
50
- targetPath: await (0, fs_util_1.mkTmpDir)(MariadbTask.name),
50
+ targetPath: await this.mkTmpDir(MariadbTask.name),
51
51
  };
52
52
  }
53
53
  async onBackup(data) {
@@ -1,6 +1,6 @@
1
1
  import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
2
2
  import { JSONSchema7 } from "json-schema";
3
- export declare type MssqlTaskConfigType = {
3
+ export type MssqlTaskConfigType = {
4
4
  command?: string;
5
5
  hostname?: string;
6
6
  username?: string;
@@ -1,7 +1,7 @@
1
1
  import { SqlDumpTaskAbstract, SqlDumpTaskConfigType, TargetDatabaseType } from "./SqlDumpTaskAbstract";
2
2
  import { JSONSchema7 } from "json-schema";
3
3
  export declare const mysqlDumpTaskName = "mysql-dump";
4
- export declare type MysqlDumpTaskConfigType = {} & SqlDumpTaskConfigType;
4
+ export type MysqlDumpTaskConfigType = {} & SqlDumpTaskConfigType;
5
5
  export declare const mysqlDumpTaskDefinition: JSONSchema7;
6
6
  export declare class MysqlDumpTask extends SqlDumpTaskAbstract<MysqlDumpTaskConfigType> {
7
7
  buildConnectionArgs(database?: boolean): Promise<string[]>;
@@ -1,7 +1,7 @@
1
1
  import { SqlDumpTaskAbstract, SqlDumpTaskConfigType, TargetDatabaseType } from "./SqlDumpTaskAbstract";
2
2
  import { JSONSchema7 } from "json-schema";
3
3
  export declare const postgresqlDumpTaskName = "postgresql-dump";
4
- export declare type PostgresqlDumpTaskConfigType = {} & SqlDumpTaskConfigType;
4
+ export type PostgresqlDumpTaskConfigType = {} & SqlDumpTaskConfigType;
5
5
  export declare const postgresqlDumpTaskDefinition: JSONSchema7;
6
6
  export declare class PostgresqlDumpTask extends SqlDumpTaskAbstract<PostgresqlDumpTaskConfigType> {
7
7
  buildConnectionArgs(database?: string): Promise<string[]>;
@@ -1,22 +1,22 @@
1
1
  import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
2
2
  import { JSONSchema7 } from "json-schema";
3
- export declare type ProcessStepConfig = {
3
+ export type ProcessStepConfig = {
4
4
  command: string;
5
5
  env?: Record<string, string>;
6
6
  args?: string[];
7
7
  };
8
- export declare type NodeStepConfig = {
8
+ export type NodeStepConfig = {
9
9
  env?: Record<string, string>;
10
10
  code: string | string[];
11
11
  };
12
- export declare type Step = {
12
+ export type Step = {
13
13
  type: "process";
14
14
  config: ProcessStepConfig;
15
15
  } | {
16
16
  type: "node";
17
17
  config: NodeStepConfig;
18
18
  };
19
- export declare type ScriptTaskConfigType = {
19
+ export type ScriptTaskConfigType = {
20
20
  env?: Record<string, string | undefined>;
21
21
  backupSteps: Step[];
22
22
  restoreSteps: Step[];
@@ -29,7 +29,7 @@ export declare class ScriptTask extends TaskAbstract<ScriptTaskConfigType> {
29
29
  targetPath: string;
30
30
  }>;
31
31
  protected getVars(data: BackupDataType | RestoreDataType): Record<string, string | undefined>;
32
- static processSteps(input: Step[] | Step, options: {
32
+ protected processSteps(input: Step[] | Step, options: {
33
33
  env?: Record<string, string | undefined>;
34
34
  vars: Record<string, string | undefined>;
35
35
  verbose?: boolean;
@@ -94,7 +94,7 @@ exports.scriptTaskDefinition = {
94
94
  class ScriptTask extends TaskAbstract_1.TaskAbstract {
95
95
  async onBeforeBackup() {
96
96
  return {
97
- targetPath: await (0, fs_util_1.mkTmpDir)(ScriptTask.name),
97
+ targetPath: await this.mkTmpDir(ScriptTask.name),
98
98
  };
99
99
  }
100
100
  getVars(data) {
@@ -106,7 +106,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
106
106
  DTT_TARGET_PATH: data.targetPath,
107
107
  };
108
108
  }
109
- static async processSteps(input, options) {
109
+ async processSteps(input, options) {
110
110
  const steps = Array.isArray(input) ? input : [input];
111
111
  for (const step of steps) {
112
112
  if (step.type === "process") {
@@ -122,7 +122,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
122
122
  });
123
123
  }
124
124
  else if (step.type === "node") {
125
- const tempDir = await (0, fs_util_1.mkTmpDir)("script-task-node-step");
125
+ const tempDir = await this.mkTmpDir("script-task-node-step");
126
126
  const scriptPath = (0, path_1.join)(tempDir, "script.js");
127
127
  await (0, promises_1.writeFile)(scriptPath, Array.isArray(step.config.code)
128
128
  ? step.config.code.join("\n")
@@ -150,7 +150,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
150
150
  const targetPath = data.targetPath;
151
151
  (0, assert_1.ok)(typeof path === "string");
152
152
  (0, assert_1.ok)(typeof targetPath === "string");
153
- await ScriptTask.processSteps(config.backupSteps, {
153
+ await this.processSteps(config.backupSteps, {
154
154
  env: config.env,
155
155
  vars: this.getVars(data),
156
156
  verbose: this.verbose,
@@ -158,7 +158,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
158
158
  }
159
159
  async onBeforeRestore() {
160
160
  return {
161
- targetPath: await (0, fs_util_1.mkTmpDir)(ScriptTask.name),
161
+ targetPath: await this.mkTmpDir(ScriptTask.name),
162
162
  };
163
163
  }
164
164
  async onRestore(data) {
@@ -170,7 +170,7 @@ class ScriptTask extends TaskAbstract_1.TaskAbstract {
170
170
  (0, assert_1.ok)(typeof targetPath === "string");
171
171
  await (0, fs_util_1.mkdirIfNotExists)(restorePath);
172
172
  await (0, fs_util_1.ensureEmptyDir)(restorePath);
173
- await ScriptTask.processSteps(config.restoreSteps, {
173
+ await this.processSteps(config.restoreSteps, {
174
174
  env: config.env,
175
175
  vars: this.getVars(data),
176
176
  verbose: this.verbose,
@@ -1,12 +1,12 @@
1
1
  import { exec } from "../util/process-util";
2
2
  import { BackupDataType, RestoreDataType, TaskAbstract } from "./TaskAbstract";
3
3
  import { JSONSchema7 } from "json-schema";
4
- export declare type TargetDatabaseType = {
4
+ export type TargetDatabaseType = {
5
5
  name: string;
6
6
  charset?: string;
7
7
  collate?: string;
8
8
  };
9
- export declare type SqlDumpTaskConfigType = {
9
+ export type SqlDumpTaskConfigType = {
10
10
  password: string | {
11
11
  path: string;
12
12
  };
@@ -118,7 +118,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
118
118
  await (0, promises_1.mkdir)(outputPath, { recursive: true });
119
119
  if (!this.config.oneFileByTable) {
120
120
  const outPath = (0, path_1.join)(outputPath, serializeSqlFile({ database: this.config.database }));
121
- data.onProgress({
121
+ await data.onProgress({
122
122
  relative: {
123
123
  description: "Exporting",
124
124
  },
@@ -168,7 +168,7 @@ class SqlDumpTaskAbstract extends TaskAbstract_1.TaskAbstract {
168
168
  }
169
169
  if (this.config.storedPrograms) {
170
170
  const outPath = (0, path_1.join)(outputPath, "stored-programs.sql");
171
- data.onProgress({
171
+ await data.onProgress({
172
172
  relative: {
173
173
  description: "Exporting storaged programs",
174
174
  },
@@ -3,14 +3,14 @@ import { RestoreActionOptionsType } from "../Action/RestoreAction";
3
3
  import { PackageConfigType } from "../Config/PackageConfig";
4
4
  import { SnapshotType } from "../Repository/RepositoryAbstract";
5
5
  import { Progress } from "../util/progress";
6
- export declare type BackupDataType = {
6
+ export type BackupDataType = {
7
7
  onProgress: (data: Progress) => Promise<void>;
8
8
  options: BackupActionOptionsType;
9
9
  package: PackageConfigType;
10
10
  targetPath: string | undefined;
11
11
  snapshot: SnapshotType;
12
12
  };
13
- export declare type RestoreDataType = {
13
+ export type RestoreDataType = {
14
14
  onProgress: (data: Progress) => Promise<void>;
15
15
  options: RestoreActionOptionsType;
16
16
  package: PackageConfigType;
@@ -19,7 +19,9 @@ export declare type RestoreDataType = {
19
19
  };
20
20
  export declare abstract class TaskAbstract<TConfig = any> {
21
21
  readonly config: TConfig;
22
+ readonly tmpDirs: string[];
22
23
  constructor(config: TConfig);
24
+ mkTmpDir(prefix: string, id?: string): Promise<string>;
23
25
  onBeforeBackup(data: Omit<BackupDataType, "onProgress" | "targetPath">): Promise<{
24
26
  targetPath?: string;
25
27
  } | undefined>;