@datatruck/cli 0.30.1 → 0.31.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @datatruck/cli
2
2
 
3
+ ## 0.31.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`c98324e`](https://github.com/swordev/datatruck/commit/c98324ebbb5b43113f1bb6d9a07bd905b5883729) Thanks [@juanrgm](https://github.com/juanrgm)! - Add cron server
8
+
9
+ - [`9b40aad`](https://github.com/swordev/datatruck/commit/9b40aadc3ba57db15f14ae08c342b7170d61aa5d) Thanks [@juanrgm](https://github.com/juanrgm)! - Add multiple backends to the datatruck repository
10
+
3
11
  ## 0.30.1
4
12
 
5
13
  ### Patch Changes
@@ -15,5 +15,5 @@ export type BackupCommandOptions<TResolved = false> = {
15
15
  export type BackupCommandResult = Unwrap<BackupAction["exec"]>;
16
16
  export declare class BackupCommand extends CommandAbstract<BackupCommandOptions<false>, BackupCommandOptions<true>> {
17
17
  onOptions(): import("../utils/cli").OptionsType<BackupCommandOptions<false>, BackupCommandOptions<true>>;
18
- onExec(): Promise<0 | 1>;
18
+ onExec(): Promise<1 | 0>;
19
19
  }
@@ -2,5 +2,5 @@ import { CommandAbstract } from "./CommandAbstract";
2
2
  export type CleanCacheCommandOptions<TResolved = false> = {};
3
3
  export declare class CleanCacheCommand extends CommandAbstract<CleanCacheCommandOptions<false>, CleanCacheCommandOptions<true>> {
4
4
  onOptions(): import("../utils/cli").OptionsType<CleanCacheCommandOptions<false>, CleanCacheCommandOptions<true>>;
5
- onExec(): Promise<0 | 1>;
5
+ onExec(): Promise<1 | 0>;
6
6
  }
@@ -16,9 +16,10 @@ export type CommandConstructor<TUnresolvedOptions, TOptions extends SimilarObjec
16
16
  };
17
17
  export declare abstract class CommandAbstract<TUnresolvedOptions, TOptions extends SimilarObject<TUnresolvedOptions>> {
18
18
  readonly globalOptions: GlobalOptions<true>;
19
+ readonly configPath?: string | undefined;
19
20
  readonly options: TOptions;
20
21
  readonly streams: Streams;
21
- constructor(globalOptions: GlobalOptions<true>, options: TUnresolvedOptions, streams?: Partial<Streams>);
22
+ constructor(globalOptions: GlobalOptions<true>, options: TUnresolvedOptions, streams?: Partial<Streams>, configPath?: string | undefined);
22
23
  abstract onOptions(): OptionsType<TUnresolvedOptions, TOptions>;
23
24
  protected returnsOptions(options: OptionsType<TUnresolvedOptions, TOptions>): OptionsType<TUnresolvedOptions, TOptions>;
24
25
  abstract onExec(): Promise<number>;
@@ -5,10 +5,12 @@ const cli_1 = require("../utils/cli");
5
5
  const stream_1 = require("../utils/stream");
6
6
  class CommandAbstract {
7
7
  globalOptions;
8
+ configPath;
8
9
  options;
9
10
  streams;
10
- constructor(globalOptions, options, streams = {}) {
11
+ constructor(globalOptions, options, streams = {}, configPath) {
11
12
  this.globalOptions = globalOptions;
13
+ this.configPath = configPath;
12
14
  this.options = (0, cli_1.parseOptions)(options, this.onOptions());
13
15
  this.streams = (0, stream_1.createStreams)(streams);
14
16
  }
@@ -12,5 +12,5 @@ export type CopyCommandOptionsType<TResolved = false> = {
12
12
  export type CopyCommandResult = Unwrap<CopyAction["exec"]>;
13
13
  export declare class CopyCommand extends CommandAbstract<CopyCommandOptionsType<false>, CopyCommandOptionsType<true>> {
14
14
  onOptions(): import("../utils/cli").OptionsType<CopyCommandOptionsType<false>, CopyCommandOptionsType<true>>;
15
- onExec(): Promise<0 | 1>;
15
+ onExec(): Promise<1 | 0>;
16
16
  }
@@ -13,5 +13,5 @@ export type RestoreCommandOptionsType<TResolved = false> = {
13
13
  };
14
14
  export declare class RestoreCommand extends CommandAbstract<RestoreCommandOptionsType<false>, RestoreCommandOptionsType<true>> {
15
15
  onOptions(): import("../utils/cli").OptionsType<RestoreCommandOptionsType<false>, RestoreCommandOptionsType<true>>;
16
- onExec(): Promise<0 | 1>;
16
+ onExec(): Promise<1 | 0>;
17
17
  }
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.StartServerCommand = void 0;
4
4
  const ConfigAction_1 = require("../Action/ConfigAction");
5
- const server_1 = require("../utils/datatruck/server");
5
+ const cron_server_1 = require("../utils/datatruck/cron-server");
6
+ const repository_server_1 = require("../utils/datatruck/repository-server");
6
7
  const CommandAbstract_1 = require("./CommandAbstract");
7
8
  class StartServerCommand extends CommandAbstract_1.CommandAbstract {
8
9
  onOptions() {
@@ -10,14 +11,35 @@ class StartServerCommand extends CommandAbstract_1.CommandAbstract {
10
11
  }
11
12
  async onExec() {
12
13
  const config = await ConfigAction_1.ConfigAction.fromGlobalOptions(this.globalOptions);
13
- const server = (0, server_1.createDatatruckServer)(config.server || {});
14
- const port = config.server?.listen?.port ?? 8888;
15
- const address = config.server?.listen?.address ?? "127.0.0.1";
16
- console.info(`Listening on http://${address}:${port}`);
17
- await new Promise((resolve, reject) => {
14
+ const verbose = !!this.globalOptions.verbose;
15
+ const log = config.server?.log ?? true;
16
+ const repositoryOptions = config.server?.repository || {};
17
+ if (repositoryOptions.enabled ?? true) {
18
+ const server = (0, repository_server_1.createDatatruckRepositoryServer)(repositoryOptions, {
19
+ log,
20
+ });
21
+ const port = repositoryOptions.listen?.port ?? 8888;
22
+ const address = repositoryOptions.listen?.address ?? "127.0.0.1";
23
+ console.info(`Listening datatruck repository on http://${address}:${port}`);
24
+ server.on("error", (error) => {
25
+ console.error(`SERVER ERROR`, error);
26
+ process.exit(1);
27
+ });
18
28
  server.listen(port, address);
19
- server.on("error", reject);
20
- });
29
+ }
30
+ const cronOptions = config.server?.cron || {};
31
+ if (cronOptions.enabled ?? true) {
32
+ if (typeof this.configPath !== "string")
33
+ throw new Error(`Config path is required by cron server`);
34
+ const server = (0, cron_server_1.createCronServer)(cronOptions, {
35
+ verbose,
36
+ log,
37
+ configPath: this.configPath,
38
+ });
39
+ server.start();
40
+ console.info(`Cron server started`);
41
+ }
42
+ await new Promise(() => setInterval(() => { }, 60000));
21
43
  return 0;
22
44
  }
23
45
  }
@@ -1,5 +1,6 @@
1
1
  import { FormatType } from "../utils/DataFormat";
2
- import { DatatruckServerOptions } from "../utils/datatruck/server";
2
+ import { DatatruckCronServerOptions } from "../utils/datatruck/cron-server";
3
+ import { DatatruckRepositoryServerOptions } from "../utils/datatruck/repository-server";
3
4
  import { Step } from "../utils/steps";
4
5
  import { PackageConfigType } from "./PackageConfig";
5
6
  import { PrunePolicyConfigType } from "./PrunePolicyConfig";
@@ -14,6 +15,11 @@ export type ConfigType = {
14
15
  reports?: ReportConfig[];
15
16
  prunePolicy?: PrunePolicyConfigType;
16
17
  };
18
+ export type DatatruckServerOptions = {
19
+ log?: boolean;
20
+ repository?: DatatruckRepositoryServerOptions;
21
+ cron?: DatatruckCronServerOptions;
22
+ };
17
23
  export type ReportConfig = {
18
24
  when?: "success" | "error";
19
25
  format?: Exclude<FormatType, "custom" | "tpl">;
package/Config/Config.js CHANGED
@@ -2,8 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.configDefinition = void 0;
4
4
  const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
5
+ const backup_def_1 = require("../JsonSchema/backup-def");
6
+ const copy_def_1 = require("../JsonSchema/copy-def");
5
7
  const ScriptTask_1 = require("../Task/ScriptTask");
6
8
  const DataFormat_1 = require("../utils/DataFormat");
9
+ const schema_1 = require("../utils/schema");
7
10
  exports.configDefinition = {
8
11
  type: "object",
9
12
  required: ["repositories", "packages"],
@@ -38,46 +41,96 @@ exports.configDefinition = {
38
41
  type: "object",
39
42
  additionalProperties: false,
40
43
  properties: {
41
- path: { type: "string" },
42
44
  log: { type: "boolean" },
43
- users: {
44
- type: "array",
45
- items: {
46
- type: "object",
47
- additionalProperties: false,
48
- properties: {
49
- name: { type: "string" },
50
- password: { type: "string" },
51
- },
52
- },
53
- },
54
- listen: {
45
+ repository: {
55
46
  type: "object",
56
47
  additionalProperties: false,
57
48
  properties: {
58
- port: { type: "integer" },
59
- address: { type: "string" },
60
- },
61
- },
62
- trustProxy: {
63
- anyOf: [
64
- { type: "boolean" },
65
- {
49
+ enabled: { type: "boolean" },
50
+ listen: {
66
51
  type: "object",
67
52
  additionalProperties: false,
68
- required: ["remoteAddressHeader"],
69
53
  properties: {
70
- remoteAddressHeader: { type: "string" },
54
+ port: { type: "integer" },
55
+ address: { type: "string" },
71
56
  },
72
57
  },
73
- ],
58
+ trustProxy: {
59
+ anyOf: [
60
+ { type: "boolean" },
61
+ {
62
+ type: "object",
63
+ additionalProperties: false,
64
+ required: ["remoteAddressHeader"],
65
+ properties: {
66
+ remoteAddressHeader: { type: "string" },
67
+ },
68
+ },
69
+ ],
70
+ },
71
+ allowlist: {
72
+ type: "object",
73
+ additionalProperties: false,
74
+ properties: {
75
+ enabled: { type: "boolean" },
76
+ remoteAddresses: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
77
+ },
78
+ },
79
+ backends: {
80
+ type: "array",
81
+ items: {
82
+ type: "object",
83
+ additionalProperties: false,
84
+ required: ["name", "path"],
85
+ properties: {
86
+ name: { type: "string" },
87
+ path: { type: "string" },
88
+ users: {
89
+ type: "array",
90
+ items: {
91
+ type: "object",
92
+ additionalProperties: false,
93
+ required: ["name", "password"],
94
+ properties: {
95
+ enabled: { type: "boolean" },
96
+ name: { type: "string" },
97
+ password: { type: "string" },
98
+ },
99
+ },
100
+ },
101
+ },
102
+ },
103
+ },
104
+ },
74
105
  },
75
- allowlist: {
106
+ cron: {
76
107
  type: "object",
77
108
  additionalProperties: false,
78
109
  properties: {
79
110
  enabled: { type: "boolean" },
80
- remoteAddresses: (0, DefinitionEnum_1.makeRef)(DefinitionEnum_1.DefinitionEnum.stringListUtil),
111
+ actions: {
112
+ type: "array",
113
+ items: {
114
+ allOf: [
115
+ {
116
+ type: "object",
117
+ required: ["schedule"],
118
+ properties: {
119
+ schedule: { type: "string" },
120
+ },
121
+ },
122
+ {
123
+ anyOf: (0, schema_1.createCaseSchema)({
124
+ type: "type",
125
+ value: "options",
126
+ }, {
127
+ backup: (0, schema_1.omitPropertySchema)(backup_def_1.backupCommandOptionDef, "dryRun"),
128
+ copy: copy_def_1.copyCommandOptionsDef,
129
+ }),
130
+ },
131
+ ],
132
+ },
133
+ },
81
134
  },
82
135
  },
83
136
  },
@@ -2,6 +2,7 @@ import { DatatruckRepositoryConfigType, datatruckRepositoryName } from "../Repos
2
2
  import { GitRepositoryConfigType, gitRepositoryName } from "../Repository/GitRepository";
3
3
  import { ResticRepositoryConfigType, resticRepositoryName } from "../Repository/ResticRepository";
4
4
  import type { JSONSchema7 } from "json-schema";
5
+ export declare const repositoryNames: ("git" | "restic" | "datatruck")[];
5
6
  export declare const repositoryConfigDefinition: JSONSchema7;
6
7
  export type RepositoryConfigTypeType = RepositoryConfigType["type"];
7
8
  export type RepositoryConfigEnabledActionType = "backup" | "init" | "prune" | "restore" | "snapshots";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.repositoryConfigDefinition = void 0;
3
+ exports.repositoryConfigDefinition = exports.repositoryNames = void 0;
4
4
  const DefinitionEnum_1 = require("../JsonSchema/DefinitionEnum");
5
5
  const DatatruckRepository_1 = require("../Repository/DatatruckRepository");
6
6
  const GitRepository_1 = require("../Repository/GitRepository");
@@ -10,6 +10,11 @@ const types = {
10
10
  [DatatruckRepository_1.datatruckRepositoryName]: DefinitionEnum_1.DefinitionEnum.datatruckRepository,
11
11
  [GitRepository_1.gitRepositoryName]: DefinitionEnum_1.DefinitionEnum.gitRepository,
12
12
  };
13
+ exports.repositoryNames = [
14
+ ResticRepository_1.resticRepositoryName,
15
+ DatatruckRepository_1.datatruckRepositoryName,
16
+ GitRepository_1.gitRepositoryName,
17
+ ];
13
18
  exports.repositoryConfigDefinition = {
14
19
  type: "object",
15
20
  additionalProperties: false,
@@ -37,7 +37,7 @@ export type LogMapType = {
37
37
  [CommandEnum.snapshots]: SnapshotsCommandResult;
38
38
  [CommandEnum.backup]: BackupCommandResult;
39
39
  };
40
- export declare function CommandFactory<TCommand extends keyof OptionsMapType>(type: TCommand, globalOptions: GlobalOptions<true>, options: OptionsMapType[TCommand], streams?: Partial<Streams>): StartServerCommand;
40
+ export declare function CommandFactory<TCommand extends keyof OptionsMapType>(type: TCommand, globalOptions: GlobalOptions<true>, options: OptionsMapType[TCommand], streams?: Partial<Streams>, configPath?: string): StartServerCommand;
41
41
  export declare function exec<TCommand extends keyof OptionsMapType>(type: TCommand, globalOptions: GlobalOptions<true>, options: OptionsMapType[TCommand], streams?: Partial<Streams>): Promise<number>;
42
42
  export declare function createActionInterface(globalOptions: GlobalOptions<true>): {
43
43
  [K in keyof OptionsMapType as `${K}`]: (options: OptionsMapType[K]) => Promise<K extends keyof LogMapType ? LogMapType[K] : never>;
@@ -24,9 +24,9 @@ var CommandEnum;
24
24
  CommandEnum["cleanCache"] = "clean-cache";
25
25
  CommandEnum["startServer"] = "start-server";
26
26
  })(CommandEnum || (exports.CommandEnum = CommandEnum = {}));
27
- function CommandFactory(type, globalOptions, options, streams) {
27
+ function CommandFactory(type, globalOptions, options, streams, configPath) {
28
28
  const constructor = CommandConstructorFactory(type);
29
- return new constructor(globalOptions, options, streams);
29
+ return new constructor(globalOptions, options, streams, configPath);
30
30
  }
31
31
  exports.CommandFactory = CommandFactory;
32
32
  async function exec(type, globalOptions, options, streams) {
@@ -0,0 +1,30 @@
1
+ export declare const backupCommandOptionDef: {
2
+ type: "object";
3
+ additionalProperties: false;
4
+ properties: {
5
+ package: {
6
+ type: "string";
7
+ };
8
+ packageTask: {
9
+ type: "string";
10
+ };
11
+ repository: {
12
+ type: "string";
13
+ };
14
+ repositoryType: {
15
+ enum: ("git" | "restic" | "datatruck")[];
16
+ };
17
+ tag: {
18
+ type: "string";
19
+ };
20
+ dryRun: {
21
+ type: "boolean";
22
+ };
23
+ date: {
24
+ type: "string";
25
+ };
26
+ prune: {
27
+ type: "boolean";
28
+ };
29
+ };
30
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.backupCommandOptionDef = void 0;
4
+ const RepositoryConfig_1 = require("../Config/RepositoryConfig");
5
+ exports.backupCommandOptionDef = {
6
+ type: "object",
7
+ additionalProperties: false,
8
+ properties: {
9
+ package: { type: "string" },
10
+ packageTask: { type: "string" },
11
+ repository: { type: "string" },
12
+ repositoryType: { enum: RepositoryConfig_1.repositoryNames },
13
+ tag: { type: "string" },
14
+ dryRun: { type: "boolean" },
15
+ date: { type: "string" },
16
+ prune: { type: "boolean" },
17
+ },
18
+ };
@@ -0,0 +1,24 @@
1
+ export declare const copyCommandOptionsDef: {
2
+ type: "object";
3
+ additionalProperties: false;
4
+ properties: {
5
+ id: {
6
+ type: "string";
7
+ };
8
+ last: {
9
+ type: "integer";
10
+ };
11
+ package: {
12
+ type: "string";
13
+ };
14
+ packageTask: {
15
+ type: "string";
16
+ };
17
+ repository: {
18
+ type: "string";
19
+ };
20
+ repository2: {
21
+ type: "string";
22
+ };
23
+ };
24
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.copyCommandOptionsDef = void 0;
4
+ exports.copyCommandOptionsDef = {
5
+ type: "object",
6
+ additionalProperties: false,
7
+ properties: {
8
+ id: { type: "string" },
9
+ last: { type: "integer" },
10
+ package: { type: "string" },
11
+ packageTask: { type: "string" },
12
+ repository: { type: "string" },
13
+ repository2: { type: "string" },
14
+ },
15
+ };
package/cli.js CHANGED
@@ -59,7 +59,7 @@ function makeCommandAction(command) {
59
59
  exitCode = await (0, CommandFactory_1.CommandFactory)(command, {
60
60
  ...globalOptions,
61
61
  config: config.data,
62
- }, options).onExec();
62
+ }, options, {}, globalOptions.config).onExec();
63
63
  }
64
64
  catch (e) {
65
65
  const error = e;